@@ -25,9 +25,11 @@ use cargo_test_support::{basic_manifest, paths, project, rustc_host, str, Execs}
25
25
use std:: env;
26
26
use std:: path:: Path ;
27
27
28
- fn enable_build_std ( e : & mut Execs , arg : Option < & str > ) {
29
- e. env_remove ( "CARGO_HOME" ) ;
30
- e. env_remove ( "HOME" ) ;
28
+ fn enable_build_std ( e : & mut Execs , arg : Option < & str > , isolated : bool ) {
29
+ if !isolated {
30
+ e. env_remove ( "CARGO_HOME" ) ;
31
+ e. env_remove ( "HOME" ) ;
32
+ }
31
33
32
34
// And finally actually enable `build-std` for now
33
35
let arg = match arg {
@@ -42,17 +44,23 @@ fn enable_build_std(e: &mut Execs, arg: Option<&str>) {
42
44
trait BuildStd : Sized {
43
45
fn build_std ( & mut self ) -> & mut Self ;
44
46
fn build_std_arg ( & mut self , arg : & str ) -> & mut Self ;
47
+ fn build_std_isolated ( & mut self ) -> & mut Self ;
45
48
fn target_host ( & mut self ) -> & mut Self ;
46
49
}
47
50
48
51
impl BuildStd for Execs {
49
52
fn build_std ( & mut self ) -> & mut Self {
50
- enable_build_std ( self , None ) ;
53
+ enable_build_std ( self , None , false ) ;
51
54
self
52
55
}
53
56
54
57
fn build_std_arg ( & mut self , arg : & str ) -> & mut Self {
55
- enable_build_std ( self , Some ( arg) ) ;
58
+ enable_build_std ( self , Some ( arg) , false ) ;
59
+ self
60
+ }
61
+
62
+ fn build_std_isolated ( & mut self ) -> & mut Self {
63
+ enable_build_std ( self , None , true ) ;
56
64
self
57
65
}
58
66
@@ -107,9 +115,12 @@ fn basic() {
107
115
)
108
116
. build ( ) ;
109
117
110
- p. cargo ( "check" ) . build_std ( ) . target_host ( ) . run ( ) ;
118
+ // An isolated CARGO_HOME environment is used elesewhere in this test
119
+ // to ensure no extra index updates is performed.
120
+ // It is achieve by asserting the complete stderr without any wildcard.
121
+ p. cargo ( "check" ) . build_std_isolated ( ) . target_host ( ) . run ( ) ;
111
122
p. cargo ( "build" )
112
- . build_std ( )
123
+ . build_std_isolated ( )
113
124
. target_host ( )
114
125
// Importantly, this should not say [UPDATING]
115
126
// There have been multiple bugs where every build triggers and update.
@@ -120,7 +131,7 @@ fn basic() {
120
131
"# ] ] )
121
132
. run ( ) ;
122
133
p. cargo ( "run" )
123
- . build_std ( )
134
+ . build_std_isolated ( )
124
135
. target_host ( )
125
136
. with_stderr_data ( str![ [ r#"
126
137
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -129,7 +140,7 @@ fn basic() {
129
140
"# ] ] )
130
141
. run ( ) ;
131
142
p. cargo ( "test" )
132
- . build_std ( )
143
+ . build_std_isolated ( )
133
144
. target_host ( )
134
145
. with_stderr_data ( str![ [ r#"
135
146
[COMPILING] rustc-std-workspace-std [..]
@@ -379,13 +390,11 @@ fn test_proc_macro() {
379
390
. file ( "src/lib.rs" , "" )
380
391
. build ( ) ;
381
392
382
- // Download dependencies first,
383
- // so we can compare `cargo test` output without any wildcard
384
- p. cargo ( "fetch" ) . build_std ( ) . run ( ) ;
385
393
p. cargo ( "test --lib" )
386
394
. env_remove ( cargo_util:: paths:: dylib_path_envvar ( ) )
387
395
. build_std ( )
388
396
. with_stderr_data ( str![ [ r#"
397
+ ...
389
398
[COMPILING] foo v0.0.0 ([ROOT]/foo)
390
399
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
391
400
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH])
0 commit comments