Skip to content

Commit

Permalink
Run tests in CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Jan 4, 2024
1 parent c9e1478 commit 5e1f0db
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- 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:
Expand Down
13 changes: 12 additions & 1 deletion libs/pavex_cli/tests/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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<PathBuf, Box<dyn std::error::Error>> {
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"))
}
21 changes: 11 additions & 10 deletions libs/pavex_test_runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Conclusion, anyhow::Error> {
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();
Expand All @@ -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);
Expand Down Expand Up @@ -211,7 +211,7 @@ impl TestData {
fn seed_test_filesystem(
&self,
test_config: &TestConfig,
cli_profile: &str,
cli: &Path,
target_dir: &Path,
) -> Result<ShouldRunTests, anyhow::Error> {
Self::remove_target_junk(target_dir).context("Failed to clean up target directory")?;
Expand Down Expand Up @@ -413,15 +413,16 @@ use pavex_cli_client::{{Client, client::Color}};
fn main() -> Result<(), Box<dyn std::error::Error>> {{
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() {{
std::process::exit(1);
}}
Ok(())
}}
"#
"#,
cli.to_str().unwrap()
);
persist_if_changed(&source_directory.join("main.rs"), main_rs.as_bytes())?;
Ok(if has_tests {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<TestOutcome, anyhow::Error> {
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")
Expand Down

0 comments on commit 5e1f0db

Please sign in to comment.