File tree 2 files changed +23
-10
lines changed
src/tools/compiletest/src
tests/ui/compiletest-self-test
2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -979,16 +979,13 @@ impl Config {
979
979
980
980
fn parse_env ( nv : String ) -> ( String , String ) {
981
981
// 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 ( ) )
992
989
}
993
990
994
991
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
+ //@ needs-env-vars
4
+ //@ rustc-env: MY_RUSTC_ENV = my-rustc-value
5
+ //@ exec-env: MY_EXEC_ENV = my-exec-value
6
+
7
+ // Check that compiletest trims whitespace from environment variable names
8
+ // specified in `rustc-env` and `exec-env` directives, so that
9
+ // `//@ exec-env: FOO=bar` sees the name as `FOO` and not ` FOO`.
10
+ //
11
+ // Values are currently not trimmed.
12
+
13
+ fn main ( ) {
14
+ assert_eq ! ( option_env!( "MY_RUSTC_ENV" ) , Some ( " my-rustc-value" ) ) ;
15
+ assert_eq ! ( std:: env:: var( "MY_EXEC_ENV" ) . as_deref( ) , Ok ( " my-exec-value" ) ) ;
16
+ }
You can’t perform that action at this time.
0 commit comments