flowey_lib_hvlite/
test_nextest_unit_tests_archive.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Run cargo-nextest based unit tests from a pre-built archive.
5//!
6//! In the context of hvlite, we consider a "unit-test" to be any test which
7//! doesn't require any special dependencies (e.g: additional binaries, disk
8//! images, etc...), and can be run simply by invoking the test bin itself.
9
10use crate::build_nextest_unit_tests::NextestUnitTestArchive;
11use crate::run_cargo_nextest_run::NextestProfile;
12use flowey::node::prelude::*;
13use flowey_lib_common::run_cargo_nextest_run::TestResults;
14
15flowey_request! {
16    pub struct Request {
17        /// Pre-built unit tests nextest archive
18        pub nextest_archive_file: ReadVar<NextestUnitTestArchive>,
19        /// Nextest profile to use when running the source code
20        pub nextest_profile: NextestProfile,
21        /// Optionally provide the nextest bin to use
22        pub nextest_bin: Option<ReadVar<PathBuf>>,
23        /// Target for the tests to run on
24        pub target: Option<ReadVar<target_lexicon::Triple>>,
25        /// Results of running the tests
26        pub results: WriteVar<TestResults>,
27    }
28}
29
30new_flow_node!(struct Node);
31
32impl FlowNode for Node {
33    type Request = Request;
34
35    fn imports(ctx: &mut ImportCtx<'_>) {
36        ctx.import::<crate::run_cargo_nextest_run::Node>();
37    }
38
39    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
40        for Request {
41            nextest_archive_file,
42            nextest_profile,
43            nextest_bin,
44            target,
45            results,
46        } in requests
47        {
48            let nextest_archive = nextest_archive_file.map(ctx, |x| x.archive_file);
49
50            ctx.req(crate::run_cargo_nextest_run::Request {
51                friendly_name: "unit-tests".into(),
52                run_kind:
53                    flowey_lib_common::run_cargo_nextest_run::NextestRunKind::RunFromArchive {
54                        archive_file: nextest_archive,
55                        target,
56                        nextest_bin,
57                    },
58                nextest_profile,
59                nextest_filter_expr: None,
60                nextest_working_dir: None,
61                nextest_config_file: None,
62                run_ignored: false,
63                extra_env: None,
64                pre_run_deps: Vec::new(), // FIXME: ensure all deps are installed
65                results,
66            })
67        }
68
69        Ok(())
70    }
71}