From 1637a0d30e5dec1102844258cecfa42be4018c5a Mon Sep 17 00:00:00 2001 From: KtorZ Date: Tue, 13 Dec 2022 16:00:29 +0100 Subject: [PATCH] Add --match-tests to 'check' cmd For running only tests matching a certain pattern. Useful when doing TDD. --- crates/cli/src/cmd/check.rs | 7 ++++++- crates/project/src/lib.rs | 22 ++++++++++++++++------ crates/project/src/options.rs | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/cli/src/cmd/check.rs b/crates/cli/src/cmd/check.rs index 1bbc1126..2ec59807 100644 --- a/crates/cli/src/cmd/check.rs +++ b/crates/cli/src/cmd/check.rs @@ -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, } 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())) } diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index a561d7ad..8ebec612 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -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) -> 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