1
1
//! Tests for the cache file for the rustc version info.
2
2
3
- use cargo_test_support:: paths:: CargoPathExt ;
3
+ use cargo_test_support:: { basic_bin_manifest , paths:: CargoPathExt } ;
4
4
use cargo_test_support:: { basic_manifest, project} ;
5
5
use std:: env;
6
6
7
+ const MISS : & str = "[..] rustc info cache miss[..]" ;
8
+ const HIT : & str = "[..]rustc info cache hit[..]" ;
9
+ const UPDATE : & str = "[..]updated rustc info cache[..]" ;
10
+
7
11
#[ cargo_test]
8
12
fn rustc_info_cache ( ) {
9
13
let p = project ( )
10
14
. file ( "src/main.rs" , r#"fn main() { println!("hello"); }"# )
11
15
. build ( ) ;
12
16
13
- let miss = "[..] rustc info cache miss[..]" ;
14
- let hit = "[..]rustc info cache hit[..]" ;
15
- let update = "[..]updated rustc info cache[..]" ;
16
-
17
17
p. cargo ( "build" )
18
18
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
19
19
. with_stderr_contains ( "[..]failed to read rustc info cache[..]" )
20
- . with_stderr_contains ( miss )
21
- . with_stderr_does_not_contain ( hit )
22
- . with_stderr_contains ( update )
20
+ . with_stderr_contains ( MISS )
21
+ . with_stderr_does_not_contain ( HIT )
22
+ . with_stderr_contains ( UPDATE )
23
23
. run ( ) ;
24
24
25
25
p. cargo ( "build" )
26
26
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
27
27
. with_stderr_contains ( "[..]reusing existing rustc info cache[..]" )
28
- . with_stderr_contains ( hit )
29
- . with_stderr_does_not_contain ( miss )
30
- . with_stderr_does_not_contain ( update )
28
+ . with_stderr_contains ( HIT )
29
+ . with_stderr_does_not_contain ( MISS )
30
+ . with_stderr_does_not_contain ( UPDATE )
31
31
. run ( ) ;
32
32
33
33
p. cargo ( "build" )
34
34
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
35
35
. env ( "CARGO_CACHE_RUSTC_INFO" , "0" )
36
36
. with_stderr_contains ( "[..]rustc info cache disabled[..]" )
37
- . with_stderr_does_not_contain ( update )
37
+ . with_stderr_does_not_contain ( UPDATE )
38
38
. run ( ) ;
39
39
40
40
let other_rustc = {
@@ -68,18 +68,18 @@ fn rustc_info_cache() {
68
68
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
69
69
. env ( "RUSTC" , other_rustc. display ( ) . to_string ( ) )
70
70
. with_stderr_contains ( "[..]different compiler, creating new rustc info cache[..]" )
71
- . with_stderr_contains ( miss )
72
- . with_stderr_does_not_contain ( hit )
73
- . with_stderr_contains ( update )
71
+ . with_stderr_contains ( MISS )
72
+ . with_stderr_does_not_contain ( HIT )
73
+ . with_stderr_contains ( UPDATE )
74
74
. run ( ) ;
75
75
76
76
p. cargo ( "build" )
77
77
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
78
78
. env ( "RUSTC" , other_rustc. display ( ) . to_string ( ) )
79
79
. with_stderr_contains ( "[..]reusing existing rustc info cache[..]" )
80
- . with_stderr_contains ( hit )
81
- . with_stderr_does_not_contain ( miss )
82
- . with_stderr_does_not_contain ( update )
80
+ . with_stderr_contains ( HIT )
81
+ . with_stderr_does_not_contain ( MISS )
82
+ . with_stderr_does_not_contain ( UPDATE )
83
83
. run ( ) ;
84
84
85
85
other_rustc. move_into_the_future ( ) ;
@@ -88,17 +88,99 @@ fn rustc_info_cache() {
88
88
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
89
89
. env ( "RUSTC" , other_rustc. display ( ) . to_string ( ) )
90
90
. with_stderr_contains ( "[..]different compiler, creating new rustc info cache[..]" )
91
- . with_stderr_contains ( miss )
92
- . with_stderr_does_not_contain ( hit )
93
- . with_stderr_contains ( update )
91
+ . with_stderr_contains ( MISS )
92
+ . with_stderr_does_not_contain ( HIT )
93
+ . with_stderr_contains ( UPDATE )
94
94
. run ( ) ;
95
95
96
96
p. cargo ( "build" )
97
97
. env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
98
98
. env ( "RUSTC" , other_rustc. display ( ) . to_string ( ) )
99
99
. with_stderr_contains ( "[..]reusing existing rustc info cache[..]" )
100
- . with_stderr_contains ( hit )
101
- . with_stderr_does_not_contain ( miss )
102
- . with_stderr_does_not_contain ( update )
100
+ . with_stderr_contains ( HIT )
101
+ . with_stderr_does_not_contain ( MISS )
102
+ . with_stderr_does_not_contain ( UPDATE )
103
103
. run ( ) ;
104
104
}
105
+
106
+ #[ cargo_test]
107
+ fn rustc_info_cache_with_wrappers ( ) {
108
+ let wrapper_project = project ( )
109
+ . at ( "wrapper" )
110
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "wrapper" ) )
111
+ . file ( "src/main.rs" , r#"fn main() { }"# )
112
+ . build ( ) ;
113
+ let wrapper = wrapper_project. bin ( "wrapper" ) ;
114
+
115
+ let p = project ( )
116
+ . file (
117
+ "Cargo.toml" ,
118
+ r#"
119
+ [package]
120
+ name = "test"
121
+ version = "0.0.0"
122
+ authors = []
123
+ [workspace]
124
+ "# ,
125
+ )
126
+ . file ( "src/main.rs" , r#"fn main() { println!("hello"); }"# )
127
+ . build ( ) ;
128
+
129
+ for & wrapper_env in [ "RUSTC_WRAPPER" , "RUSTC_WORKSPACE_WRAPPER" ] . iter ( ) {
130
+ p. cargo ( "clean" ) . with_status ( 0 ) . run ( ) ;
131
+ wrapper_project. change_file (
132
+ "src/main.rs" ,
133
+ r#"
134
+ fn main() {
135
+ let mut args = std::env::args_os();
136
+ let _me = args.next().unwrap();
137
+ let rustc = args.next().unwrap();
138
+ let status = std::process::Command::new(rustc).args(args).status().unwrap();
139
+ std::process::exit(if status.success() { 0 } else { 1 })
140
+ }
141
+ "# ,
142
+ ) ;
143
+ wrapper_project. cargo ( "build" ) . with_status ( 0 ) . run ( ) ;
144
+
145
+ p. cargo ( "build" )
146
+ . env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
147
+ . env ( wrapper_env, & wrapper)
148
+ . with_stderr_contains ( "[..]failed to read rustc info cache[..]" )
149
+ . with_stderr_contains ( MISS )
150
+ . with_stderr_contains ( UPDATE )
151
+ . with_stderr_does_not_contain ( HIT )
152
+ . with_status ( 0 )
153
+ . run ( ) ;
154
+ p. cargo ( "build" )
155
+ . env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
156
+ . env ( wrapper_env, & wrapper)
157
+ . with_stderr_contains ( "[..]reusing existing rustc info cache[..]" )
158
+ . with_stderr_contains ( HIT )
159
+ . with_stderr_does_not_contain ( UPDATE )
160
+ . with_stderr_does_not_contain ( MISS )
161
+ . with_status ( 0 )
162
+ . run ( ) ;
163
+
164
+ wrapper_project. change_file ( "src/main.rs" , r#"fn main() { panic!() }"# ) ;
165
+ wrapper_project. cargo ( "build" ) . with_status ( 0 ) . run ( ) ;
166
+
167
+ p. cargo ( "build" )
168
+ . env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
169
+ . env ( wrapper_env, & wrapper)
170
+ . with_stderr_contains ( "[..]different compiler, creating new rustc info cache[..]" )
171
+ . with_stderr_contains ( MISS )
172
+ . with_stderr_contains ( UPDATE )
173
+ . with_stderr_does_not_contain ( HIT )
174
+ . with_status ( 101 )
175
+ . run ( ) ;
176
+ p. cargo ( "build" )
177
+ . env ( "CARGO_LOG" , "cargo::util::rustc=debug" )
178
+ . env ( wrapper_env, & wrapper)
179
+ . with_stderr_contains ( "[..]reusing existing rustc info cache[..]" )
180
+ . with_stderr_contains ( HIT )
181
+ . with_stderr_does_not_contain ( UPDATE )
182
+ . with_stderr_does_not_contain ( MISS )
183
+ . with_status ( 101 )
184
+ . run ( ) ;
185
+ }
186
+ }
0 commit comments