@@ -210,17 +210,25 @@ fn set_command_global() -> Result<(), Box<dyn std::error::Error>> {
210
210
. arg ( "--global" ) ;
211
211
cmd. assert ( ) . success ( ) ;
212
212
213
- // Verify using a new shell instance
213
+ // Verify using shell commands
214
214
#[ cfg( target_os = "windows" ) ]
215
215
{
216
216
let output = std:: process:: Command :: new ( "cmd" )
217
217
. args ( & [ "/C" , "reg" , "query" , "HKCU\\ Environment" , "/v" , var_name] )
218
218
. output ( ) ?;
219
- let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
220
- assert ! ( stdout. contains( var_value) ) ;
219
+ assert ! ( String :: from_utf8_lossy( & output. stdout) . contains( var_value) ) ;
221
220
}
222
221
223
- #[ cfg( not( target_os = "windows" ) ) ]
222
+ #[ cfg( target_os = "macos" ) ]
223
+ {
224
+ let output = std:: process:: Command :: new ( "zsh" )
225
+ . args ( & [ "-c" , & format ! ( "source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null; echo ${}" , var_name) ] )
226
+ . output ( ) ?;
227
+ assert ! ( String :: from_utf8_lossy( & output. stdout) . contains( var_value) ,
228
+ "Variable not found in shell output: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
229
+ }
230
+
231
+ #[ cfg( all( not( target_os = "windows" ) , not( target_os = "macos" ) ) ) ]
224
232
{
225
233
let output = std:: process:: Command :: new ( "bash" )
226
234
. args ( & [ "-c" , & format ! ( "source ~/.bashrc && echo ${}" , var_name) ] )
@@ -358,14 +366,25 @@ fn load_command_global() -> Result<(), Box<dyn std::error::Error>> {
358
366
assert ! ( String :: from_utf8_lossy( & output2. stdout) . contains( "Hello" ) ) ;
359
367
}
360
368
361
- #[ cfg( not ( target_os = "windows" ) ) ]
369
+ #[ cfg( target_os = "macos" ) ]
362
370
{
363
- let output = std:: process:: Command :: new ( "sh" )
364
- . args ( & [ "-c" , "echo $GLOBAL_TEST_VAR $GLOBAL_TEST_VAR2" ] )
371
+ // On macOS, we need to source both potential config files
372
+ let output = std:: process:: Command :: new ( "zsh" )
373
+ . args ( & [ "-c" , "source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null; echo $GLOBAL_TEST_VAR $GLOBAL_TEST_VAR2" ] )
374
+ . output ( ) ?;
375
+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
376
+ assert ! ( stdout. contains( "GlobalTest" ) && stdout. contains( "Hello" ) ,
377
+ "Variables not found in shell output: {}" , stdout) ;
378
+ }
379
+
380
+ #[ cfg( all( not( target_os = "windows" ) , not( target_os = "macos" ) ) ) ]
381
+ {
382
+ let output = std:: process:: Command :: new ( "bash" )
383
+ . args ( & [ "-c" , "source ~/.bashrc && echo $GLOBAL_TEST_VAR $GLOBAL_TEST_VAR2" ] )
365
384
. output ( ) ?;
366
385
let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
367
- assert ! ( stdout. contains( "GlobalTest" ) ) ;
368
- assert ! ( stdout . contains ( "Hello" ) ) ;
386
+ assert ! ( stdout. contains( "GlobalTest" ) && stdout . contains ( "Hello" ) ,
387
+ "Variables not found in shell output: {}" , stdout ) ;
369
388
}
370
389
371
390
// Clean up
0 commit comments