@@ -15,14 +15,14 @@ fn set_command_success() -> Result<(), Box<dyn std::error::Error>> {
15
15
cmd. arg ( "set" ) . arg ( "MY_VAR" ) . arg ( "Hello" ) ;
16
16
// Windows
17
17
#[ cfg( target_os = "windows" ) ]
18
- cmd. arg ( "echo %MY_VAR%" )
18
+ cmd. arg ( "--" ) . arg ( " echo %MY_VAR%")
19
19
. assert ( )
20
20
. success ( )
21
21
. stdout ( predicate:: str:: contains ( "Hello" ) ) ;
22
22
23
23
// Linux and macOS
24
24
#[ cfg( not( target_os = "windows" ) ) ]
25
- cmd. arg ( "echo $MY_VAR" )
25
+ cmd. arg ( "--" ) . arg ( " echo $MY_VAR")
26
26
. assert ( )
27
27
. success ( )
28
28
. stdout ( predicate:: str:: contains ( "Hello" ) ) ;
@@ -36,15 +36,14 @@ fn set_command_failure() -> Result<(), Box<dyn std::error::Error>> {
36
36
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
37
37
cmd. arg ( "set" ) . arg ( "MY_VARR" ) . arg ( "Hello" ) ;
38
38
// We can use only Windows command here because it should fail
39
- cmd. arg ( "%MY_VARIABLE%" ) . assert ( ) . failure ( ) ;
39
+ cmd. arg ( "--" ) . arg ( " %MY_VARIABLE%") . assert ( ) . failure ( ) ;
40
40
Ok ( ( ) )
41
41
}
42
42
43
43
#[ test]
44
44
/// Test for get command if specified variable exists
45
45
fn get_variable_exists ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
46
46
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
47
- // TODO: Audit that the environment access only happens in single-threaded code.
48
47
unsafe { env:: set_var ( "MY_VAR" , "Hello" ) } ;
49
48
cmd. arg ( "get" ) . arg ( "MY_VAR" ) ;
50
49
cmd. assert ( )
@@ -67,7 +66,6 @@ fn get_variable_doesnt_exists() -> Result<(), Box<dyn std::error::Error>> {
67
66
#[ test]
68
67
/// Test for get command if specified variable doesn't exist and showing similar variables is enabled
69
68
fn get_variable_doesnt_exists_similar_enabled ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
70
- // TODO: Audit that the environment access only happens in single-threaded code.
71
69
unsafe { env:: set_var ( "MY_VARIABLEE" , "Hello" ) } ;
72
70
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
73
71
cmd. arg ( "get" ) . arg ( "MY_VARIABLE" ) ;
@@ -85,7 +83,6 @@ fn get_variable_doesnt_exists_similar_enabled() -> Result<(), Box<dyn std::error
85
83
/// Test for get command if specified variable doesn't exist and showing similar variables is disabled
86
84
fn get_variable_doesnt_exists_similar_disabled ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
87
85
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
88
- // TODO: Audit that the environment access only happens in single-threaded code.
89
86
unsafe { env:: set_var ( "MY_VARIABLEE" , "Hello" ) } ;
90
87
cmd. arg ( "get" ) . arg ( "MY_VARIABLE" ) . arg ( "--no-similar-names" ) ;
91
88
cmd. assert ( ) . failure ( ) ;
@@ -96,7 +93,6 @@ fn get_variable_doesnt_exists_similar_disabled() -> Result<(), Box<dyn std::erro
96
93
/// Test for print command
97
94
fn print_success ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
98
95
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
99
- // TODO: Audit that the environment access only happens in single-threaded code.
100
96
unsafe { env:: set_var ( "PRINT_TEST" , "Print" ) } ;
101
97
cmd. arg ( "print" )
102
98
. assert ( )
@@ -109,12 +105,11 @@ fn print_success() -> Result<(), Box<dyn std::error::Error>> {
109
105
/// Test for delete command if specified process is successful
110
106
fn delete_command_success ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
111
107
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
112
- // TODO: Audit that the environment access only happens in single-threaded code.
113
108
unsafe { env:: set_var ( "MY_VAR" , "Hello" ) } ;
114
109
cmd. arg ( "delete" ) . arg ( "MY_VAR" ) ;
115
110
// Windows
116
111
#[ cfg( target_os = "windows" ) ]
117
- cmd. arg ( "echo 'Hello'" )
112
+ cmd. arg ( "--" ) . arg ( " echo 'Hello'")
118
113
. assert ( )
119
114
. success ( )
120
115
. stdout ( predicate:: str:: contains ( "Hello" ) ) ;
@@ -137,14 +132,14 @@ fn load_custom_file_exists() -> Result<(), Box<dyn std::error::Error>> {
137
132
cmd. arg ( "load" ) . arg ( "--file" ) . arg ( file. path ( ) ) ;
138
133
// Windows
139
134
#[ cfg( target_os = "windows" ) ]
140
- cmd. arg ( "echo %MY_ENV_VAR%" )
135
+ cmd. arg ( "--" ) . arg ( " echo %MY_ENV_VAR%")
141
136
. assert ( )
142
137
. success ( )
143
138
. stdout ( predicate:: str:: contains ( "TEST" ) ) ;
144
139
145
140
// Linux and macOS
146
141
#[ cfg( not( target_os = "windows" ) ) ]
147
- cmd. arg ( "echo $MY_ENV_VAR" )
142
+ cmd. arg ( "--" ) . arg ( " echo $MY_ENV_VAR")
148
143
. assert ( )
149
144
. success ( )
150
145
. stdout ( predicate:: str:: contains ( "TEST" ) ) ;
@@ -163,14 +158,14 @@ fn load_custom_file_exists_command_failed() -> Result<(), Box<dyn std::error::Er
163
158
cmd. arg ( "load" ) . arg ( "--file" ) . arg ( file. path ( ) ) ;
164
159
// Windows
165
160
#[ cfg( target_os = "windows" ) ]
166
- cmd. arg ( "echo %MY_ENV_VAR_TEST%" )
161
+ cmd. arg ( "--" ) . arg ( " echo %MY_ENV_VAR_TEST%")
167
162
. assert ( )
168
163
. success ( )
169
164
. stdout ( predicate:: str:: contains ( "%MY_ENV_VAR_TEST%" ) ) ;
170
165
171
166
// Linux and macOS
172
167
#[ cfg( not( target_os = "windows" ) ) ]
173
- cmd. arg ( "(exit 1)" ) . assert ( ) . failure ( ) ;
168
+ cmd. arg ( "--" ) . arg ( " (exit 1)") . assert ( ) . failure ( ) ;
174
169
// Close file after test
175
170
file. close ( ) . unwrap ( ) ;
176
171
Ok ( ( ) )
@@ -183,11 +178,11 @@ fn load_custom_file_doesnt_exists() -> Result<(), Box<dyn std::error::Error>> {
183
178
cmd. arg ( "load" ) . arg ( "--file" ) . arg ( ".env.production" ) ;
184
179
// Windows
185
180
#[ cfg( target_os = "windows" ) ]
186
- cmd. arg ( "echo %MY_ENV_VAR%" ) . assert ( ) . failure ( ) ;
181
+ cmd. arg ( "--" ) . arg ( " echo %MY_ENV_VAR%") . assert ( ) . failure ( ) ;
187
182
188
183
// Linux and macOS
189
184
#[ cfg( not( target_os = "windows" ) ) ]
190
- cmd. arg ( "echo $MY_VARIABLE" ) . assert ( ) . failure ( ) ;
185
+ cmd. arg ( "--" ) . arg ( " echo $MY_VARIABLE") . assert ( ) . failure ( ) ;
191
186
Ok ( ( ) )
192
187
}
193
188
@@ -203,6 +198,7 @@ fn test_add_local_variable() -> Result<(), Box<dyn std::error::Error>> {
203
198
"add" ,
204
199
"TEST_VAR" ,
205
200
"test_value" ,
201
+ "--" ,
206
202
& format ! ( "{} get TEST_VAR" , envfetch) ,
207
203
] )
208
204
. assert ( )
@@ -224,6 +220,7 @@ fn test_add_variable_with_special_characters() -> Result<(), Box<dyn std::error:
224
220
"add" ,
225
221
"SPECIAL_VAR" ,
226
222
"test@#$%^&*" ,
223
+ "--" ,
227
224
& format ! ( "{} get SPECIAL_VAR" , envfetch) ,
228
225
] )
229
226
. assert ( )
@@ -245,6 +242,7 @@ fn test_add_empty_value() -> Result<(), Box<dyn std::error::Error>> {
245
242
"add" ,
246
243
"EMPTY_VAR" ,
247
244
"" ,
245
+ "--" ,
248
246
& format ! ( "{} get EMPTY_VAR" , envfetch) ,
249
247
] )
250
248
. assert ( )
@@ -257,7 +255,7 @@ fn test_add_empty_value() -> Result<(), Box<dyn std::error::Error>> {
257
255
#[ test]
258
256
fn test_add_invalid_variable_name ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
259
257
let mut cmd = Command :: cargo_bin ( "envfetch" ) ?;
260
- cmd. args ( [ "add" , "INVALID NAME" , "test_value" , "echo test" ] )
258
+ cmd. args ( [ "add" , "INVALID NAME" , "test_value" , "--" , " echo test"] )
261
259
. assert ( )
262
260
. failure ( )
263
261
. stderr ( predicates:: str:: contains (
@@ -285,6 +283,7 @@ fn test_add_with_process() -> Result<(), Box<dyn std::error::Error>> {
285
283
"add" ,
286
284
"PROCESS_VAR" ,
287
285
"test_value" ,
286
+ "--" ,
288
287
& format ! ( "{} get PROCESS_VAR" , envfetch) ,
289
288
] )
290
289
. assert ( )
0 commit comments