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

Commit c74cb4b

Browse files
committed
Refactor rustfix tests a bit
To allow us to add more fixture tests modes soon.
1 parent 17bcea9 commit c74cb4b

14 files changed

+32
-27
lines changed
File renamed without changes.
File renamed without changes.

tests/fixtures/E0178.json renamed to tests/everything/E0178.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"level": "error",
88
"spans": [
99
{
10-
"file_name": "./tests/fixtures/E0178.rs",
10+
"file_name": "./tests/everything/E0178.rs",
1111
"byte_start": 60,
1212
"byte_end": 74,
1313
"line_start": 6,
@@ -34,7 +34,7 @@
3434
"level": "help",
3535
"spans": [
3636
{
37-
"file_name": "./tests/fixtures/E0178.rs",
37+
"file_name": "./tests/everything/E0178.rs",
3838
"byte_start": 60,
3939
"byte_end": 74,
4040
"line_start": 6,
@@ -58,7 +58,7 @@
5858
"rendered": null
5959
}
6060
],
61-
"rendered": "error[E0178]: expected a path on the left-hand side of `+`, not `&'a Foo`\n --> ./tests/fixtures/E0178.rs:6:8\n |\n6 | w: &'a Foo + Send,\n | ^^^^^^^^^^^^^^ help: try adding parentheses: `&'a (Foo + Send)`\n\nIf you want more information on this error, try using \"rustc --explain E0178\"\n"
61+
"rendered": "error[E0178]: expected a path on the left-hand side of `+`, not `&'a Foo`\n --> ./tests/everything/E0178.rs:6:8\n |\n6 | w: &'a Foo + Send,\n | ^^^^^^^^^^^^^^ help: try adding parentheses: `&'a (Foo + Send)`\n\nIf you want more information on this error, try using \"rustc --explain E0178\"\n"
6262
}
6363
{
6464
"message": "aborting due to previous error",
File renamed without changes.

tests/fixtures/closure-immutable-outer-variable.json renamed to tests/everything/closure-immutable-outer-variable.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"level": "error",
88
"spans": [
99
{
10-
"file_name": "./tests/fixtures/closure-immutable-outer-variable.rs",
10+
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
1111
"byte_start": 615,
1212
"byte_end": 624,
1313
"line_start": 19,
@@ -34,7 +34,7 @@
3434
"level": "help",
3535
"spans": [
3636
{
37-
"file_name": "./tests/fixtures/closure-immutable-outer-variable.rs",
37+
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
3838
"byte_start": 580,
3939
"byte_end": 581,
4040
"line_start": 18,
@@ -58,7 +58,7 @@
5858
"rendered": null
5959
}
6060
],
61-
"rendered": "error[E0594]: cannot assign to captured outer variable in an `FnMut` closure\n --> ./tests/fixtures/closure-immutable-outer-variable.rs:19:26\n |\n18 | let y = true;\n | - help: consider making `y` mutable: `mut y`\n19 | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable\n | ^^^^^^^^^\n\nIf you want more information on this error, try using \"rustc --explain E0594\"\n"
61+
"rendered": "error[E0594]: cannot assign to captured outer variable in an `FnMut` closure\n --> ./tests/everything/closure-immutable-outer-variable.rs:19:26\n |\n18 | let y = true;\n | - help: consider making `y` mutable: `mut y`\n19 | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable\n | ^^^^^^^^^\n\nIf you want more information on this error, try using \"rustc --explain E0594\"\n"
6262
}
6363
{
6464
"message": "aborting due to previous error",

tests/fixtures/lt-generic-comp.json renamed to tests/everything/lt-generic-comp.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"level": "error",
55
"spans": [
66
{
7-
"file_name": "./tests/fixtures/lt-generic-comp.rs",
7+
"file_name": "./tests/everything/lt-generic-comp.rs",
88
"byte_start": 49,
99
"byte_end": 50,
1010
"line_start": 4,
@@ -24,7 +24,7 @@
2424
"expansion": null
2525
},
2626
{
27-
"file_name": "./tests/fixtures/lt-generic-comp.rs",
27+
"file_name": "./tests/everything/lt-generic-comp.rs",
2828
"byte_start": 47,
2929
"byte_end": 48,
3030
"line_start": 4,
@@ -51,7 +51,7 @@
5151
"level": "help",
5252
"spans": [
5353
{
54-
"file_name": "./tests/fixtures/lt-generic-comp.rs",
54+
"file_name": "./tests/everything/lt-generic-comp.rs",
5555
"byte_start": 38,
5656
"byte_end": 46,
5757
"line_start": 4,
@@ -75,7 +75,7 @@
7575
"rendered": null
7676
}
7777
],
78-
"rendered": "error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison\n --> ./tests/fixtures/lt-generic-comp.rs:4:17\n |\n4 | if x as u32 < 4 {\n | -------- ^ - interpreted as generic arguments\n | | |\n | | not interpreted as comparison\n | help: try comparing the cast value: `(x as u32)`\n\n"
78+
"rendered": "error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison\n --> ./tests/everything/lt-generic-comp.rs:4:17\n |\n4 | if x as u32 < 4 {\n | -------- ^ - interpreted as generic arguments\n | | |\n | | not interpreted as comparison\n | help: try comparing the cast value: `(x as u32)`\n\n"
7979
}
8080
{
8181
"message": "aborting due to previous error",

tests/fixtures/str-lit-type-mismatch.json renamed to tests/everything/str-lit-type-mismatch.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"level": "error",
88
"spans": [
99
{
10-
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
10+
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
1111
"byte_start": 499,
1212
"byte_end": 504,
1313
"line_start": 13,
@@ -42,7 +42,7 @@
4242
"level": "help",
4343
"spans": [
4444
{
45-
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
45+
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
4646
"byte_start": 499,
4747
"byte_end": 504,
4848
"line_start": 13,
@@ -66,7 +66,7 @@
6666
"rendered": null
6767
}
6868
],
69-
"rendered": "error[E0308]: mismatched types\n --> ./tests/fixtures/str-lit-type-mismatch.rs:13:20\n |\n13 | let x: &[u8] = \"foo\"; //~ ERROR mismatched types\n | ^^^^^\n | |\n | expected slice, found str\n | help: consider adding a leading `b`: `b\"foo\"`\n |\n = note: expected type `&[u8]`\n found type `&'static str`\n\nIf you want more information on this error, try using \"rustc --explain E0308\"\n"
69+
"rendered": "error[E0308]: mismatched types\n --> ./tests/everything/str-lit-type-mismatch.rs:13:20\n |\n13 | let x: &[u8] = \"foo\"; //~ ERROR mismatched types\n | ^^^^^\n | |\n | expected slice, found str\n | help: consider adding a leading `b`: `b\"foo\"`\n |\n = note: expected type `&[u8]`\n found type `&'static str`\n\nIf you want more information on this error, try using \"rustc --explain E0308\"\n"
7070
}
7171
{
7272
"message": "mismatched types",
@@ -77,7 +77,7 @@
7777
"level": "error",
7878
"spans": [
7979
{
80-
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
80+
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
8181
"byte_start": 555,
8282
"byte_end": 561,
8383
"line_start": 14,
@@ -112,7 +112,7 @@
112112
"level": "help",
113113
"spans": [
114114
{
115-
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
115+
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
116116
"byte_start": 555,
117117
"byte_end": 561,
118118
"line_start": 14,
@@ -136,7 +136,7 @@
136136
"rendered": null
137137
}
138138
],
139-
"rendered": "error[E0308]: mismatched types\n --> ./tests/fixtures/str-lit-type-mismatch.rs:14:23\n |\n14 | let y: &[u8; 4] = \"baaa\"; //~ ERROR mismatched types\n | ^^^^^^\n | |\n | expected array of 4 elements, found str\n | help: consider adding a leading `b`: `b\"baaa\"`\n |\n = note: expected type `&[u8; 4]`\n found type `&'static str`\n\nIf you want more information on this error, try using \"rustc --explain E0308\"\n"
139+
"rendered": "error[E0308]: mismatched types\n --> ./tests/everything/str-lit-type-mismatch.rs:14:23\n |\n14 | let y: &[u8; 4] = \"baaa\"; //~ ERROR mismatched types\n | ^^^^^^\n | |\n | expected array of 4 elements, found str\n | help: consider adding a leading `b`: `b\"baaa\"`\n |\n = note: expected type `&[u8; 4]`\n found type `&'static str`\n\nIf you want more information on this error, try using \"rustc --explain E0308\"\n"
140140
}
141141
{
142142
"message": "mismatched types",
@@ -147,7 +147,7 @@
147147
"level": "error",
148148
"spans": [
149149
{
150-
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
150+
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
151151
"byte_start": 608,
152152
"byte_end": 614,
153153
"line_start": 15,
@@ -182,7 +182,7 @@
182182
"level": "help",
183183
"spans": [
184184
{
185-
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
185+
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
186186
"byte_start": 608,
187187
"byte_end": 614,
188188
"line_start": 15,
@@ -206,7 +206,7 @@
206206
"rendered": null
207207
}
208208
],
209-
"rendered": "error[E0308]: mismatched types\n --> ./tests/fixtures/str-lit-type-mismatch.rs:15:19\n |\n15 | let z: &str = b\"foo\"; //~ ERROR mismatched types\n | ^^^^^^\n | |\n | expected str, found array of 3 elements\n | help: consider removing the leading `b`: `\"foo\"`\n |\n = note: expected type `&str`\n found type `&'static [u8; 3]`\n\nIf you want more information on this error, try using \"rustc --explain E0308\"\n"
209+
"rendered": "error[E0308]: mismatched types\n --> ./tests/everything/str-lit-type-mismatch.rs:15:19\n |\n15 | let z: &str = b\"foo\"; //~ ERROR mismatched types\n | ^^^^^^\n | |\n | expected str, found array of 3 elements\n | help: consider removing the leading `b`: `\"foo\"`\n |\n = note: expected type `&str`\n found type `&'static [u8; 3]`\n\nIf you want more information on this error, try using \"rustc --explain E0308\"\n"
210210
}
211211
{
212212
"message": "aborting due to 3 previous errors",

tests/everything.rs renamed to tests/parse_and_replace.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate rustfix;
1111
extern crate serde_json;
1212
extern crate tempdir;
1313

14-
use std::fs;
14+
use std::{env, fs};
1515
use std::error::Error;
1616
use std::path::{Path, PathBuf};
1717
use std::collections::HashSet;
@@ -135,8 +135,8 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
135135
Ok(())
136136
}
137137

138-
fn get_fixture_files() -> Result<Vec<PathBuf>, Box<Error>> {
139-
Ok(fs::read_dir("./tests/fixtures")?
138+
fn get_fixture_files(p: &str) -> Result<Vec<PathBuf>, Box<Error>> {
139+
Ok(fs::read_dir(&p)?
140140
.into_iter()
141141
.map(|e| e.unwrap().path())
142142
.filter(|p| p.is_file())
@@ -147,12 +147,17 @@ fn get_fixture_files() -> Result<Vec<PathBuf>, Box<Error>> {
147147
.collect())
148148
}
149149

150-
#[test]
151-
fn fixtures() {
152-
let _ = env_logger::try_init();
153-
154-
for file in &get_fixture_files().unwrap() {
150+
fn assert_fixtures(dir: &str, mode: &str) {
151+
for file in &get_fixture_files(&dir).unwrap() {
152+
env::set_var("RUSTFIX_MODE", mode);
155153
test_rustfix_with_file(file).unwrap();
154+
env::remove_var("RUSTFIX_MODE")
156155
info!("passed: {:?}", file);
157156
}
158157
}
158+
159+
#[test]
160+
fn everything() {
161+
let _ = env_logger::try_init();
162+
assert_fixtures("./tests/everything", "yolo");
163+
}

0 commit comments

Comments
 (0)