Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion tests/by-util/test_printenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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");
}
}
Loading