Skip to content

Commit 2463d0d

Browse files
Faster local testing with reference.rs (#4255)
1 parent 97c05b5 commit 2463d0d

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

crates/cli/tests/reference.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
//! compilation. Use `BLESS=1` in the environment to automatically update all
1010
//! tests.
1111
//!
12+
//! Note: Tests are run sequentially. In CI, tests are run ordered by name and
13+
//! all tests will be run to show all errors. Outside of CI, recently modified
14+
//! tests are run first and the runner will stop on the first failure. This is
15+
//! done to make it faster to iterate on tests.
16+
//!
1217
//! ## Dependencies
1318
//!
1419
//! By default, tests only have access to the `wasm-bindgen` and
@@ -57,15 +62,32 @@ fn main() -> Result<()> {
5762
}
5863
tests.sort();
5964

60-
let errs = tests
61-
.iter()
62-
.filter_map(|t| runtest(t).err().map(|e| (t, e)))
63-
.collect::<Vec<_>>();
65+
let is_ci = env::var("CI").is_ok();
66+
if !is_ci {
67+
// sort test files by when they were last modified, so that we run the most
68+
// recently modified tests first. This just makes iterating on tests a bit
69+
// easier.
70+
tests.sort_by_cached_key(|p| fs::metadata(p).unwrap().modified().unwrap());
71+
tests.reverse();
72+
}
6473

65-
if errs.is_empty() {
74+
let mut errs_iter = tests.iter().filter_map(|t| {
75+
println!(" {}", t.file_name().unwrap().to_string_lossy());
76+
runtest(t).err().map(|e| (t, e))
77+
});
78+
79+
let Some(first_error) = errs_iter.next() else {
6680
println!("{} tests passed", tests.len());
6781
return Ok(());
82+
};
83+
84+
let mut errs = vec![first_error];
85+
if is_ci {
86+
// one error should be enough for local testing to ensure fast iteration
87+
// only find all errors in CI
88+
errs.extend(errs_iter);
6889
}
90+
6991
eprintln!("failed tests:\n");
7092
for (test, err) in errs {
7193
eprintln!("{} failure\n{}", test.display(), tab(&format!("{:?}", err)));

0 commit comments

Comments
 (0)