Add --match-tests to 'check' cmd

For running only tests matching a certain pattern. Useful when doing TDD.
This commit is contained in:
KtorZ 2022-12-13 16:00:29 +01:00 committed by Lucas
parent 0d891daac8
commit 1637a0d30e
3 changed files with 23 additions and 8 deletions

View File

@ -10,13 +10,18 @@ pub struct Args {
/// Skip tests; run only the type-checker
#[clap(short, long)]
skip_tests: bool,
/// Only run tests if their path + name match the given string
#[clap(short, long)]
match_tests: Option<String>,
}
pub fn exec(
Args {
directory,
skip_tests,
match_tests,
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, |p| p.check(skip_tests))
crate::with_project(directory, |p| p.check(skip_tests, match_tests.clone()))
}

View File

@ -101,12 +101,12 @@ where
self.compile(options)
}
pub fn check(&mut self, skip_tests: bool) -> Result<(), Error> {
pub fn check(&mut self, skip_tests: bool, match_tests: Option<String>) -> Result<(), Error> {
let options = Options {
code_gen_mode: if skip_tests {
CodeGenMode::NoOp
} else {
CodeGenMode::Test
CodeGenMode::Test(match_tests)
},
};
@ -145,10 +145,9 @@ where
self.write_build_outputs(programs, uplc_dump)?;
}
CodeGenMode::Test => {
CodeGenMode::Test(match_tests) => {
let tests = self.test_gen(&checked_modules)?;
self.run_tests(tests);
self.run_tests(tests, match_tests);
}
CodeGenMode::NoOp => (),
}
@ -518,7 +517,7 @@ where
Ok(programs)
}
fn run_tests(&self, tests: Vec<Script>) {
fn run_tests(&self, tests: Vec<Script>, match_tests: Option<String>) {
// TODO: in the future we probably just want to be able to
// tell the machine to not explode on budget consumption.
let initial_budget = ExBudget {
@ -533,6 +532,17 @@ where
let mut results = Vec::new();
for test in tests {
let path = format!("{}{}", test.module, test.name);
match match_tests.clone() {
None => {}
Some(search_str) => {
if !path.to_string().contains(&search_str) {
continue;
}
}
}
match test.program.eval(initial_budget) {
(Ok(..), remaining_budget, _) => {
let test_info = TestInfo {

View File

@ -3,7 +3,7 @@ pub struct Options {
}
pub enum CodeGenMode {
Test,
Test(Option<String>),
Build(bool),
NoOp,
}