Implement test runner.

easy.
This commit is contained in:
KtorZ 2022-12-08 16:23:21 +01:00 committed by rvcas
parent 384c4daa4a
commit 4cdb5d8d02
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
1 changed files with 24 additions and 2 deletions

View File

@ -78,11 +78,11 @@ impl Project {
} }
pub fn build(&mut self, uplc: bool) -> Result<(), Error> { pub fn build(&mut self, uplc: bool) -> Result<(), Error> {
self.compile(true, uplc) self.compile(true, uplc, false)
} }
pub fn check(&mut self) -> Result<(), Error> { pub fn check(&mut self) -> Result<(), Error> {
self.compile(false, false) self.compile(false, false, true)
} }
pub fn compile( pub fn compile(
@ -101,12 +101,19 @@ impl Project {
let validators = self.validate_validators(&mut checked_modules)?; let validators = self.validate_validators(&mut checked_modules)?;
// TODO: In principle, uplc_gen and run_tests can't be true together. We probably want to
// model the options differently to make it obvious at the type-level.
if uplc_gen { if uplc_gen {
let programs = self.code_gen(validators, &checked_modules)?; let programs = self.code_gen(validators, &checked_modules)?;
self.write_build_outputs(programs, uplc_dump)?; self.write_build_outputs(programs, uplc_dump)?;
} }
if run_tests {
let tests = self.test_gen(&checked_modules)?;
self.run_tests(tests);
}
Ok(()) Ok(())
} }
@ -472,6 +479,21 @@ impl Project {
Ok(programs) Ok(programs)
} }
fn run_tests(&self, tests: Vec<Script>) {
for test in tests {
let result = test.program.eval();
match result {
(Ok(..), _, _) => {
println!("{}::{}", test.module, test.name);
}
(Err(e), _, _) => {
println!("{}::{} x", test.module, test.name);
println!("{}", e);
}
}
}
}
fn write_build_outputs(&self, programs: Vec<Script>, uplc_dump: bool) -> Result<(), Error> { fn write_build_outputs(&self, programs: Vec<Script>, uplc_dump: bool) -> Result<(), Error> {
let assets = self.root.join("assets"); let assets = self.root.join("assets");