diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d92ce6d4d..76b02a206 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -53,6 +53,30 @@ jobs: name: tutorial_generator path: doc_examples/tutorial_generator/target/debug/tutorial_generator + tests: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1.6.0 + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + workspaces: "./libs -> ./target" + key: "tests" + - name: Download pavex CLI artifact + uses: actions/download-artifact@v4 + with: + name: pavex_cli + path: ~/.cargo/bin + - name: Run tests + run: | + cd libs + cargo test --no-run + cargo test --workspace --exclude="pavex_cli" + PAVEX_TEST_CLI_PATH="pavex" cargo test --package pavex_cli + is_up_to_date: runs-on: ubuntu-latest needs: diff --git a/libs/pavex_cli/tests/ui_tests.rs b/libs/pavex_cli/tests/ui_tests.rs index a87158a0d..99e5e7a2d 100644 --- a/libs/pavex_cli/tests/ui_tests.rs +++ b/libs/pavex_cli/tests/ui_tests.rs @@ -6,5 +6,16 @@ fn main() -> Result<(), Box> { let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); let test_data_folder = manifest_dir.join("tests").join("ui_tests"); let test_runtime_folder = manifest_dir.parent().unwrap().join("ui_test_envs"); - run_tests(test_data_folder, test_runtime_folder)?.exit(); + run_tests(get_cli_path()?, test_data_folder, test_runtime_folder)?.exit(); +} + +fn get_cli_path() -> Result> { + if let Ok(path) = std::env::var("PAVEX_TEST_CLI_PATH") { + return Ok(PathBuf::from_str(&path)?); + } + + let profile = std::env::var("PAVEX_TEST_CLI_PROFILE").unwrap_or("debug".to_string()); + let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR"))?; + let target_dir = manifest_dir.parent().unwrap().join("target"); + Ok(target_dir.join(profile).join("pavex")) } diff --git a/libs/pavex_test_runner/src/lib.rs b/libs/pavex_test_runner/src/lib.rs index 61a2a7b88..e590b6010 100644 --- a/libs/pavex_test_runner/src/lib.rs +++ b/libs/pavex_test_runner/src/lib.rs @@ -57,12 +57,12 @@ pub fn get_test_name(ui_tests_folder: &Path, ui_test_folder: &Path) -> String { /// Our custom test runner is built on top of `libtest_mimic`, which gives us /// [compatibility out-of-the-box](https://nexte.st/book/custom-test-harnesses.html) with `cargo-nextest`. pub fn run_tests( + cli_path: PathBuf, definition_directory: PathBuf, runtime_directory: PathBuf, ) -> Result { let arguments = libtest_mimic::Arguments::from_args(); - let cli_profile = std::env::var("PAVEX_TEST_CLI_PROFILE").unwrap_or("debug".to_string()); let target_directory_pool = TargetDirectoryPool::new(None, &runtime_directory); let mut tests = Vec::new(); @@ -77,10 +77,10 @@ pub fn run_tests( .load_configuration() .expect("Failed to load test configuration"); let is_ignored = test_configuration.ignore; - let profile = cli_profile.clone(); + let cli = cli_path.clone(); let pool = target_directory_pool.clone(); let test = libtest_mimic::Trial::test(name.clone(), move || { - run_test(test_data, test_configuration, profile, pool) + run_test(test_data, test_configuration, cli, pool) }) .with_ignored_flag(is_ignored); tests.push(test); @@ -211,7 +211,7 @@ impl TestData { fn seed_test_filesystem( &self, test_config: &TestConfig, - cli_profile: &str, + cli: &Path, target_dir: &Path, ) -> Result { Self::remove_target_junk(target_dir).context("Failed to clean up target directory")?; @@ -413,7 +413,7 @@ use pavex_cli_client::{{Client, client::Color}}; fn main() -> Result<(), Box> {{ if Client::new() .color(Color::Always) - .pavex_cli_path("../../../../../libs/target/{cli_profile}/pavex".into()) + .pavex_cli_path("{}".into()) .generate(blueprint(), "generated_app".into()) .diagnostics_path("diagnostics.dot".into()) .execute().is_err() {{ @@ -421,7 +421,8 @@ fn main() -> Result<(), Box> {{ }} Ok(()) }} -"# +"#, + cli.to_str().unwrap() ); persist_if_changed(&source_directory.join("main.rs"), main_rs.as_bytes())?; Ok(if has_tests { @@ -467,10 +468,10 @@ enum ShouldRunTests { fn run_test( test: TestData, config: TestConfig, - cli_profile: String, + cli: PathBuf, target_dir_pool: TargetDirectoryPool, ) -> Result<(), Failed> { - match _run_test(&config, &test, &cli_profile, &target_dir_pool) { + match _run_test(&config, &test, &cli, &target_dir_pool) { Ok(TestOutcome { outcome: Err(mut msg), codegen_output, @@ -514,12 +515,12 @@ fn run_test( fn _run_test( test_config: &TestConfig, test: &TestData, - cli_profile: &str, + cli: &Path, target_dir_pool: &TargetDirectoryPool, ) -> Result { let target_dir = target_dir_pool.pull(); let should_run_tests = test - .seed_test_filesystem(test_config, cli_profile, &target_dir) + .seed_test_filesystem(test_config, cli, &target_dir) .context("Failed to seed the filesystem for the test runtime folder")?; let output = std::process::Command::new("cargo")