Skip to content

Commit

Permalink
Auto merge of #13047 - tompscanlan:rustfix-ignored-tests, r=weihanglo
Browse files Browse the repository at this point in the history
review and remove ignored tests in rustfix

### What does this PR try to resolve?
review ignored tests in rustfix crate per #13034.

### How should we test and review this PR?
CI testing

### Additional information

* Removed unproductive test in `parse_and_replace`
* un-ignore proptests, and reduce runtime from ~2s to ~<.25s
  • Loading branch information
bors committed Nov 26, 2023
2 parents 35ed69c + b179cd1 commit 3920bd5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
4 changes: 1 addition & 3 deletions crates/rustfix/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,16 @@ mod tests {

proptest! {
#[test]
#[ignore]
fn new_to_vec_roundtrip(ref s in "\\PC*") {
assert_eq!(s.as_bytes(), Data::new(s.as_bytes()).to_vec().as_slice());
}

#[test]
#[ignore]
fn replace_random_chunks(
ref data in "\\PC*",
ref replacements in prop::collection::vec(
(any::<::std::ops::Range<usize>>(), any::<Vec<u8>>()),
1..1337,
1..100,
)
) {
let mut d = Data::new(data.as_bytes());
Expand Down
2 changes: 0 additions & 2 deletions crates/rustfix/tests/edition/.gitignore

This file was deleted.

30 changes: 9 additions & 21 deletions crates/rustfix/tests/parse_and_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use tracing::{debug, info, warn};

mod fixmode {
pub const EVERYTHING: &str = "yolo";
pub const EDITION: &str = "edition";
}

mod settings {
Expand All @@ -23,10 +22,10 @@ mod settings {
pub const RECORD_FIXED_RUST: &str = "RUSTFIX_TEST_RECORD_FIXED_RUST";
}

fn compile(file: &Path, mode: &str) -> Result<Output, Error> {
fn compile(file: &Path) -> Result<Output, Error> {
let tmp = tempdir()?;

let mut args: Vec<OsString> = vec![
let args: Vec<OsString> = vec![
file.into(),
"--error-format=json".into(),
"--emit=metadata".into(),
Expand All @@ -35,10 +34,6 @@ fn compile(file: &Path, mode: &str) -> Result<Output, Error> {
tmp.path().into(),
];

if mode == fixmode::EDITION {
args.push("--edition=2018".into());
}

let res = Command::new(env::var_os("RUSTC").unwrap_or("rustc".into()))
.args(&args)
.env("CLIPPY_DISABLE_DOCS_LINKS", "true")
Expand All @@ -48,8 +43,8 @@ fn compile(file: &Path, mode: &str) -> Result<Output, Error> {
Ok(res)
}

fn compile_and_get_json_errors(file: &Path, mode: &str) -> Result<String, Error> {
let res = compile(file, mode)?;
fn compile_and_get_json_errors(file: &Path) -> Result<String, Error> {
let res = compile(file)?;
let stderr = String::from_utf8(res.stderr)?;
if stderr.contains("is only accepted on the nightly compiler") {
panic!("rustfix tests require a nightly compiler");
Expand All @@ -65,8 +60,8 @@ fn compile_and_get_json_errors(file: &Path, mode: &str) -> Result<String, Error>
}
}

fn compiles_without_errors(file: &Path, mode: &str) -> Result<(), Error> {
let res = compile(file, mode)?;
fn compiles_without_errors(file: &Path) -> Result<(), Error> {
let res = compile(file)?;

match res.status.code() {
Some(0) => Ok(()),
Expand Down Expand Up @@ -139,8 +134,8 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err

debug!("next up: {:?}", file);
let code = read_file(file).context(format!("could not read {}", file.display()))?;
let errors = compile_and_get_json_errors(file, mode)
.context(format!("could compile {}", file.display()))?;
let errors =
compile_and_get_json_errors(file).context(format!("could compile {}", file.display()))?;
let suggestions =
rustfix::get_suggestions_from_json(&errors, &HashSet::new(), filter_suggestions)
.context("could not load suggestions")?;
Expand Down Expand Up @@ -190,7 +185,7 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
diff(fixed.trim(), expected_fixed.trim())
);

compiles_without_errors(&fixed_file, mode)?;
compiles_without_errors(&fixed_file)?;

Ok(())
}
Expand Down Expand Up @@ -237,10 +232,3 @@ fn everything() {
tracing_subscriber::fmt::init();
assert_fixtures("./tests/everything", fixmode::EVERYTHING);
}

#[test]
#[ignore = "Requires custom rustc build"]
fn edition() {
tracing_subscriber::fmt::init();
assert_fixtures("./tests/edition", fixmode::EDITION);
}

0 comments on commit 3920bd5

Please sign in to comment.