@@ -5,8 +5,8 @@ use cargo_test_support::compare::assert_match_exact;
5
5
use cargo_test_support:: git:: { self , init} ;
6
6
use cargo_test_support:: paths:: { self , CargoPathExt } ;
7
7
use cargo_test_support:: registry:: { Dependency , Package } ;
8
- use cargo_test_support:: tools ;
9
- use cargo_test_support:: { basic_manifest , is_nightly , project } ;
8
+ use cargo_test_support:: { basic_manifest , is_nightly , project , Project } ;
9
+ use cargo_test_support:: { tools , wrapped_clippy_driver } ;
10
10
11
11
#[ cargo_test]
12
12
fn do_not_fix_broken_builds ( ) {
@@ -53,8 +53,7 @@ fn fix_broken_if_requested() {
53
53
. run ( ) ;
54
54
}
55
55
56
- #[ cargo_test]
57
- fn broken_fixes_backed_out ( ) {
56
+ fn rustc_shim_for_cargo_fix ( ) -> Project {
58
57
// This works as follows:
59
58
// - Create a `rustc` shim (the "foo" project) which will pretend that the
60
59
// verification step fails.
@@ -109,7 +108,6 @@ fn broken_fixes_backed_out() {
109
108
fs::File::create(&first).unwrap();
110
109
}
111
110
}
112
-
113
111
let status = Command::new("rustc")
114
112
.args(env::args().skip(1))
115
113
.status()
@@ -142,11 +140,60 @@ fn broken_fixes_backed_out() {
142
140
// Build our rustc shim
143
141
p. cargo ( "build" ) . cwd ( "foo" ) . run ( ) ;
144
142
145
- // Attempt to fix code, but our shim will always fail the second compile
143
+ p
144
+ }
145
+
146
+ #[ cargo_test]
147
+ fn broken_fixes_backed_out ( ) {
148
+ let p = rustc_shim_for_cargo_fix ( ) ;
149
+ // Attempt to fix code, but our shim will always fail the second compile.
150
+ p. cargo ( "fix --allow-no-vcs --lib" )
151
+ . cwd ( "bar" )
152
+ . env ( "__CARGO_FIX_YOLO" , "1" )
153
+ . env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
154
+ . with_stderr_contains (
155
+ "warning: failed to automatically apply fixes suggested by rustc \
156
+ to crate `bar`\n \
157
+ \n \
158
+ after fixes were automatically applied the compiler reported \
159
+ errors within these files:\n \
160
+ \n \
161
+ * src/lib.rs\n \
162
+ \n \
163
+ This likely indicates a bug in either rustc or cargo itself,\n \
164
+ and we would appreciate a bug report! You're likely to see \n \
165
+ a number of compiler warnings after this message which cargo\n \
166
+ attempted to fix but failed. If you could open an issue at\n \
167
+ https://github.com/rust-lang/rust/issues\n \
168
+ quoting the full output of this command we'd be very appreciative!\n \
169
+ Note that you may be able to make some more progress in the near-term\n \
170
+ fixing code with the `--broken-code` flag\n \
171
+ \n \
172
+ The following errors were reported:\n \
173
+ error: expected one of `!` or `::`, found `rust`\n \
174
+ ",
175
+ )
176
+ . with_stderr_contains ( "Original diagnostics will follow." )
177
+ . with_stderr_contains ( "[WARNING] variable does not need to be mutable" )
178
+ . with_stderr_does_not_contain ( "[..][FIXED][..]" )
179
+ . run ( ) ;
180
+
181
+ // Make sure the fix which should have been applied was backed out
182
+ assert ! ( p. read_file( "bar/src/lib.rs" ) . contains( "let mut x = 3;" ) ) ;
183
+ }
184
+
185
+ #[ cargo_test]
186
+ fn broken_clippy_fixes_backed_out ( ) {
187
+ let p = rustc_shim_for_cargo_fix ( ) ;
188
+ // Attempt to fix code, but our shim will always fail the second compile.
189
+ // Also, we use `clippy` as a workspace wrapper to make sure that we properly
190
+ // generate the report bug text.
146
191
p. cargo ( "fix --allow-no-vcs --lib" )
147
192
. cwd ( "bar" )
148
193
. env ( "__CARGO_FIX_YOLO" , "1" )
149
194
. env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
195
+ // We can't use `clippy` so we use a `rustc` workspace wrapper instead
196
+ . env ( "RUSTC_WORKSPACE_WRAPPER" , wrapped_clippy_driver ( ) )
150
197
. with_stderr_contains (
151
198
"warning: failed to automatically apply fixes suggested by rustc \
152
199
to crate `bar`\n \
@@ -160,7 +207,7 @@ fn broken_fixes_backed_out() {
160
207
and we would appreciate a bug report! You're likely to see \n \
161
208
a number of compiler warnings after this message which cargo\n \
162
209
attempted to fix but failed. If you could open an issue at\n \
163
- [..] \n \
210
+ https://github.com/rust-lang/rust-clippy/issues \n \
164
211
quoting the full output of this command we'd be very appreciative!\n \
165
212
Note that you may be able to make some more progress in the near-term\n \
166
213
fixing code with the `--broken-code` flag\n \
0 commit comments