-
-
Notifications
You must be signed in to change notification settings - Fork 2k
tests/printenv: add more tests #9151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
|
|
@@ -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"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||
|
|
@@ -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"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. I wrapped it with a loop of |
||||||||||
|
|
||||||||||
| 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"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I would check for the exact output:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||||||
| } | ||||||||||
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it