Skip to content

Allow configuring rustfix::Filter independently of the mode #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use regex::bytes::Regex;

use crate::{dependencies::build_dependencies, CommandBuilder, Filter, Match, Mode};
use crate::{dependencies::build_dependencies, CommandBuilder, Filter, Match, Mode, RustfixMode};
pub use color_eyre;
use color_eyre::eyre::Result;
use std::{
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Config {
root_dir: root_dir.into(),
mode: Mode::Fail {
require_patterns: true,
rustfix: true,
rustfix: RustfixMode::MachineApplicable,
},
program: CommandBuilder::rustc(),
cfgs: CommandBuilder::cfgs(),
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Config {
edition: None,
mode: Mode::Fail {
require_patterns: true,
rustfix: false,
rustfix: RustfixMode::Disabled,
},
..Self::rustc(root_dir)
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,11 @@ fn run_rustfix(
comments.find_one_for_revision(revision, "`no-rustfix` annotations", |r| r.no_rustfix)?;

let global_rustfix = match mode {
Mode::Pass | Mode::Run { .. } | Mode::Panic => false,
Mode::Pass | Mode::Run { .. } | Mode::Panic => RustfixMode::Disabled,
Mode::Fail { rustfix, .. } | Mode::Yolo { rustfix } => rustfix,
};

let fixed_code = (no_run_rustfix.is_none() && global_rustfix)
let fixed_code = (no_run_rustfix.is_none() && global_rustfix.enabled())
.then_some(())
.and_then(|()| {
let suggestions = std::str::from_utf8(stderr)
Expand All @@ -748,7 +748,7 @@ fn run_rustfix(
rustfix::get_suggestions_from_json(
line,
&HashSet::new(),
if let Mode::Yolo { .. } = config.mode {
if global_rustfix == RustfixMode::Everything {
rustfix::Filter::Everything
} else {
rustfix::Filter::MachineApplicableOnly
Expand Down
25 changes: 21 additions & 4 deletions src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ use crate::Errored;
use std::fmt::Display;
use std::process::ExitStatus;

/// When to run rustfix on tests
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum RustfixMode {
/// Do not run rustfix on the test
Disabled,
/// Apply only `MachineApplicable` suggestions emitted by the test
MachineApplicable,
/// Apply all suggestions emitted by the test
Everything,
}

impl RustfixMode {
pub(crate) fn enabled(self) -> bool {
self != RustfixMode::Disabled
}
}

#[derive(Copy, Clone, Debug)]
/// Decides what is expected of each test's exit status.
pub enum Mode {
Expand All @@ -21,13 +38,13 @@ pub enum Mode {
Fail {
/// Whether failing tests must have error patterns. Set to false if you just care about .stderr output.
require_patterns: bool,
/// Whether to run rustfix on the test if it has machine applicable suggestions.
rustfix: bool,
/// When to run rustfix on the test
rustfix: RustfixMode,
},
/// Run the tests, but always pass them as long as all annotations are satisfied and stderr files match.
Yolo {
/// Whether to run
rustfix: bool,
/// When to run rustfix on the test
rustfix: RustfixMode,
},
}

Expand Down
5 changes: 4 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,10 @@ impl<CommentsType> CommentParser<CommentsType> {
});
let Some(end) = end else {
self.error(s.span(), "`[` without corresponding `]`");
return (Spanned::new(vec![], pattern.span().shrink_to_start()), pattern);
return (
Spanned::new(vec![], pattern.span().shrink_to_start()),
pattern,
);
};
let (revision, pattern) = s.split_at(end);
let revisions = revision.split(',').map(|s| s.trim().to_string()).collect();
Expand Down
2 changes: 1 addition & 1 deletion src/status_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Text {
let Some(spinner) = threads.remove(&msg) else {
// This can happen when a test was not run at all, because it failed directly during
// comment parsing.
continue
continue;
};
spinner.set_style(
ProgressStyle::with_template("{prefix} {msg}").unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic-fail-mode/tests/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() -> ui_test::color_eyre::Result<()> {
dependencies_crate_manifest_path: Some("Cargo.toml".into()),
mode: Mode::Fail {
require_patterns: true,
rustfix: true,
rustfix: RustfixMode::MachineApplicable,
},
..Config::rustc("tests/actual_tests")
};
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/basic-fail/tests/ui_tests_bless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ fn main() -> ui_test::color_eyre::Result<()> {
for mode in [
Mode::Fail {
require_patterns: true,
rustfix: true,
rustfix: RustfixMode::MachineApplicable,
},
Mode::Yolo { rustfix: true },
Mode::Yolo { rustfix: RustfixMode::Everything },
] {
let path = "../../../target";

Expand Down