From 9972f01eb2b905a4188b24e13fd20d333827c504 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Thu, 26 Dec 2024 23:04:43 +0000 Subject: [PATCH] Fixes nbuild test, and resolves a clippy lint. --- nbuild/src/lib.rs | 12 ++++++++++-- nbuild/src/main.rs | 21 +++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/nbuild/src/lib.rs b/nbuild/src/lib.rs index 9416b5f..a516b7a 100644 --- a/nbuild/src/lib.rs +++ b/nbuild/src/lib.rs @@ -28,13 +28,21 @@ pub enum PackageKind { NBuild, } +/// Can this package be tested? +#[derive(Debug, PartialEq, Eq)] +pub enum Testable { + No, + All, + Libs, +} + /// Describes a package in this repository #[derive(Debug)] pub struct Package { pub name: &'static str, pub path: &'static std::path::Path, pub kind: PackageKind, - pub testable: bool, + pub testable: Testable, pub output_template: Option<&'static str>, } @@ -98,7 +106,7 @@ where } command_line.arg("--manifest-path"); command_line.arg(manifest_path.as_ref()); - for (k, v) in environment.into_iter() { + for (k, v) in environment.iter() { command_line.env(k, v); } diff --git a/nbuild/src/main.rs b/nbuild/src/main.rs index 90dac30..f083b88 100644 --- a/nbuild/src/main.rs +++ b/nbuild/src/main.rs @@ -47,21 +47,21 @@ fn packages() -> Vec { path: std::path::Path::new("./nbuild/Cargo.toml"), output_template: None, kind: nbuild::PackageKind::NBuild, - testable: true, + testable: nbuild::Testable::All, }, nbuild::Package { name: "flames", path: std::path::Path::new("./utilities/flames/Cargo.toml"), output_template: Some("./target/{target}/{profile}/flames"), kind: nbuild::PackageKind::Utility, - testable: false, + testable: nbuild::Testable::No, }, nbuild::Package { name: "Neotron OS", path: std::path::Path::new("./neotron-os/Cargo.toml"), output_template: Some("./target/{target}/{profile}/neotron-os"), kind: nbuild::PackageKind::Os, - testable: false, + testable: nbuild::Testable::Libs, }, ] } @@ -265,7 +265,20 @@ fn clippy(packages: &[nbuild::Package]) { /// Runs `cargo test` over all the packages fn test(packages: &[nbuild::Package]) { let mut is_error = false; - for package in packages.iter().filter(|p| p.testable) { + for package in packages + .iter() + .filter(|p| p.testable == nbuild::Testable::Libs) + { + println!("Testing {}", package.name); + if let Err(e) = nbuild::cargo(&["test", "--lib"], None, package.path) { + eprintln!("Test failed: {}", e); + is_error = true; + } + } + for package in packages + .iter() + .filter(|p| p.testable == nbuild::Testable::All) + { println!("Testing {}", package.name); if let Err(e) = nbuild::cargo(&["test"], None, package.path) { eprintln!("Test failed: {}", e);