@@ -54,6 +54,19 @@ fn fix_broken_if_requested() {
5454
5555#[ test]
5656fn broken_fixes_backed_out ( ) {
57+ // This works as follows:
58+ // - Create a `rustc` shim (the "foo" project) which will pretend that the
59+ // verification step fails.
60+ // - There is an empty build script so `foo` has `OUT_DIR` to track the steps.
61+ // - The first "check", `foo` creates a file in OUT_DIR, and it completes
62+ // successfully with a warning diagnostic to remove unused `mut`.
63+ // - rustfix removes the `mut`.
64+ // - The second "check" to verify the changes, `foo` swaps out the content
65+ // with something that fails to compile. It creates a second file so it
66+ // won't do anything in the third check.
67+ // - cargo fix discovers that the fix failed, and it backs out the changes.
68+ // - The third "check" is done to display the original diagnostics of the
69+ // original code.
5770 let p = project ( )
5871 . file (
5972 "foo/Cargo.toml" ,
@@ -74,19 +87,19 @@ fn broken_fixes_backed_out() {
7487 use std::process::{self, Command};
7588
7689 fn main() {
90+ // Ignore calls to things like --print=file-names and compiling build.rs.
7791 let is_lib_rs = env::args_os()
7892 .map(PathBuf::from)
7993 .any(|l| l == Path::new("src/lib.rs"));
8094 if is_lib_rs {
8195 let path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
82- let path = path.join("foo");
83- if path.exists() {
84- fs::File::create("src/lib.rs")
85- .unwrap()
86- .write_all(b"not rust code")
87- .unwrap();
96+ let first = path.join("first");
97+ let second = path.join("second");
98+ if first.exists() && !second.exists() {
99+ fs::write("src/lib.rs", b"not rust code").unwrap();
100+ fs::File::create(&second).unwrap();
88101 } else {
89- fs::File::create(&path ).unwrap();
102+ fs::File::create(&first ).unwrap();
90103 }
91104 }
92105
@@ -127,8 +140,6 @@ fn broken_fixes_backed_out() {
127140 . cwd ( p. root ( ) . join ( "bar" ) )
128141 . env ( "__CARGO_FIX_YOLO" , "1" )
129142 . env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
130- . with_status ( 101 )
131- . with_stderr_contains ( "[..]not rust code[..]" )
132143 . with_stderr_contains (
133144 "\
134145 warning: failed to automatically apply fixes suggested by rustc \
@@ -144,11 +155,19 @@ fn broken_fixes_backed_out() {
144155 a number of compiler warnings after this message which cargo\n \
145156 attempted to fix but failed. If you could open an issue at\n \
146157 https://github.com/rust-lang/cargo/issues\n \
147- quoting the full output of this command we'd be very appreciative!\
158+ quoting the full output of this command we'd be very appreciative!\n \
159+ \n \
160+ The following errors were reported:\n \
161+ error: expected one of `!` or `::`, found `rust`\n \
148162 ",
149163 )
164+ . with_stderr_contains ( "Original diagnostics will follow." )
165+ . with_stderr_contains ( "[WARNING] variable does not need to be mutable" )
150166 . with_stderr_does_not_contain ( "[..][FIXING][..]" )
151167 . run ( ) ;
168+
169+ // Make sure the fix which should have been applied was backed out
170+ assert ! ( p. read_file( "bar/src/lib.rs" ) . contains( "let mut x = 3;" ) ) ;
152171}
153172
154173#[ test]
0 commit comments