fix test output formatting

This commit is contained in:
collin 2020-08-21 18:08:14 -07:00
parent 2e3333cd25
commit 551595026b
5 changed files with 44 additions and 9 deletions

View File

@ -180,11 +180,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
}
/// Synthesizes the circuit for test functions with program input.
pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(), CompilerError> {
pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), CompilerError> {
generate_test_constraints::<F, G>(
self.program,
input_pairs,
&self.imported_programs,
&self.main_file_path,
&self.output_directory,
)
}

View File

@ -65,8 +65,9 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
program: Program,
input: InputPairs,
imported_programs: &ImportParser,
main_file_path: &PathBuf,
output_directory: &PathBuf,
) -> Result<(), CompilerError> {
) -> Result<(u32, u32), CompilerError> {
let mut resolved_program = ConstrainedProgram::<F, G>::new();
let program_name = program.get_name();
@ -80,6 +81,10 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
tracing::info!("Running {} tests", tests.len());
// Count passed and failed tests
let mut passed = 0;
let mut failed = 0;
for (test_name, test) in tests.into_iter() {
let cs = &mut TestConstraintSystem::<F>::new();
let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string());
@ -129,14 +134,28 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
let output_file = OutputFile::new(&output_file_name);
output_file.write(output_directory, output.bytes()).unwrap();
// increment passed tests
passed += 1;
}
(true, false) => {
tracing::error!("{} constraint system not satisfied\n", full_test_name);
// increment failed tests
failed += 1;
}
(true, false) => tracing::error!("{} constraint system not satisfied", full_test_name),
(false, _) => {
let error = result.unwrap_err();
tracing::error!("{} failed due to error\n{}", full_test_name, error);
// Set file location of error
let mut error = result.unwrap_err();
error.set_path(main_file_path.clone());
tracing::error!("{} failed due to error\n\n{}\n", full_test_name, error);
// increment failed tests
failed += 1;
}
}
}
Ok(())
Ok((passed, failed))
}

View File

@ -182,7 +182,7 @@ impl CLI for BuildCommand {
drop(enter);
// Begin "Finished" context for console logging todo: @collin figure a way to get this output with tracing without dropping span
tracing::span!(tracing::Level::INFO, " Finished").in_scope(|| {
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
tracing::info!("compiled in {} milliseconds", start.elapsed().as_millis());
});

View File

@ -118,7 +118,7 @@ impl CLI for PublishCommand {
// If not logged in, then try logging in using JWT.
Err(_error) => {
tracing::warn!("You should be tracingged in before attempting to publish a package");
tracing::warn!("You should be logged in before attempting to publish a package");
tracing::info!("Trying to log in using JWT...");
let options = (None, None, None);

View File

@ -103,7 +103,22 @@ impl CLI for TestCommand {
// Run tests
let temporary_program = program.clone();
let output = temporary_program.compile_test_constraints(pairs)?;
let (passed, failed) = temporary_program.compile_test_constraints(pairs)?;
// Set the result of the test command to "ok" if all tests pass
let result = if failed == 0 {
"ok".to_owned()
} else {
"failed".to_owned()
};
// Drop "Test" context for console logging
drop(enter);
// Begin "Finished" context for console logging
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
tracing::info!("result: {}. {} passed; {} failed;\n", result, passed, failed);
});
Ok(())
}