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 /// Skip tests; run only the type-checker
#[clap(short, long)] #[clap(short, long)]
skip_tests: bool, skip_tests: bool,
/// Only run tests if their path + name match the given string
#[clap(short, long)]
match_tests: Option<String>,
} }
pub fn exec( pub fn exec(
Args { Args {
directory, directory,
skip_tests, skip_tests,
match_tests,
}: Args, }: Args,
) -> miette::Result<()> { ) -> 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) 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 { let options = Options {
code_gen_mode: if skip_tests { code_gen_mode: if skip_tests {
CodeGenMode::NoOp CodeGenMode::NoOp
} else { } else {
CodeGenMode::Test CodeGenMode::Test(match_tests)
}, },
}; };
@ -145,10 +145,9 @@ where
self.write_build_outputs(programs, uplc_dump)?; self.write_build_outputs(programs, uplc_dump)?;
} }
CodeGenMode::Test => { CodeGenMode::Test(match_tests) => {
let tests = self.test_gen(&checked_modules)?; let tests = self.test_gen(&checked_modules)?;
self.run_tests(tests, match_tests);
self.run_tests(tests);
} }
CodeGenMode::NoOp => (), CodeGenMode::NoOp => (),
} }
@ -518,7 +517,7 @@ where
Ok(programs) 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 // TODO: in the future we probably just want to be able to
// tell the machine to not explode on budget consumption. // tell the machine to not explode on budget consumption.
let initial_budget = ExBudget { let initial_budget = ExBudget {
@ -533,6 +532,17 @@ where
let mut results = Vec::new(); let mut results = Vec::new();
for test in tests { 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) { match test.program.eval(initial_budget) {
(Ok(..), remaining_budget, _) => { (Ok(..), remaining_budget, _) => {
let test_info = TestInfo { let test_info = TestInfo {

View File

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