Merge pull request #248 from aiken-lang/rvcas/match_tests
`aiken check` make match tests flag fancier
This commit is contained in:
commit
e61a56566d
|
@ -152,8 +152,9 @@ where
|
||||||
pub fn check(
|
pub fn check(
|
||||||
&mut self,
|
&mut self,
|
||||||
skip_tests: bool,
|
skip_tests: bool,
|
||||||
match_tests: Option<String>,
|
match_tests: Option<Vec<String>>,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
|
exact_match: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let options = Options {
|
let options = Options {
|
||||||
code_gen_mode: if skip_tests {
|
code_gen_mode: if skip_tests {
|
||||||
|
@ -162,6 +163,7 @@ where
|
||||||
CodeGenMode::Test {
|
CodeGenMode::Test {
|
||||||
match_tests,
|
match_tests,
|
||||||
verbose,
|
verbose,
|
||||||
|
exact_match,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -202,6 +204,7 @@ where
|
||||||
CodeGenMode::Test {
|
CodeGenMode::Test {
|
||||||
match_tests,
|
match_tests,
|
||||||
verbose,
|
verbose,
|
||||||
|
exact_match,
|
||||||
} => {
|
} => {
|
||||||
let tests =
|
let tests =
|
||||||
self.collect_scripts(verbose, |def| matches!(def, Definition::Test(..)))?;
|
self.collect_scripts(verbose, |def| matches!(def, Definition::Test(..)))?;
|
||||||
|
@ -210,7 +213,7 @@ where
|
||||||
self.event_listener.handle_event(Event::RunningTests);
|
self.event_listener.handle_event(Event::RunningTests);
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = self.eval_scripts(tests, match_tests);
|
let results = self.eval_scripts(tests, match_tests, exact_match);
|
||||||
|
|
||||||
let errors: Vec<Error> = results
|
let errors: Vec<Error> = results
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -692,7 +695,12 @@ where
|
||||||
Ok(programs)
|
Ok(programs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval_scripts(&self, scripts: Vec<Script>, match_name: Option<String>) -> Vec<EvalInfo> {
|
fn eval_scripts(
|
||||||
|
&self,
|
||||||
|
scripts: Vec<Script>,
|
||||||
|
match_tests: Option<Vec<String>>,
|
||||||
|
exact_match: bool,
|
||||||
|
) -> Vec<EvalInfo> {
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
// TODO: in the future we probably just want to be able to
|
// TODO: in the future we probably just want to be able to
|
||||||
|
@ -702,14 +710,54 @@ where
|
||||||
cpu: i64::MAX,
|
cpu: i64::MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let scripts = if let Some(match_tests) = match_tests {
|
||||||
|
let match_tests: Vec<(&str, Option<Vec<String>>)> = match_tests
|
||||||
|
.iter()
|
||||||
|
.map(|match_test| {
|
||||||
|
let mut match_split_dot = match_test.split('.');
|
||||||
|
|
||||||
|
let match_module = if match_test.contains('.') {
|
||||||
|
match_split_dot.next().unwrap_or("")
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
|
||||||
|
let match_names = match_split_dot.next().map(|names| {
|
||||||
|
let names = names.replace(&['{', '}'][..], "");
|
||||||
|
|
||||||
|
let names_split_comma = names.split(',');
|
||||||
|
|
||||||
|
names_split_comma.map(str::to_string).collect()
|
||||||
|
});
|
||||||
|
|
||||||
|
(match_module, match_names)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
scripts
|
scripts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|script| -> bool {
|
.filter(|script| -> bool {
|
||||||
let path = format!("{}{}", script.module, script.name);
|
match_tests.iter().any(|(module, names)| {
|
||||||
|
let matched_module = module == &"" || script.module.contains(module);
|
||||||
|
|
||||||
!matches!(&match_name, Some(search_str) if !path.contains(search_str))
|
let matched_name = matches!(names, Some(names) if names
|
||||||
|
.iter()
|
||||||
|
.any(|name| if exact_match {
|
||||||
|
name == &script.name
|
||||||
|
} else {
|
||||||
|
script.name.contains(name)
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
matched_module && matched_name
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<Script>>()
|
.collect::<Vec<Script>>()
|
||||||
|
} else {
|
||||||
|
scripts
|
||||||
|
};
|
||||||
|
|
||||||
|
scripts
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|script| match script.program.eval(initial_budget) {
|
.map(|script| match script.program.eval(initial_budget) {
|
||||||
(Ok(result), remaining_budget, logs) => EvalInfo {
|
(Ok(result), remaining_budget, logs) => EvalInfo {
|
||||||
|
|
|
@ -4,8 +4,9 @@ pub struct Options {
|
||||||
|
|
||||||
pub enum CodeGenMode {
|
pub enum CodeGenMode {
|
||||||
Test {
|
Test {
|
||||||
match_tests: Option<String>,
|
match_tests: Option<Vec<String>>,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
|
exact_match: bool,
|
||||||
},
|
},
|
||||||
Build(bool),
|
Build(bool),
|
||||||
NoOp,
|
NoOp,
|
||||||
|
|
|
@ -14,9 +14,16 @@ pub struct Args {
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
debug: bool,
|
debug: bool,
|
||||||
|
|
||||||
/// Only run tests if their path + name match the given string
|
/// Only run tests if they match any of these strings.
|
||||||
|
/// You can match a module with `-m aiken/list` or `-m list`.
|
||||||
|
/// You can match a test with `-m "aiken/list.{map}"` or `-m "aiken/option.{flatten_1}"`
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
match_tests: Option<String>,
|
match_tests: Option<Vec<String>>,
|
||||||
|
|
||||||
|
/// This is meant to be used with `--match-tests`.
|
||||||
|
/// It forces test names to match exactly
|
||||||
|
#[clap(short, long)]
|
||||||
|
exact_match: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(
|
pub fn exec(
|
||||||
|
@ -25,9 +32,10 @@ pub fn exec(
|
||||||
skip_tests,
|
skip_tests,
|
||||||
debug,
|
debug,
|
||||||
match_tests,
|
match_tests,
|
||||||
|
exact_match,
|
||||||
}: Args,
|
}: Args,
|
||||||
) -> miette::Result<()> {
|
) -> miette::Result<()> {
|
||||||
crate::with_project(directory, |p| {
|
crate::with_project(directory, |p| {
|
||||||
p.check(skip_tests, match_tests.clone(), debug)
|
p.check(skip_tests, match_tests.clone(), debug, exact_match)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue