@@ -54,6 +54,19 @@ fn fix_broken_if_requested() {
54
54
55
55
#[ test]
56
56
fn 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.
57
70
let p = project ( )
58
71
. file (
59
72
"foo/Cargo.toml" ,
@@ -74,19 +87,19 @@ fn broken_fixes_backed_out() {
74
87
use std::process::{self, Command};
75
88
76
89
fn main() {
90
+ // Ignore calls to things like --print=file-names and compiling build.rs.
77
91
let is_lib_rs = env::args_os()
78
92
.map(PathBuf::from)
79
93
.any(|l| l == Path::new("src/lib.rs"));
80
94
if is_lib_rs {
81
95
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();
88
101
} else {
89
- fs::File::create(&path ).unwrap();
102
+ fs::File::create(&first ).unwrap();
90
103
}
91
104
}
92
105
@@ -127,8 +140,6 @@ fn broken_fixes_backed_out() {
127
140
. cwd ( p. root ( ) . join ( "bar" ) )
128
141
. env ( "__CARGO_FIX_YOLO" , "1" )
129
142
. env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
130
- . with_status ( 101 )
131
- . with_stderr_contains ( "[..]not rust code[..]" )
132
143
. with_stderr_contains (
133
144
"\
134
145
warning: failed to automatically apply fixes suggested by rustc \
@@ -144,11 +155,19 @@ fn broken_fixes_backed_out() {
144
155
a number of compiler warnings after this message which cargo\n \
145
156
attempted to fix but failed. If you could open an issue at\n \
146
157
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 \
148
162
",
149
163
)
164
+ . with_stderr_contains ( "Original diagnostics will follow." )
165
+ . with_stderr_contains ( "[WARNING] variable does not need to be mutable" )
150
166
. with_stderr_does_not_contain ( "[..][FIXING][..]" )
151
167
. 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;" ) ) ;
152
171
}
153
172
154
173
#[ test]
0 commit comments