rust_doctest_runner/
main.rs

1//! A custom rustdoc test runner which essentially is a frontend for [test_runner_lib]
2//! Allowing for rustdoc tests to be run with [nextest](https://github.com/nextest-rs/nextest).
3
4use camino::Utf8PathBuf;
5use clap::Parser;
6use rust_doctest_common::Manifest;
7use test_runner_lib::{Binary, Config};
8
9/// Simple program to greet a person
10#[derive(Parser, Debug)]
11#[command(version, about, long_about = None)]
12struct Args {
13    #[arg(long, env = "RUNNER_CRATE")]
14    package: String,
15
16    #[arg(long, env = "RUNNER_DOCTEST_OUT")]
17    doctest_out: Utf8PathBuf,
18
19    #[arg(long, env = "RUNNER_CONFIG")]
20    config: Utf8PathBuf,
21
22    #[arg(long, env = "RUNNER_PROFILE")]
23    profile: String,
24
25    #[arg(long, env = "TEST_TMPDIR")]
26    tmp_dir: Utf8PathBuf,
27
28    #[arg(long, env = "XML_OUTPUT_FILE")]
29    xml_output_file: Option<Utf8PathBuf>,
30
31    #[command(flatten)]
32    args: test_runner_lib::Args,
33}
34
35fn main() {
36    let args = Args::parse();
37
38    let manifest_path = args.doctest_out.join("manifest.json");
39    let manifest = std::fs::read_to_string(manifest_path).expect("invalid manifest");
40    let manifest: Manifest = serde_json::from_str(&manifest).expect("malformed manifest");
41
42    for (var, path) in manifest.standalone_binary_envs {
43        // Safety: This function is safe to call in a single-threaded program.
44        // We are starting up so at this point there are no other threads.
45        unsafe { std::env::set_var(var, args.doctest_out.join(path)) };
46    }
47
48    test_runner_lib::run_nextest(Config {
49        config_path: args.config,
50        package: args.package.clone(),
51        profile: args.profile,
52        tmp_dir: args.tmp_dir,
53        xml_output_file: args.xml_output_file,
54        args: args.args,
55        insta: false,
56        source_dir: Utf8PathBuf::new(),
57        test_output_dir: None,
58        binaries: manifest
59            .test_binaries
60            .into_iter()
61            .map(|binary| Binary {
62                name: binary.name,
63                path: args.doctest_out.join(binary.path),
64            })
65            .collect(),
66    });
67}