From 9d7606fe63f707bffe6da2d0d56e55c1583ac188 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 31 Oct 2024 10:00:46 +0000 Subject: [PATCH] Test runner. --- ast/src/parsed/types.rs | 6 ++++++ cli/Cargo.toml | 1 + cli/src/main.rs | 31 ++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ast/src/parsed/types.rs b/ast/src/parsed/types.rs index 3a374d054b..49bed0e11d 100644 --- a/ast/src/parsed/types.rs +++ b/ast/src/parsed/types.rs @@ -416,6 +416,12 @@ impl From>> for FunctionType { } } +impl From for Type { + fn from(value: FunctionType) -> Self { + Type::Function(value) + } +} + #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)] pub struct TypeScheme { /// Type variables and their trait bounds. diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 04cc991000..097ee5b4d2 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -24,6 +24,7 @@ powdr.workspace = true clap = { version = "^4.3", features = ["derive"] } env_logger = "0.10.0" +itertools = "0.13" log = "0.4.17" strum = { version = "0.24.1", features = ["derive"] } clap-markdown = "0.1.3" diff --git a/cli/src/main.rs b/cli/src/main.rs index 6668ecb9c9..c5204b2991 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,6 @@ //! The powdr CLI tool +mod test_runner; mod util; use clap::{CommandFactory, Parser, Subcommand}; @@ -363,6 +364,24 @@ enum Commands { #[arg(value_parser = clap_enum_variants!(FieldArgument))] field: FieldArgument, }, + + /// Executes all functions starting with `test_` in every module called + /// `test` starting from the given module. + Test { + /// Input file or directory. + file: String, + + /// The field to use + #[arg(long)] + #[arg(default_value_t = FieldArgument::Gl)] + #[arg(value_parser = clap_enum_variants!(FieldArgument))] + field: FieldArgument, + + /// Also run the tests inside the standard library. + #[arg(long)] + #[arg(default_value_t = false)] + include_std_tests: bool, + }, } fn split_inputs(inputs: &str) -> Vec { @@ -469,6 +488,13 @@ fn run_command(command: Commands) { csv_mode )) } + Commands::Test { + file, + field, + include_std_tests, + } => { + call_with_field!(run_test::(&file, include_std_tests)) + } Commands::Prove { file, dir, @@ -688,10 +714,13 @@ fn run( .compute_proof() .unwrap(); } - Ok(()) } +fn run_test(file: &str, include_std_tests: bool) -> Result<(), Vec> { + test_runner::run::(file, include_std_tests) +} + #[allow(clippy::too_many_arguments)] fn read_and_prove( file: &Path,