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

Commit

Permalink
Refactor rustfix tests a bit
Browse files Browse the repository at this point in the history
To allow us to add more fixture tests modes soon.
  • Loading branch information
killercup committed May 6, 2018
1 parent 17bcea9 commit c74cb4b
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 27 deletions.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/fixtures/E0178.json → tests/everything/E0178.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/E0178.rs",
"file_name": "./tests/everything/E0178.rs",
"byte_start": 60,
"byte_end": 74,
"line_start": 6,
Expand All @@ -34,7 +34,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/E0178.rs",
"file_name": "./tests/everything/E0178.rs",
"byte_start": 60,
"byte_end": 74,
"line_start": 6,
Expand All @@ -58,7 +58,7 @@
"rendered": null
}
],
"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"
"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"
}
{
"message": "aborting due to previous error",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/closure-immutable-outer-variable.rs",
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
"byte_start": 615,
"byte_end": 624,
"line_start": 19,
Expand All @@ -34,7 +34,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/closure-immutable-outer-variable.rs",
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
"byte_start": 580,
"byte_end": 581,
"line_start": 18,
Expand All @@ -58,7 +58,7 @@
"rendered": null
}
],
"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"
"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"
}
{
"message": "aborting due to previous error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/lt-generic-comp.rs",
"file_name": "./tests/everything/lt-generic-comp.rs",
"byte_start": 49,
"byte_end": 50,
"line_start": 4,
Expand All @@ -24,7 +24,7 @@
"expansion": null
},
{
"file_name": "./tests/fixtures/lt-generic-comp.rs",
"file_name": "./tests/everything/lt-generic-comp.rs",
"byte_start": 47,
"byte_end": 48,
"line_start": 4,
Expand All @@ -51,7 +51,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/lt-generic-comp.rs",
"file_name": "./tests/everything/lt-generic-comp.rs",
"byte_start": 38,
"byte_end": 46,
"line_start": 4,
Expand All @@ -75,7 +75,7 @@
"rendered": null
}
],
"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"
"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"
}
{
"message": "aborting due to previous error",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
"byte_start": 499,
"byte_end": 504,
"line_start": 13,
Expand Down Expand Up @@ -42,7 +42,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
"byte_start": 499,
"byte_end": 504,
"line_start": 13,
Expand All @@ -66,7 +66,7 @@
"rendered": null
}
],
"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"
"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"
}
{
"message": "mismatched types",
Expand All @@ -77,7 +77,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
"byte_start": 555,
"byte_end": 561,
"line_start": 14,
Expand Down Expand Up @@ -112,7 +112,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
"byte_start": 555,
"byte_end": 561,
"line_start": 14,
Expand All @@ -136,7 +136,7 @@
"rendered": null
}
],
"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"
"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"
}
{
"message": "mismatched types",
Expand All @@ -147,7 +147,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
"byte_start": 608,
"byte_end": 614,
"line_start": 15,
Expand Down Expand Up @@ -182,7 +182,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/str-lit-type-mismatch.rs",
"file_name": "./tests/everything/str-lit-type-mismatch.rs",
"byte_start": 608,
"byte_end": 614,
"line_start": 15,
Expand All @@ -206,7 +206,7 @@
"rendered": null
}
],
"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"
"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"
}
{
"message": "aborting due to 3 previous errors",
Expand Down
21 changes: 13 additions & 8 deletions tests/everything.rs → tests/parse_and_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern crate rustfix;
extern crate serde_json;
extern crate tempdir;

use std::fs;
use std::{env, fs};
use std::error::Error;
use std::path::{Path, PathBuf};
use std::collections::HashSet;
Expand Down Expand Up @@ -135,8 +135,8 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
Ok(())
}

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

#[test]
fn fixtures() {
let _ = env_logger::try_init();

for file in &get_fixture_files().unwrap() {
fn assert_fixtures(dir: &str, mode: &str) {
for file in &get_fixture_files(&dir).unwrap() {
env::set_var("RUSTFIX_MODE", mode);
test_rustfix_with_file(file).unwrap();
env::remove_var("RUSTFIX_MODE")
info!("passed: {:?}", file);
}
}

#[test]
fn everything() {
let _ = env_logger::try_init();
assert_fixtures("./tests/everything", "yolo");
}

0 comments on commit c74cb4b

Please sign in to comment.