@@ -5,8 +5,8 @@ use cargo_test_support::compare::assert_match_exact;
55use cargo_test_support:: git:: { self , init} ;
66use cargo_test_support:: paths:: { self , CargoPathExt } ;
77use 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 } ;
1010
1111#[ cargo_test]
1212fn do_not_fix_broken_builds ( ) {
@@ -53,8 +53,7 @@ fn fix_broken_if_requested() {
5353 . run ( ) ;
5454}
5555
56- #[ cargo_test]
57- fn broken_fixes_backed_out ( ) {
56+ fn rustc_shim_for_cargo_fix ( ) -> Project {
5857 // This works as follows:
5958 // - Create a `rustc` shim (the "foo" project) which will pretend that the
6059 // verification step fails.
@@ -109,7 +108,6 @@ fn broken_fixes_backed_out() {
109108 fs::File::create(&first).unwrap();
110109 }
111110 }
112-
113111 let status = Command::new("rustc")
114112 .args(env::args().skip(1))
115113 .status()
@@ -142,11 +140,60 @@ fn broken_fixes_backed_out() {
142140 // Build our rustc shim
143141 p. cargo ( "build" ) . cwd ( "foo" ) . run ( ) ;
144142
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.
146191 p. cargo ( "fix --allow-no-vcs --lib" )
147192 . cwd ( "bar" )
148193 . env ( "__CARGO_FIX_YOLO" , "1" )
149194 . 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 ( ) )
150197 . with_stderr_contains (
151198 "warning: failed to automatically apply fixes suggested by rustc \
152199 to crate `bar`\n \
@@ -160,7 +207,7 @@ fn broken_fixes_backed_out() {
160207 and we would appreciate a bug report! You're likely to see \n \
161208 a number of compiler warnings after this message which cargo\n \
162209 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 \
164211 quoting the full output of this command we'd be very appreciative!\n \
165212 Note that you may be able to make some more progress in the near-term\n \
166213 fixing code with the `--broken-code` flag\n \
0 commit comments