Added target awareness and fixed property based test json output

This commit is contained in:
Riley-Kilgore 2024-10-22 09:48:26 -07:00 committed by KtorZ
parent d1a1d0ec01
commit 1a75568027
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 42 additions and 24 deletions

View File

@ -591,10 +591,22 @@ fn fmt_overall_summary_json(tests: &[TestResult<UntypedExpr, UntypedExpr>]) -> 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<UntypedExpr, UntypedExpr>]) -> s
json!({
"name": module,
"tests": results.iter().map(|r| fmt_test_json(r)).collect::<Vec<_>>(),
"summary": fmt_test_summary_json(&results),
"summary": fmt_test_summary_json(&results)
})
}).collect::<Vec<_>>(),
})

View File

@ -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))