File tree Expand file tree Collapse file tree 1 file changed +51
-1
lines changed Expand file tree Collapse file tree 1 file changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,10 @@ fn test_get_all() {
1818fn test_get_var ( ) {
1919 new_ucmd ! ( )
2020 . env ( "KEY" , "VALUE" )
21+ . env ( "FOO" , "BAR" )
2122 . arg ( "KEY" )
2223 . succeeds ( )
23- . stdout_contains ( "VALUE\n " ) ;
24+ . stdout_is ( "VALUE\n " ) ;
2425}
2526
2627#[ test]
@@ -29,6 +30,31 @@ fn test_ignore_equal_var() {
2930 new_ucmd ! ( ) . env ( "a=b" , "c" ) . arg ( "a=b" ) . fails ( ) . no_stdout ( ) ;
3031}
3132
33+ #[ test]
34+ fn test_silent_error_equal_var ( ) {
35+ // printenv should ignore variables with equal signs e.g. a=b=c
36+ new_ucmd ! ( )
37+ . env ( "KEY" , "VALUE" )
38+ . env ( "a=b" , "c" )
39+ . arg ( "KEY" )
40+ . arg ( "a=b" )
41+ . fails_with_code ( 1 )
42+ . stdout_is ( "VALUE\n " )
43+ . no_stderr ( ) ;
44+ }
45+
46+ #[ test]
47+ fn test_silent_error_not_present ( ) {
48+ // printenv should ignore unspecified variables, not panic on them
49+ new_ucmd ! ( )
50+ . env ( "KEY" , "VALUE" )
51+ . arg ( "FOO" )
52+ . arg ( "KEY" )
53+ . fails_with_code ( 1 )
54+ . stdout_is ( "VALUE\n " )
55+ . no_stderr ( ) ;
56+ }
57+
3258#[ test]
3359fn test_invalid_option_exit_code ( ) {
3460 // printenv should return exit code 2 for invalid options
@@ -40,3 +66,27 @@ fn test_invalid_option_exit_code() {
4066 . stderr_contains ( "unexpected argument" )
4167 . stderr_contains ( "For more information, try '--help'" ) ;
4268}
69+
70+ #[ test]
71+ fn test_null_separator ( ) {
72+ // printenv should use \x00 as separator if null option is provided
73+ for null_opt in [ "-0" , "--null" ] {
74+ new_ucmd ! ( )
75+ . env ( "HOME" , "FOO" )
76+ . env ( "KEY" , "VALUE" )
77+ . arg ( null_opt)
78+ . succeeds ( )
79+ . stdout_contains ( "HOME=FOO\x00 " )
80+ . stdout_contains ( "KEY=VALUE\x00 " ) ;
81+
82+ new_ucmd ! ( )
83+ . env ( "HOME" , "FOO" )
84+ . env ( "KEY" , "VALUE" )
85+ . env ( "FOO" , "BAR" )
86+ . arg ( null_opt)
87+ . arg ( "HOME" )
88+ . arg ( "KEY" )
89+ . succeeds ( )
90+ . stdout_is ( "FOO\x00 VALUE\x00 " ) ;
91+ }
92+ }
You can’t perform that action at this time.
0 commit comments