Skip to content
Merged
Changes from 1 commit
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
60 changes: 59 additions & 1 deletion tests/by-util/test_printenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ fn test_get_all() {
fn test_get_var() {
new_ucmd!()
.env("KEY", "VALUE")
.env("FOO", "BAR")
.arg("KEY")
.succeeds()
.stdout_contains("VALUE\n");
.stdout_contains("VALUE\n")
.stdout_does_not_contain("BAR");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's clearer if you simply check for the exact expected output:

Suggested change
.stdout_contains("VALUE\n")
.stdout_does_not_contain("BAR");
.stdout_is("VALUE\n");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it

}

#[test]
Expand All @@ -29,6 +31,30 @@ 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_contains("VALUE\n")
.stdout_does_not_contain("c");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. In addition, I would also ensure that it is a silent error.

Suggested change
.stdout_contains("VALUE\n")
.stdout_does_not_contain("c");
.stdout_is("VALUE\n")
.no_stderr();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it

}

#[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_contains("VALUE\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Suggested change
.stdout_contains("VALUE\n");
.stdout_is("VALUE\n")
.no_stderr();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

#[test]
fn test_invalid_option_exit_code() {
// printenv should return exit code 2 for invalid options
Expand All @@ -40,3 +66,35 @@ 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
new_ucmd!()
.env("HOME", "FOO")
.env("KEY", "VALUE")
.arg("-0")
.succeeds()
.stdout_contains("HOME=FOO\x00")
.stdout_contains("KEY=VALUE\x00");

new_ucmd!()
.env("HOME", "FOO")
.env("KEY", "VALUE")
.arg("--null")
.succeeds()
.stdout_contains("HOME=FOO\x00")
.stdout_contains("KEY=VALUE\x00");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it might make sense to use a loop over the args so it's easy to see that -0 and --null are the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I wrapped it with a loop of ["-0", "--null"]. Thanks for the review


new_ucmd!()
.env("HOME", "FOO")
.env("KEY", "VALUE")
.env("FOO", "BAR")
.arg("-0")
.arg("HOME")
.arg("KEY")
.succeeds()
.stdout_contains("FOO\x00")
.stdout_contains("VALUE\x00")
.stdout_does_not_contain("BAR");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would check for the exact output:

Suggested change
.stdout_contains("FOO\x00")
.stdout_contains("VALUE\x00")
.stdout_does_not_contain("BAR");
.stdout_is("FOO\x00VALUE\x00");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
Loading