|
9 | 9 | //! compilation. Use `BLESS=1` in the environment to automatically update all
|
10 | 10 | //! tests.
|
11 | 11 | //!
|
| 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 | +//! |
12 | 17 | //! ## Dependencies
|
13 | 18 | //!
|
14 | 19 | //! By default, tests only have access to the `wasm-bindgen` and
|
@@ -57,15 +62,32 @@ fn main() -> Result<()> {
|
57 | 62 | }
|
58 | 63 | tests.sort();
|
59 | 64 |
|
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 | + } |
64 | 73 |
|
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 { |
66 | 80 | println!("{} tests passed", tests.len());
|
67 | 81 | 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); |
68 | 89 | }
|
| 90 | + |
69 | 91 | eprintln!("failed tests:\n");
|
70 | 92 | for (test, err) in errs {
|
71 | 93 | eprintln!("{} failure\n{}", test.display(), tab(&format!("{:?}", err)));
|
|
0 commit comments