file_test_runner/
lib.rs

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