Skip to content

Commit 75e4321

Browse files
committed
Deduplicate TestRun creation
1 parent 93863d5 commit 75e4321

File tree

5 files changed

+39
-46
lines changed

5 files changed

+39
-46
lines changed

src/build_manager.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Auxiliary and dependency builder. Extendable to custom builds.
22
33
use crate::{
4+
per_test_config::TestConfig,
45
status_emitter::{RevisionStyle, TestStatus},
5-
test_result::TestRun,
6+
test_result::{TestResult, TestRun},
67
Config, Errored,
78
};
89
use color_eyre::eyre::Result;
@@ -52,12 +53,24 @@ impl BuildManager {
5253

5354
/// Lazily add more jobs after a test has finished. These are added to the queue
5455
/// as normally, but nested below the test.
55-
pub fn add_new_job(&self, job: impl Send + 'static + FnOnce() -> TestRun) {
56+
pub fn add_new_job(
57+
&self,
58+
mut config: TestConfig,
59+
job: impl Send + 'static + FnOnce(&mut TestConfig) -> TestResult,
60+
) {
5661
if self.aborted() {
5762
return;
5863
}
5964
self.new_job_submitter
60-
.send(Box::new(move |sender| Ok(sender.send(job())?)))
65+
.send(Box::new(move |sender| {
66+
let result = job(&mut config);
67+
let result = TestRun {
68+
result,
69+
status: config.status,
70+
abort_check: config.config.abort_check,
71+
};
72+
Ok(sender.send(result)?)
73+
}))
6174
.unwrap()
6275
}
6376

src/custom_flags/run.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::Flag;
44
use crate::{
55
build_manager::BuildManager, display, per_test_config::TestConfig,
66
status_emitter::RevisionStyle, CommandBuilder, Error, Errored, OutputConflictHandling, TestOk,
7-
TestRun,
87
};
98
use bstr::ByteSlice;
109
use spanned::Spanned;
@@ -45,16 +44,10 @@ impl Flag for Run {
4544
if let Some(och) = self.output_conflict_handling {
4645
config.config.output_conflict_handling = och;
4746
}
48-
build_manager.add_new_job(move || {
47+
build_manager.add_new_job(config, move |config| {
4948
cmd.arg("--print").arg("file-names");
5049
let output = cmd.output().unwrap();
51-
if config.aborted() {
52-
return TestRun {
53-
result: Err(Errored::aborted()),
54-
status: config.status,
55-
abort_check: config.config.abort_check.clone(),
56-
};
57-
}
50+
config.aborted()?;
5851
assert!(output.status.success(), "{cmd:#?}: {output:#?}");
5952

6053
let mut files = output.stdout.lines();
@@ -81,13 +74,7 @@ impl Flag for Run {
8174
)
8275
});
8376

84-
if config.aborted() {
85-
return TestRun {
86-
result: Err(Errored::aborted()),
87-
status: config.status,
88-
abort_check: config.config.abort_check.clone(),
89-
};
90-
}
77+
config.aborted()?;
9178

9279
let mut errors = vec![];
9380

@@ -108,20 +95,15 @@ impl Flag for Run {
10895
},
10996
})
11097
}
111-
112-
TestRun {
113-
result: if errors.is_empty() {
114-
Ok(TestOk::Ok)
115-
} else {
116-
Err(Errored {
117-
command: format!("{exe:?}"),
118-
errors,
119-
stderr: output.stderr,
120-
stdout: output.stdout,
121-
})
122-
},
123-
status: config.status,
124-
abort_check: config.config.abort_check,
98+
if errors.is_empty() {
99+
Ok(TestOk::Ok)
100+
} else {
101+
Err(Errored {
102+
command: format!("{exe:?}"),
103+
errors,
104+
stderr: output.stderr,
105+
stdout: output.stdout,
106+
})
125107
}
126108
});
127109
Ok(())

src/custom_flags/rustfix.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
display,
77
parser::OptWithLine,
88
per_test_config::{Comments, Revisioned, TestConfig},
9-
Error, Errored, TestOk, TestRun,
9+
Error, Errored, TestOk,
1010
};
1111
use rustfix::{CodeFix, Filter, Suggestion};
1212
use spanned::{Span, Spanned};
@@ -214,11 +214,10 @@ fn compile_fixed(
214214
let mut cmd = fixed_config.build_command(build_manager)?;
215215
cmd.arg("--crate-name")
216216
.arg(format!("__{crate_name}_{}", i + 1));
217-
build_manager.add_new_job(move || {
217+
build_manager.add_new_job(fixed_config, move |fixed_config| {
218218
let output = cmd.output().unwrap();
219-
let result = if fixed_config.aborted() {
220-
Err(Errored::aborted())
221-
} else if output.status.success() {
219+
fixed_config.aborted()?;
220+
if output.status.success() {
222221
Ok(TestOk::Ok)
223222
} else {
224223
let diagnostics = fixed_config.process(&output.stderr);
@@ -242,11 +241,6 @@ fn compile_fixed(
242241
stderr: diagnostics.rendered,
243242
stdout: output.stdout,
244243
})
245-
};
246-
TestRun {
247-
result,
248-
status: fixed_config.status,
249-
abort_check: fixed_config.config.abort_check,
250244
}
251245
});
252246
}

src/per_test_config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,12 @@ impl TestConfig {
411411
})
412412
}
413413

414-
pub(crate) fn aborted(&self) -> bool {
415-
self.config.aborted()
414+
pub(crate) fn aborted(&self) -> Result<(), Errored> {
415+
if self.config.aborted() {
416+
Err(Errored::aborted())
417+
} else {
418+
Ok(())
419+
}
416420
}
417421

418422
/// All the environment variables set for the given revision

tests/integrations/basic-fail/Cargo.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ tests/actual_tests_bless/revisions.rs ... ok
490490
tests/actual_tests_bless/revisions.rs (revision `foo`) ... ok
491491
tests/actual_tests_bless/revisions.rs (revision `bar`) ... ok
492492
tests/actual_tests_bless/revisions_bad.rs ... ok
493-
tests/actual_tests_bless/revisions_filter.rs ... ok
494493
tests/actual_tests_bless/revisions_bad.rs (revision `foo`) ... ok
495494
tests/actual_tests_bless/revisions_bad.rs (revision `bar`) ... FAILED
495+
tests/actual_tests_bless/revisions_filter.rs ... ok
496496
tests/actual_tests_bless/revisions_filter.rs (revision `foo`) ... ignored (in-test comment)
497497
tests/actual_tests_bless/revisions_filter.rs (revision `bar`) ... ignored (in-test comment)
498498
tests/actual_tests_bless/revisions_filter2.rs ... ok

0 commit comments

Comments
 (0)