Skip to content

Commit 848aa1f

Browse files
committed
Allow running the same tests with different configs in parallel
1 parent cdabcbd commit 848aa1f

File tree

9 files changed

+44
-11
lines changed

9 files changed

+44
-11
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#[cfg(feature = "rustc")]
2+
use std::sync::atomic::Ordering;
3+
#[cfg(feature = "rustc")]
4+
use ui_test::{
5+
default_file_filter, default_per_file_config, run_tests_generic, status_emitter, Config,
6+
};
7+
8+
#[cfg(feature = "rustc")]
9+
#[cfg_attr(test, test)]
10+
fn main() -> ui_test::color_eyre::Result<()> {
11+
let config = Config::rustc("examples_tests/rustc_basic");
12+
let abort_check = config.abort_check.clone();
13+
ctrlc::set_handler(move || abort_check.store(true, Ordering::Relaxed))?;
14+
15+
// Compile all `.rs` files in the given directory (relative to your
16+
// Cargo.toml) and compare their output against the corresponding
17+
// `.stderr` files.
18+
run_tests_generic(
19+
vec![config.clone(), config],
20+
default_file_filter,
21+
default_per_file_config,
22+
status_emitter::Text::verbose(),
23+
)
24+
}
25+
26+
#[cfg(not(feature = "rustc"))]
27+
fn main() -> ui_test::color_eyre::Result<()> {
28+
Ok(())
29+
}

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct Config {
4040
/// The recommended command to bless failing tests.
4141
pub bless_command: Option<String>,
4242
/// Where to dump files like the binaries compiled from tests.
43-
/// Defaults to `target/ui` in the current directory.
43+
/// Defaults to `target/ui/index_of_config` in the current directory.
4444
pub out_dir: PathBuf,
4545
/// Skip test files whose names contain any of these entries.
4646
pub skip_files: Vec<String>,

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ pub fn run_tests_generic(
182182
return Ok(());
183183
}
184184

185-
for config in &mut configs {
185+
for (i, config) in configs.iter_mut().enumerate() {
186186
config.fill_host_and_target()?;
187+
config.out_dir.push(i.to_string())
187188
}
188189

189190
let mut results = vec![];

tests/integration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ fn main() -> Result<()> {
7373
config.filter(" +[0-9]+: .*\n", "");
7474
config.filter(" +at \\.?/.*\n", "");
7575
config.filter(" running on .*", "");
76-
config.stdout_filter("/target/[^/]+/[^/]+/debug", "/target/$$TMP/$$TRIPLE/debug");
76+
config.stdout_filter(
77+
"/target/[^/]+/[0-9]+/[^/]+/debug",
78+
"/target/$$TMP/$$TRIPLE/debug",
79+
);
7780
config.stdout_filter("/target/.tmp[^/ \"]+", "/target/$$TMP");
7881
// Normalize proc macro filenames on windows to their linux repr
7982
config.stdout_filter("/([^/\\.]+)\\.dll", "/lib$1.so");

tests/integrations/basic-bin/tests/ui_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() -> ui_test::color_eyre::Result<()> {
1919
config.stdout_filter("in ([0-9]m )?[0-9\\.]+s", "");
2020
config.stderr_filter(r"[^ ]*/\.?cargo/registry/.*/", "$$CARGO_REGISTRY");
2121
config.stderr_filter(r"\.exe", "");
22-
config.stderr_filter("/target/[^/]+/[^/]+/debug", "/target/$$TMP/$$TRIPLE/debug");
22+
config.stderr_filter("/target/[^/]+/[0-9]+/[^/]+/debug", "/target/$$TMP/$$TRIPLE/debug");
2323
config.path_stderr_filter(&std::path::Path::new(path), "$DIR");
2424

2525
// hide binaries generated for successfully passing tests

tests/integrations/basic-fail/Cargo.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Location:
55
error: test failed, to rerun pass `--test ui_tests`
66

77
Caused by:
8-
process didn't exit successfully: `$DIR/target/ui/tests/integrations/basic-fail/debug/deps/ui_tests-HASH` (exit status: 1)
8+
process didn't exit successfully: `$DIR/target/ui/1/tests/integrations/basic-fail/debug/deps/ui_tests-HASH` (exit status: 1)
99
Error: tests failed
1010

1111
Location:
1212
$DIR/src/lib.rs:LL:CC
1313
error: test failed, to rerun pass `--test ui_tests_diff_only`
1414

1515
Caused by:
16-
process didn't exit successfully: `$DIR/target/ui/tests/integrations/basic-fail/debug/deps/ui_tests_diff_only-HASH` (exit status: 1)
16+
process didn't exit successfully: `$DIR/target/ui/1/tests/integrations/basic-fail/debug/deps/ui_tests_diff_only-HASH` (exit status: 1)
1717
Error: failed to parse rustc version info: invalid_foobarlaksdfalsdfj
1818

1919
Caused by:
@@ -23,15 +23,15 @@ Location:
2323
error: test failed, to rerun pass `--test ui_tests_invalid_program`
2424

2525
Caused by:
26-
process didn't exit successfully: `$DIR/target/ui/tests/integrations/basic-fail/debug/deps/ui_tests_invalid_program-HASH` (exit status: 1)
26+
process didn't exit successfully: `$DIR/target/ui/1/tests/integrations/basic-fail/debug/deps/ui_tests_invalid_program-HASH` (exit status: 1)
2727
Error: tests failed
2828

2929
Location:
3030
$DIR/src/lib.rs:LL:CC
3131
error: test failed, to rerun pass `--test ui_tests_invalid_program2`
3232

3333
Caused by:
34-
process didn't exit successfully: `$DIR/target/ui/tests/integrations/basic-fail/debug/deps/ui_tests_invalid_program2-HASH` (exit status: 1)
34+
process didn't exit successfully: `$DIR/target/ui/1/tests/integrations/basic-fail/debug/deps/ui_tests_invalid_program2-HASH` (exit status: 1)
3535
error: 4 targets failed:
3636
`--test ui_tests`
3737
`--test ui_tests_diff_only`

tests/integrations/basic-fail/Cargo.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ full stdout:
558558

559559

560560
FAILED TEST: tests/actual_tests_bless/aux_proc_macro_no_main.rs
561-
command: "rustc" "--error-format=json" "--crate-type=lib" "--out-dir" "$TMP "tests/actual_tests_bless/aux_proc_macro_no_main.rs" "--extern" "the_proc_macro=$DIR/tests/integrations/basic-fail/../../../target/$TMP/tests/actual_tests_bless/auxiliary/libthe_proc_macro.so" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/tests/actual_tests_bless/auxiliary" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "--edition" "2021"
561+
command: "rustc" "--error-format=json" "--crate-type=lib" "--out-dir" "$TMP "tests/actual_tests_bless/aux_proc_macro_no_main.rs" "--extern" "the_proc_macro=$DIR/tests/integrations/basic-fail/../../../target/$TMP/0/tests/actual_tests_bless/auxiliary/libthe_proc_macro.so" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/0/tests/actual_tests_bless/auxiliary" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "--edition" "2021"
562562

563563
error: there were 1 unmatched diagnostics
564564
--> tests/actual_tests_bless/aux_proc_macro_no_main.rs:7:8

tests/integrations/dep-fail/Cargo.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Location:
55
error: test failed, to rerun pass `--test ui`
66

77
Caused by:
8-
process didn't exit successfully: `$DIR/target/ui/tests/integrations/dep-fail/debug/deps/ui-HASH` (exit status: 1)
8+
process didn't exit successfully: `$DIR/target/ui/1/tests/integrations/dep-fail/debug/deps/ui-HASH` (exit status: 1)
99
error: 1 target failed:
1010
`--test ui`

tests/integrations/dep-fail/Cargo.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Building dependencies ... FAILED
77
tests/ui/basic_test.rs ... FAILED
88

99
FAILED TEST: tests/ui/basic_test.rs
10-
command: "$CMD" "build" "--color=never" "--quiet" "--jobs" "1" "--target-dir" "$DIR/tests/integrations/dep-fail/target/ui" "--manifest-path" "tested_crate/Cargo.toml" "--message-format=json"
10+
command: "$CMD" "build" "--color=never" "--quiet" "--jobs" "1" "--target-dir" "$DIR/tests/integrations/dep-fail/target/ui/0" "--manifest-path" "tested_crate/Cargo.toml" "--message-format=json"
1111

1212
full stderr:
1313
error: could not compile `tested_crate` (lib) due to 2 previous errors

0 commit comments

Comments
 (0)