Skip to content

Commit 8d4b5e8

Browse files
committed
Allow overwriting the output conflict handling for run tests
1 parent 5571a35 commit 8d4b5e8

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/config.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ pub struct Config {
3636
/// The binary to actually execute.
3737
pub program: CommandBuilder,
3838
/// What to do in case the stdout/stderr output differs from the expected one.
39-
pub output_conflict_handling:
40-
fn(path: &Path, actual: Vec<u8>, errors: &mut Errors, config: &Config),
39+
pub output_conflict_handling: OutputConflictHandling,
4140
/// The recommended command to bless failing tests.
4241
pub bless_command: Option<String>,
4342
/// Where to dump files like the binaries compiled from tests.
@@ -69,6 +68,9 @@ pub struct Config {
6968
pub abort_check: Arc<AtomicBool>,
7069
}
7170

71+
/// Function that performs the actual output conflict handling.
72+
pub type OutputConflictHandling = fn(&Path, Vec<u8>, &mut Errors, &Config);
73+
7274
impl Config {
7375
/// Create a blank configuration that doesn't do anything interesting
7476
pub fn dummy() -> Self {
@@ -200,7 +202,14 @@ impl Config {
200202

201203
config.custom_comments.insert("run", |parser, args, span| {
202204
let set = |exit_code| {
203-
parser.set_custom_once("run", Run { exit_code }, args.span());
205+
parser.set_custom_once(
206+
"run",
207+
Run {
208+
exit_code,
209+
output_conflict_handling: None,
210+
},
211+
args.span(),
212+
);
204213
parser.exit_status = Spanned::new(0, span.clone()).into();
205214
parser.require_annotations = Spanned::new(false, span.clone()).into();
206215

src/custom_flags/run.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{path::Path, process::Output};
66

77
use crate::{
88
build_manager::BuildManager, display, per_test_config::TestConfig,
9-
status_emitter::RevisionStyle, CommandBuilder, Error, Errored, TestOk, TestRun,
9+
status_emitter::RevisionStyle, CommandBuilder, Error, Errored, OutputConflictHandling, TestOk, TestRun,
1010
};
1111

1212
use super::Flag;
@@ -16,6 +16,8 @@ use super::Flag;
1616
pub struct Run {
1717
/// The exit code that the test is expected to emit.
1818
pub exit_code: i32,
19+
/// How to handle output conflicts
20+
pub output_conflict_handling: Option<OutputConflictHandling>,
1921
}
2022

2123
impl Flag for Run {
@@ -41,6 +43,9 @@ impl Flag for Run {
4143
aux_dir: config.aux_dir.clone(),
4244
status: config.status.for_revision(&revision, RevisionStyle::Show),
4345
};
46+
if let Some(och) = self.output_conflict_handling {
47+
config.config.output_conflict_handling = och;
48+
}
4449
build_manager.add_new_job(move || {
4550
cmd.arg("--print").arg("file-names");
4651
let output = cmd.output().unwrap();

0 commit comments

Comments
 (0)