@@ -24,7 +24,7 @@ use nextest_metadata::{
24
24
use once_cell:: sync:: { Lazy , OnceCell } ;
25
25
use owo_colors:: OwoColorize ;
26
26
use std:: {
27
- collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ,
27
+ collections:: { BTreeMap , BTreeSet , HashMap } ,
28
28
ffi:: { OsStr , OsString } ,
29
29
io,
30
30
io:: Write ,
@@ -908,10 +908,13 @@ pub(crate) fn make_test_command(
908
908
} ;
909
909
910
910
// NB: we will always override user-provided environment variables with the
911
- // ones we set below.
912
- let mut existing_keys: HashSet < _ > = std:: env:: vars_os ( )
913
- . map ( |( k, _v) | k)
914
- . map ( make_windows_compatible_key)
911
+ // `CARGO_*` and `NEXTEST_*` variables set directly on `cmd` below.
912
+ enum EnvSource {
913
+ Env ,
914
+ CargoConfig ,
915
+ }
916
+ let mut existing_keys: HashMap < OsString , EnvSource > = std:: env:: vars_os ( )
917
+ . map ( |( k, _v) | ( make_windows_compatible_key ( k) , EnvSource :: Env ) )
915
918
. collect ( ) ;
916
919
for CargoEnvironmentVariable {
917
920
source,
@@ -922,7 +925,20 @@ pub(crate) fn make_test_command(
922
925
} in env
923
926
{
924
927
let name_os_string = make_windows_compatible_key ( OsString :: from ( name) ) ;
925
- if !existing_keys. insert ( name_os_string) && !force {
928
+ let should_set_value = match existing_keys. insert ( name_os_string, EnvSource :: CargoConfig ) {
929
+ None => {
930
+ // No key with this name was set, proceed to set the value.
931
+ true
932
+ }
933
+ Some ( EnvSource :: CargoConfig ) => {
934
+ // Always prefer previously-set cargo config values, since they have higher
935
+ // precedence. Note that `force` only applies to overwriting environment variables,
936
+ // not other cargo config values.
937
+ false
938
+ }
939
+ Some ( EnvSource :: Env ) => * force,
940
+ } ;
941
+ if !should_set_value {
926
942
continue ;
927
943
}
928
944
0 commit comments