file_test_runner/
lib.rs

1// Copyright 2018-2025 the Deno authors. MIT license.
2
3pub mod collection;
4pub mod parallelism;
5pub mod reporter;
6mod runner;
7mod utils;
8
9use collection::CollectedTest;
10pub use runner::*;
11
12use std::path::Path;
13use std::path::PathBuf;
14
15use collection::CollectOptions;
16use collection::collect_tests_or_exit;
17use thiserror::Error;
18
19#[derive(Debug, Error)]
20#[error("{:#} ({})", err, path.display())]
21pub struct PathedIoError {
22  path: PathBuf,
23  err: std::io::Error,
24}
25
26impl PathedIoError {
27  pub fn new(path: &Path, err: std::io::Error) -> Self {
28    Self {
29      path: path.to_path_buf(),
30      err,
31    }
32  }
33}
34
35/// Helper function to collect and run the tests.
36pub fn collect_and_run_tests<TData: Clone + Send + 'static>(
37  collect_options: CollectOptions<TData>,
38  run_options: RunOptions<TData>,
39  run_test: impl (Fn(&CollectedTest<TData>) -> TestResult) + Send + Sync + 'static,
40) {
41  let category = collect_tests_or_exit(collect_options);
42  run_tests(&category, run_options, run_test)
43}
44
45/// Gets if a `--no-capture` or `--nocapture` flag was provided to the cli args.
46pub static NO_CAPTURE: std::sync::LazyLock<bool> =
47  std::sync::LazyLock::new(|| {
48    std::env::args().any(|arg| arg == "--no-capture" || arg == "--nocapture")
49  });