Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 5e71ec2

Browse files
committed
Add a .fix_everything() test helper
1 parent 2eaaa75 commit 5e71ec2

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

cargo-fix/tests/all/broken_build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn fix_broken_if_requested() {
3737
.build();
3838

3939
p.expect_cmd("cargo-fix fix --broken-code")
40-
.env("__CARGO_FIX_YOLO", "true")
40+
.fix_everything()
4141
.status(0)
4242
.run();
4343
}
@@ -114,7 +114,7 @@ fn broken_fixes_backed_out() {
114114

115115
// Attempt to fix code, but our shim will always fail the second compile
116116
p.expect_cmd("cargo-fix fix")
117-
.env("__CARGO_FIX_YOLO", "true")
117+
.fix_everything()
118118
.cwd("bar")
119119
.env("RUSTC", p.root.join("foo/target/debug/foo"))
120120
.stderr_contains("not rust code")

cargo-fix/tests/all/broken_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// .build();
2020

2121
// p.expect_cmd("cargo-fix fix")
22-
// .env("__CARGO_FIX_YOLO", "true")
22+
// .fix_everything()
2323
// .stderr_contains(r"warning: error applying suggestions to `src/lib.rs`")
2424
// .stderr_contains("The full error message was:")
2525
// .stderr_contains("> Could not replace range 56...60 in file -- maybe parts of it were already replaced?")

cargo-fix/tests/all/dependencies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn fix_path_deps() {
5454
[FINISHED] dev [unoptimized + debuginfo]
5555
";
5656
p.expect_cmd("cargo-fix fix")
57-
.env("__CARGO_FIX_YOLO", "true")
57+
.fix_everything()
5858
.stdout("")
5959
.stderr(stderr)
6060
.run();

cargo-fix/tests/all/edition_upgrade.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn upgrade_extern_crate() {
161161
[FINISHED] dev [unoptimized + debuginfo]
162162
";
163163
p.expect_cmd("cargo-fix fix")
164-
.env("__CARGO_FIX_YOLO", "true")
164+
.fix_everything()
165165
.stdout("")
166166
.stderr(stderr)
167167
.run();

cargo-fix/tests/all/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ impl<'a> ExpectCmd<'a> {
151151
self
152152
}
153153

154+
fn fix_everything(&mut self) -> &mut Self {
155+
self.env("__CARGO_FIX_YOLO", "true");
156+
self
157+
}
158+
154159
fn stdout(&mut self, s: &str) -> &mut Self {
155160
self.stdout = Some(s.to_string());
156161
self

cargo-fix/tests/all/smoke.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn fixes_extra_mut() {
3434
[FINISHED] dev [unoptimized + debuginfo]
3535
";
3636
p.expect_cmd("cargo-fix fix")
37-
.env("__CARGO_FIX_YOLO", "true")
37+
.fix_everything()
3838
.stdout("")
3939
.stderr(stderr)
4040
.run();
@@ -61,7 +61,7 @@ fn fixes_two_missing_ampersands() {
6161
[FINISHED] dev [unoptimized + debuginfo]
6262
";
6363
p.expect_cmd("cargo-fix fix")
64-
.env("__CARGO_FIX_YOLO", "true")
64+
.fix_everything()
6565
.stdout("")
6666
.stderr(stderr)
6767
.run();
@@ -87,7 +87,7 @@ fn tricky() {
8787
[FINISHED] dev [unoptimized + debuginfo]
8888
";
8989
p.expect_cmd("cargo-fix fix")
90-
.env("__CARGO_FIX_YOLO", "true")
90+
.fix_everything()
9191
.stdout("")
9292
.stderr(stderr)
9393
.run();
@@ -106,7 +106,7 @@ fn preserve_line_endings() {
106106
.build();
107107

108108
p.expect_cmd("cargo-fix fix")
109-
.env("__CARGO_FIX_YOLO", "true")
109+
.fix_everything()
110110
.run();
111111
assert!(p.read("src/lib.rs").contains("\r\n"));
112112
}
@@ -124,7 +124,7 @@ fn fix_deny_warnings() {
124124
.build();
125125

126126
p.expect_cmd("cargo-fix fix")
127-
.env("__CARGO_FIX_YOLO", "true")
127+
.fix_everything()
128128
.run();
129129
}
130130

@@ -147,7 +147,7 @@ fn fix_deny_warnings_but_not_others() {
147147
.build();
148148

149149
p.expect_cmd("cargo-fix fix")
150-
.env("__CARGO_FIX_YOLO", "true")
150+
.fix_everything()
151151
.run();
152152
assert!(!p.read("src/lib.rs").contains("let mut x = 3;"));
153153
assert!(p.read("src/lib.rs").contains("fn bar() {}"));
@@ -179,7 +179,7 @@ fn fix_two_files() {
179179
.build();
180180

181181
p.expect_cmd("cargo-fix fix")
182-
.env("__CARGO_FIX_YOLO", "true")
182+
.fix_everything()
183183
.stderr_contains("[FIXING] src/bar.rs (1 fix)")
184184
.stderr_contains("[FIXING] src/lib.rs (1 fix)")
185185
.run();

cargo-fix/tests/all/subtargets.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn fixes_missing_ampersand() {
4040
.build();
4141

4242
p.expect_cmd("cargo fix -- --all-targets")
43-
.env("__CARGO_FIX_YOLO", "true")
43+
.fix_everything()
4444
.stdout("")
4545
.stderr_contains("[COMPILING] foo v0.1.0 (CWD)")
4646
.stderr_contains("[FIXING] build.rs (1 fix)")

0 commit comments

Comments
 (0)