Skip to content
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

Silence subtests in Flags #247

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 3 additions & 6 deletions src/custom_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::{
process::{Command, Output},
};

use crate::{
build_manager::BuildManager, per_test_config::TestConfig, test_result::TestRun, Config, Errored,
};
use crate::{build_manager::BuildManager, per_test_config::TestConfig, Config, Errored};

#[cfg(feature = "rustc")]
pub mod run;
Expand All @@ -34,15 +32,14 @@ pub trait Flag: Send + Sync + UnwindSafe + RefUnwindSafe + std::fmt::Debug {
}

/// Run an action after a test is finished.
/// Returns an empty [`Vec`] if no action was taken.
fn post_test_action(
&self,
_config: &TestConfig<'_>,
_cmd: &mut Command,
_output: &Output,
_build_manager: &BuildManager<'_>,
) -> Result<Vec<TestRun>, Errored> {
Ok(Vec::new())
) -> Result<(), Errored> {
Ok(())
}

/// Whether the flag gets overridden by the same flag in revisions.
Expand Down
30 changes: 12 additions & 18 deletions src/custom_flags/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use std::{
process::{Command, Output},
};

use crate::{
build_manager::BuildManager, display, per_test_config::TestConfig, Error, Errored, TestOk,
TestRun,
};
use crate::{build_manager::BuildManager, display, per_test_config::TestConfig, Error, Errored};

use super::Flag;

Expand All @@ -33,7 +30,7 @@ impl Flag for Run {
cmd: &mut Command,
_output: &Output,
_build_manager: &BuildManager<'_>,
) -> Result<Vec<TestRun>, Errored> {
) -> Result<(), Errored> {
let exit_code = self.exit_code;
let revision = config.extension("run");
let config = TestConfig {
Expand Down Expand Up @@ -81,19 +78,16 @@ impl Flag for Run {
})
}

Ok(vec![TestRun {
result: if errors.is_empty() {
Ok(TestOk::Ok)
} else {
Err(Errored {
command: format!("{exe:?}"),
errors,
stderr: output.stderr,
stdout: output.stdout,
})
},
status: config.status,
}])
if errors.is_empty() {
Ok(())
} else {
Err(Errored {
command: format!("{exe:?}"),
errors,
stderr: output.stderr,
stdout: output.stdout,
})
}
}
}

Expand Down
23 changes: 8 additions & 15 deletions src/custom_flags/rustfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
display,
parser::OptWithLine,
per_test_config::{Comments, Revisioned, TestConfig},
Error, Errored, TestOk, TestRun,
Error, Errored,
};

use super::Flag;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Flag for RustfixMode {
_cmd: &mut Command,
output: &Output,
build_manager: &BuildManager<'_>,
) -> Result<Vec<TestRun>, Errored> {
) -> Result<(), Errored> {
let global_rustfix = match config.exit_status()? {
Some(Spanned {
content: 101 | 0, ..
Expand Down Expand Up @@ -170,7 +170,7 @@ fn compile_fixed(
config: &TestConfig,
build_manager: &BuildManager<'_>,
fixed_paths: Vec<PathBuf>,
) -> Result<Vec<TestRun>, Errored> {
) -> Result<(), Errored> {
// picking the crate name from the file name is problematic when `.revision_name` is inserted,
// so we compute it here before replacing the path.
let crate_name = config
Expand Down Expand Up @@ -207,7 +207,6 @@ fn compile_fixed(
.collect(),
};

let mut runs = Vec::new();
for fixed_path in fixed_paths {
let fixed_config = TestConfig {
config: config.config.clone(),
Expand All @@ -218,11 +217,9 @@ fn compile_fixed(
let mut cmd = fixed_config.build_command(build_manager)?;
cmd.arg("--crate-name").arg(&crate_name);
let output = cmd.output().unwrap();
let result = if output.status.success() {
Ok(TestOk::Ok)
} else {
if !output.status.success() {
let diagnostics = fixed_config.process(&output.stderr);
Err(Errored {
return Err(Errored {
command: format!("{cmd:?}"),
errors: vec![Error::ExitStatus {
expected: 0,
Expand All @@ -240,13 +237,9 @@ fn compile_fixed(
}],
stderr: diagnostics.rendered,
stdout: output.stdout,
})
};
runs.push(TestRun {
result,
status: fixed_config.status,
});
});
}
}

Ok(runs)
Ok(())
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn parse_and_test_file(
status,
};

let result = test_config.run_test(build_manager, &mut runs);
let result = test_config.run_test(build_manager);
runs.push(TestRun {
result,
status: test_config.status,
Expand Down
21 changes: 13 additions & 8 deletions src/per_test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub use crate::diagnostics::Level;
use crate::diagnostics::{Diagnostics, Message};
pub use crate::parser::{Comments, Condition, Revisioned};
use crate::parser::{ErrorMatch, ErrorMatchKind, OptWithLine};
use crate::status_emitter::TestStatus;
use crate::status_emitter::{SilentStatus, TestStatus};
use crate::test_result::{Errored, TestOk, TestResult};
use crate::{core::strip_path_prefix, Config, Error, Errors, OutputConflictHandling, TestRun};
use crate::{core::strip_path_prefix, Config, Error, Errors, OutputConflictHandling};

/// All information needed to run a single test
pub struct TestConfig<'a> {
Expand Down Expand Up @@ -395,11 +395,7 @@ impl TestConfig<'_> {
Ok(())
}

pub(crate) fn run_test(
&mut self,
build_manager: &BuildManager<'_>,
runs: &mut Vec<TestRun>,
) -> TestResult {
pub(crate) fn run_test(&mut self, build_manager: &BuildManager<'_>) -> TestResult {
self.patch_out_dir();

let mut cmd = self.build_command(build_manager)?;
Expand All @@ -412,10 +408,19 @@ impl TestConfig<'_> {

let output = self.check_test_result(&cmd, output)?;

let silent = TestConfig {
config: self.config.clone(),
comments: self.comments,
aux_dir: self.aux_dir,
status: Box::new(SilentStatus {
revision: self.status.revision().to_string(),
path: self.status.path().to_path_buf(),
}),
};
for rev in self.comments() {
for custom in rev.custom.values() {
for flag in &custom.content {
runs.extend(flag.post_test_action(self, &mut cmd, &output, build_manager)?);
flag.post_test_action(&silent, &mut cmd, &output, build_manager)?;
}
}
}
Expand Down
Loading