Remove debug line for pretty-printing test, and add '--debug' flag to 'check instead.

This commit is contained in:
KtorZ 2022-12-14 22:31:25 +01:00
parent e5972640d2
commit 5024bd884c
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
5 changed files with 32 additions and 9 deletions

View File

@ -11,6 +11,10 @@ pub struct Args {
#[clap(short, long)]
skip_tests: bool,
/// When enabled, also pretty-print test UPLC on failure
#[clap(long)]
debug: bool,
/// Only run tests if their path + name match the given string
#[clap(short, long)]
match_tests: Option<String>,
@ -20,8 +24,11 @@ pub fn exec(
Args {
directory,
skip_tests,
debug,
match_tests,
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, |p| p.check(skip_tests, match_tests.clone()))
crate::with_project(directory, |p| {
p.check(skip_tests, match_tests.clone(), debug)
})
}

View File

@ -5,6 +5,7 @@ use std::sync::{
pub mod air;
pub mod ast;
pub mod builder;
pub mod builtins;
pub mod expr;
pub mod format;
@ -12,7 +13,6 @@ pub mod parser;
pub mod pretty;
pub mod tipo;
pub mod uplc;
pub mod builder;
#[derive(Debug, Default, Clone)]
pub struct IdGenerator {

View File

@ -79,10 +79,12 @@ pub enum Error {
named: NamedSource,
},
#[error("{} failed", name)]
#[error("{name} failed{}", if *verbose { format!("\n{src}") } else { String::new() } )]
TestFailure {
name: String,
path: PathBuf,
verbose: bool,
src: String,
evaluation_hint: Option<EvalHint>,
},
}

View File

@ -105,12 +105,20 @@ where
self.compile(options)
}
pub fn check(&mut self, skip_tests: bool, match_tests: Option<String>) -> Result<(), Error> {
pub fn check(
&mut self,
skip_tests: bool,
match_tests: Option<String>,
verbose: bool,
) -> Result<(), Error> {
let options = Options {
code_gen_mode: if skip_tests {
CodeGenMode::NoOp
} else {
CodeGenMode::Test(match_tests)
CodeGenMode::Test {
match_tests,
verbose,
}
},
};
@ -148,7 +156,10 @@ where
self.write_build_outputs(programs, uplc_dump)?;
Ok(())
}
CodeGenMode::Test(match_tests) => {
CodeGenMode::Test {
match_tests,
verbose,
} => {
let tests = self
.collect_scripts(&checked_modules, |def| matches!(def, Definition::Test(..)))?;
if !tests.is_empty() {
@ -165,6 +176,8 @@ where
name: e.script.name.clone(),
path: e.script.input_path.clone(),
evaluation_hint: e.script.evaluation_hint.clone(),
src: e.script.program.to_pretty(),
verbose,
})
}
})
@ -627,8 +640,6 @@ where
continue;
}
println!("{}", script.program.to_pretty());
match script.program.eval(initial_budget) {
(Ok(result), remaining_budget, _) => {
let eval_info = EvalInfo {

View File

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