Skip to content

Commit 8ae1ec6

Browse files
committed
Spawn one subprocess per unit test when panic=abort
1 parent 76b12bd commit 8ae1ec6

File tree

5 files changed

+304
-100
lines changed

5 files changed

+304
-100
lines changed

src/librustc_interface/passes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ fn configure_and_expand_inner<'a>(
440440
&mut krate,
441441
sess.diagnostic(),
442442
&sess.features_untracked(),
443+
sess.panic_strategy(),
443444
)
444445
});
445446

src/libsyntax_ext/test_harness.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use log::debug;
44
use smallvec::{smallvec, SmallVec};
5+
use rustc_target::spec::PanicStrategy;
56
use syntax::ast::{self, Ident};
67
use syntax::attr;
78
use syntax::entry::{self, EntryPointType};
@@ -25,6 +26,7 @@ struct Test {
2526

2627
struct TestCtxt<'a> {
2728
ext_cx: ExtCtxt<'a>,
29+
panic_strategy: PanicStrategy,
2830
def_site: Span,
2931
test_cases: Vec<Test>,
3032
reexport_test_harness_main: Option<Symbol>,
@@ -40,6 +42,7 @@ pub fn inject(
4042
krate: &mut ast::Crate,
4143
span_diagnostic: &errors::Handler,
4244
features: &Features,
45+
panic_strategy: PanicStrategy,
4346
) {
4447
// Check for #![reexport_test_harness_main = "some_name"] which gives the
4548
// main test function the name `some_name` without hygiene. This needs to be
@@ -54,7 +57,7 @@ pub fn inject(
5457

5558
if should_test {
5659
generate_test_harness(sess, resolver, reexport_test_harness_main,
57-
krate, features, test_runner)
60+
krate, features, panic_strategy, test_runner)
5861
}
5962
}
6063

@@ -183,6 +186,7 @@ fn generate_test_harness(sess: &ParseSess,
183186
reexport_test_harness_main: Option<Symbol>,
184187
krate: &mut ast::Crate,
185188
features: &Features,
189+
panic_strategy: PanicStrategy,
186190
test_runner: Option<ast::Path>) {
187191
let mut econfig = ExpansionConfig::default("test".to_string());
188192
econfig.features = Some(features);
@@ -203,6 +207,7 @@ fn generate_test_harness(sess: &ParseSess,
203207

204208
let cx = TestCtxt {
205209
ext_cx,
210+
panic_strategy,
206211
def_site,
207212
test_cases: Vec::new(),
208213
reexport_test_harness_main,
@@ -248,9 +253,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
248253
let ecx = &cx.ext_cx;
249254
let test_id = Ident::new(sym::test, sp);
250255

256+
let runner_name = match cx.panic_strategy {
257+
PanicStrategy::Unwind => "test_main_static",
258+
PanicStrategy::Abort => "test_main_static_abort",
259+
};
260+
251261
// test::test_main_static(...)
252262
let mut test_runner = cx.test_runner.clone().unwrap_or(
253-
ecx.path(sp, vec![test_id, ecx.ident_of("test_main_static", sp)]));
263+
ecx.path(sp, vec![test_id, ecx.ident_of(runner_name, sp)]));
254264

255265
test_runner.span = sp;
256266

src/libtest/formatters/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ pub(crate) trait OutputFormatter {
2222
) -> io::Result<()>;
2323
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool>;
2424
}
25+
26+
pub(crate) fn write_stderr_delimiter(test_output: &mut Vec<u8>, test_name: &TestName) {
27+
match test_output.last() {
28+
Some(b'\n') => (),
29+
Some(_) => test_output.push(b'\n'),
30+
None => (),
31+
}
32+
write!(test_output, "---- {} stderr ----\n", test_name).unwrap();
33+
}

0 commit comments

Comments
 (0)