diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index d1d5b51fe8..ea4036b97b 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -180,11 +180,12 @@ impl> Compiler { } /// 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::( self.program, input_pairs, &self.imported_programs, + &self.main_file_path, &self.output_directory, ) } diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 13a22ed898..a95976a4e4 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -65,8 +65,9 @@ pub fn generate_test_constraints>( 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::::new(); let program_name = program.get_name(); @@ -80,6 +81,10 @@ pub fn generate_test_constraints>( 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::::new(); let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string()); @@ -129,14 +134,28 @@ pub fn generate_test_constraints>( 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)) } diff --git a/leo/commands/build.rs b/leo/commands/build.rs index abe813a7e9..ca26883ef4 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -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()); }); diff --git a/leo/commands/publish.rs b/leo/commands/publish.rs index a92537e458..4ac46a9e42 100644 --- a/leo/commands/publish.rs +++ b/leo/commands/publish.rs @@ -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); diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 481585322f..277bc1d98e 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -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(()) }