Skip to content

Commit 6d8ad4f

Browse files
committed
Add multiple tests
1 parent d17a0e8 commit 6d8ad4f

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use std::collections::VecDeque;
99
use std::ffi::OsString;
1010
use std::fmt::Write;
11+
use std::num::NonZeroUsize;
1112
use std::path::{Path, PathBuf};
1213
use std::process::{Command, ExitStatus};
1314
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -55,6 +56,8 @@ pub struct Config {
5556
pub dependency_builder: Option<DependencyBuilder>,
5657
/// Print one character per test instead of one line
5758
pub quiet: bool,
59+
/// How many threads to use for running tests. Defaults to number of cores
60+
pub num_test_threads: NonZeroUsize,
5861
}
5962

6063
impl Default for Config {
@@ -74,6 +77,7 @@ impl Default for Config {
7477
dependencies_crate_manifest_path: None,
7578
dependency_builder: None,
7679
quiet: true,
80+
num_test_threads: std::thread::available_parallelism().unwrap(),
7781
}
7882
}
7983
}
@@ -206,7 +210,7 @@ pub fn run_tests_generic(config: Config, file_filter: impl Fn(&Path) -> bool + S
206210
let mut threads = vec![];
207211

208212
// Create N worker threads that receive files to test.
209-
for _ in 0..std::thread::available_parallelism().unwrap().get() {
213+
for _ in 0..config.num_test_threads.get() {
210214
let finished_files_sender = finished_files_sender.clone();
211215
threads.push(s.spawn(|_| -> Result<()> {
212216
let finished_files_sender = finished_files_sender;

tests/integrations/basic-fail/Cargo.stderr

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,41 @@
33
Running tests/ui_tests.rs
44
Compiler flags: ["--error-format=json", "--edition=2021"]
55
Building test dependencies...
6+
tests/actual_tests/bad_pattern.rs ... FAILED
67
tests/actual_tests/foomp.rs ... FAILED
78

9+
tests/actual_tests/bad_pattern.rs FAILED:
10+
command: "rustc" "--error-format=json" "--edition=2021" "--extern" "basic_fail=/home/ubuntu/crates/ui_test/$DIR/../../../target/debug/deps/libbasic_fail-8603f4ccb2fe730c.rmeta" "-L" "/home/ubuntu/crates/ui_test/$DIR/../../../target/debug" "-L" "/home/ubuntu/crates/ui_test/$DIR/../../../target/debug/deps" "tests/actual_tests/bad_pattern.rs"
11+
12+
substring `miesmätsched types` not found in stderr output
13+
expected because of pattern here: tests/actual_tests/bad_pattern.rs:5
14+
15+
There were 1 unmatched diagnostics at tests/actual_tests/bad_pattern.rs:4
16+
Error: mismatched types
17+
18+
full stderr:
19+
error[E0308]: mismatched types
20+
--> tests/actual_tests/bad_pattern.rs:4:9
21+
|
22+
4 | add("42", 3);
23+
| --- ^^^^ expected `usize`, found `&str`
24+
| |
25+
| arguments to this function are incorrect
26+
|
27+
note: function defined here
28+
--> /home/ubuntu/crates/ui_test/$DIR/src/lib.rs:1:8
29+
|
30+
1 | pub fn add(left: usize, right: usize) -> usize {
31+
| ^^^
32+
33+
error: aborting due to previous error
34+
35+
For more information about this error, try `rustc --explain E0308`.
36+
37+
38+
839
tests/actual_tests/foomp.rs FAILED:
9-
command: "rustc" "--error-format=json" "--edition=2021" "--extern" "basic_fail=/home/ubuntu/crates/ui_test/$DIR/../../../target/debug/deps/libbasic_fail-8603f4ccb2fe730c.rmeta" "-L" "/home/ubuntu/crates/ui_test/$DIR/../../../target/debug/deps" "-L" "/home/ubuntu/crates/ui_test/$DIR/../../../target/debug" "tests/actual_tests/foomp.rs"
40+
command: "rustc" "--error-format=json" "--edition=2021" "--extern" "basic_fail=/home/ubuntu/crates/ui_test/$DIR/../../../target/debug/deps/libbasic_fail-8603f4ccb2fe730c.rmeta" "-L" "/home/ubuntu/crates/ui_test/$DIR/../../../target/debug" "-L" "/home/ubuntu/crates/ui_test/$DIR/../../../target/debug/deps" "tests/actual_tests/foomp.rs"
1041

1142
actual output differed from expected tests/actual_tests/foomp.stderr
1243
Diff < left / right > :
@@ -55,7 +86,8 @@ For more information about this error, try `rustc --explain E0308`.
5586

5687

5788
FAILURES:
89+
tests/actual_tests/bad_pattern.rs
5890
tests/actual_tests/foomp.rs
5991

60-
test result: FAIL. 1 tests failed, 0 tests passed, 0 ignored, 0 filtered out
92+
test result: FAIL. 2 tests failed, 0 tests passed, 0 ignored, 0 filtered out
6193
error: test failed, to rerun pass '--test ui_tests'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use basic_fail::add;
2+
3+
fn main() {
4+
add("42", 3);
5+
//~^ ERROR: miesmätsched types
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/bad_pattern.rs:4:9
3+
|
4+
4 | add("42", 3);
5+
| --- ^^^^ expected `usize`, found `&str`
6+
| |
7+
| arguments to this function are incorrect
8+
|
9+
note: function defined here
10+
--> $DIR/tests/integrations/basic-fail/src/lib.rs:1:8
11+
|
12+
1 | pub fn add(left: usize, right: usize) -> usize {
13+
| ^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::num::NonZeroUsize;
12
use ui_test::*;
23

34
fn main() -> ui_test::color_eyre::Result<()> {
@@ -13,6 +14,8 @@ fn main() -> ui_test::color_eyre::Result<()> {
1314
}),
1415
// Never bless integrations-fail tests, we want to see stderr mismatches
1516
output_conflict_handling: OutputConflictHandling::Error,
17+
// Make sure our tests are ordered for reliable output.
18+
num_test_threads: NonZeroUsize::new(1).unwrap(),
1619
..Config::default()
1720
};
1821
config.args.push("--edition=2021".into());

0 commit comments

Comments
 (0)