tests/printenv: add more tests (#9151)

* tests/printenv: add more tests

* tests/printenv: use clearer checks in tests
This commit is contained in:
Suprun
2025-11-06 13:40:23 +01:00
committed by GitHub
parent c9e110a769
commit 45fd3c9e93
+51 -1
View File
@@ -18,9 +18,10 @@ fn test_get_all() {
fn test_get_var() {
new_ucmd!()
.env("KEY", "VALUE")
.env("FOO", "BAR")
.arg("KEY")
.succeeds()
.stdout_contains("VALUE\n");
.stdout_is("VALUE\n");
}
#[test]
@@ -29,6 +30,31 @@ fn test_ignore_equal_var() {
new_ucmd!().env("a=b", "c").arg("a=b").fails().no_stdout();
}
#[test]
fn test_silent_error_equal_var() {
// printenv should ignore variables with equal signs e.g. a=b=c
new_ucmd!()
.env("KEY", "VALUE")
.env("a=b", "c")
.arg("KEY")
.arg("a=b")
.fails_with_code(1)
.stdout_is("VALUE\n")
.no_stderr();
}
#[test]
fn test_silent_error_not_present() {
// printenv should ignore unspecified variables, not panic on them
new_ucmd!()
.env("KEY", "VALUE")
.arg("FOO")
.arg("KEY")
.fails_with_code(1)
.stdout_is("VALUE\n")
.no_stderr();
}
#[test]
fn test_invalid_option_exit_code() {
// printenv should return exit code 2 for invalid options
@@ -40,3 +66,27 @@ fn test_invalid_option_exit_code() {
.stderr_contains("unexpected argument")
.stderr_contains("For more information, try '--help'");
}
#[test]
fn test_null_separator() {
// printenv should use \x00 as separator if null option is provided
for null_opt in ["-0", "--null"] {
new_ucmd!()
.env("HOME", "FOO")
.env("KEY", "VALUE")
.arg(null_opt)
.succeeds()
.stdout_contains("HOME=FOO\x00")
.stdout_contains("KEY=VALUE\x00");
new_ucmd!()
.env("HOME", "FOO")
.env("KEY", "VALUE")
.env("FOO", "BAR")
.arg(null_opt)
.arg("HOME")
.arg("KEY")
.succeeds()
.stdout_is("FOO\x00VALUE\x00");
}
}