Skip to content

Commit

Permalink
Test runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 31, 2024
1 parent f3f8c60 commit 9d7606f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ast/src/parsed/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ impl<R: Display> From<FunctionType<Expression<R>>> for FunctionType<u64> {
}
}

impl From<FunctionType> for Type {
fn from(value: FunctionType) -> Self {
Type::Function(value)
}
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)]
pub struct TypeScheme<E = u64> {
/// Type variables and their trait bounds.
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 30 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The powdr CLI tool

mod test_runner;
mod util;

use clap::{CommandFactory, Parser, Subcommand};
Expand Down Expand Up @@ -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<T: FieldElement>(inputs: &str) -> Vec<T> {
Expand Down Expand Up @@ -469,6 +488,13 @@ fn run_command(command: Commands) {
csv_mode
))
}
Commands::Test {
file,
field,
include_std_tests,
} => {
call_with_field!(run_test::<field>(&file, include_std_tests))
}
Commands::Prove {
file,
dir,
Expand Down Expand Up @@ -688,10 +714,13 @@ fn run<F: FieldElement>(
.compute_proof()
.unwrap();
}

Ok(())
}

fn run_test<T: FieldElement>(file: &str, include_std_tests: bool) -> Result<(), Vec<String>> {
test_runner::run::<T>(file, include_std_tests)
}

#[allow(clippy::too_many_arguments)]
fn read_and_prove<T: FieldElement>(
file: &Path,
Expand Down

0 comments on commit 9d7606f

Please sign in to comment.