From 1a755680279acf2743b093210887a5dd66be983d Mon Sep 17 00:00:00 2001 From: Riley-Kilgore Date: Tue, 22 Oct 2024 09:48:26 -0700 Subject: [PATCH] Added target awareness and fixed property based test json output --- crates/aiken-project/src/telemetry.rs | 14 +++++++- crates/aiken/src/cmd/check.rs | 52 +++++++++++++++------------ 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/crates/aiken-project/src/telemetry.rs b/crates/aiken-project/src/telemetry.rs index ecbde3d9..aa259e92 100644 --- a/crates/aiken-project/src/telemetry.rs +++ b/crates/aiken-project/src/telemetry.rs @@ -591,10 +591,22 @@ fn fmt_overall_summary_json(tests: &[TestResult]) -> s let (max_mem, max_cpu, max_iter) = find_max_execution_units(tests); + // Separate counts for unit tests and property-based tests + let unit_tests = tests + .iter() + .filter(|t| matches!(t, TestResult::UnitTestResult { .. })) + .count(); + let property_tests = tests + .iter() + .filter(|t| matches!(t, TestResult::PropertyTestResult { .. })) + .count(); + json!({ "total_tests": total, "passed_tests": passed, "failed_tests": failed, + "unit_tests": unit_tests, + "property_tests": property_tests, "module_count": module_count, "max_execution_units": { "memory": max_mem, @@ -605,7 +617,7 @@ fn fmt_overall_summary_json(tests: &[TestResult]) -> s json!({ "name": module, "tests": results.iter().map(|r| fmt_test_json(r)).collect::>(), - "summary": fmt_test_summary_json(&results), + "summary": fmt_test_summary_json(&results) }) }).collect::>(), }) diff --git a/crates/aiken/src/cmd/check.rs b/crates/aiken/src/cmd/check.rs index 32bdc05c..feee6591 100644 --- a/crates/aiken/src/cmd/check.rs +++ b/crates/aiken/src/cmd/check.rs @@ -5,7 +5,11 @@ use aiken_lang::{ }; use aiken_project::watch::{self, watch_project, with_project}; use rand::prelude::*; -use std::{path::PathBuf, process}; +use std::{ + io::{self, IsTerminal}, + path::PathBuf, + process, +}; #[derive(clap::Args)] /// Type-check an Aiken project @@ -84,10 +88,6 @@ pub struct Args { /// [optional] #[clap(short, long, value_parser=trace_level_parser(), default_value_t=TraceLevel::Verbose, verbatim_doc_comment)] trace_level: TraceLevel, - - /// Output JSON (useful for scripting & automation) - #[clap(long)] - json: bool, } pub fn exec( @@ -104,13 +104,14 @@ pub fn exec( seed, max_success, env, - json, }: Args, ) -> miette::Result<()> { let mut rng = rand::thread_rng(); let seed = seed.unwrap_or_else(|| rng.gen()); + let json_output = !io::stdout().is_terminal(); + let result = if watch { watch_project(directory.as_deref(), watch::default_filter, 500, |p| { p.check( @@ -125,26 +126,31 @@ pub fn exec( None => Tracing::All(trace_level), }, env.clone(), - json, + json_output, ) }) } else { - with_project(directory.as_deref(), deny, json, |p| { - p.check( - skip_tests, - match_tests.clone(), - debug, - exact_match, - seed, - max_success, - match trace_filter { - Some(trace_filter) => trace_filter(trace_level), - None => Tracing::All(trace_level), - }, - env.clone(), - json, - ) - }) + with_project( + directory.as_deref(), + deny, + !io::stdout().is_terminal(), + |p| { + p.check( + skip_tests, + match_tests.clone(), + debug, + exact_match, + seed, + max_success, + match trace_filter { + Some(trace_filter) => trace_filter(trace_level), + None => Tracing::All(trace_level), + }, + env.clone(), + json_output, + ) + }, + ) }; result.map_err(|_| process::exit(1))