File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed 
src/tools/compiletest/src 
tests/ui/compiletest-self-test Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -979,16 +979,13 @@ impl Config {
979979
980980    fn  parse_env ( nv :  String )  -> ( String ,  String )  { 
981981        // nv is either FOO or FOO=BAR 
982-         let  mut  strs:  Vec < String >  = nv. splitn ( 2 ,  '=' ) . map ( str:: to_owned) . collect ( ) ; 
983- 
984-         match  strs. len ( )  { 
985-             1  => ( strs. pop ( ) . unwrap ( ) ,  String :: new ( ) ) , 
986-             2  => { 
987-                 let  end = strs. pop ( ) . unwrap ( ) ; 
988-                 ( strs. pop ( ) . unwrap ( ) ,  end) 
989-             } 
990-             n => panic ! ( "Expected 1 or 2 strings, not {}" ,  n) , 
991-         } 
982+         // FIXME(Zalathar): The form without `=` seems to be unused; should 
983+         // we drop support for it? 
984+         let  ( name,  value)  = nv. split_once ( '=' ) . unwrap_or ( ( & nv,  "" ) ) ; 
985+         // Trim whitespace from the name, so that `//@ exec-env: FOO=BAR` 
986+         // sees the name as `FOO` and not ` FOO`. 
987+         let  name = name. trim ( ) ; 
988+         ( name. to_owned ( ) ,  value. to_owned ( ) ) 
992989    } 
993990
994991    fn  parse_pp_exact ( & self ,  line :  & str ,  testfile :  & Path )  -> Option < PathBuf >  { 
Original file line number Diff line number Diff line change 1+ //@ edition: 2024 
2+ //@ run-pass 
3+ //@ rustc-env: MY_RUSTC_ENV = my-rustc-value 
4+ //@ exec-env: MY_EXEC_ENV = my-exec-value 
5+ 
6+ // Check that compiletest trims whitespace from environment variable names 
7+ // specified in `rustc-env` and `exec-env` directives, so that 
8+ // `//@ exec-env: FOO=bar` sees the name as `FOO` and not ` FOO`. 
9+ // 
10+ // Values are currently not trimmed. 
11+ 
12+ fn  main ( )  { 
13+     assert_eq ! ( option_env!( "MY_RUSTC_ENV" ) ,  Some ( " my-rustc-value" ) ) ; 
14+     assert_eq ! ( std:: env:: var( "MY_EXEC_ENV" ) . as_deref( ) ,  Ok ( " my-exec-value" ) ) ; 
15+ } 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments