Skip to content

Commit

Permalink
aml_tester:Make cli print more pretty (#221)
Browse files Browse the repository at this point in the history
if args<=1 print help info, and add summary info
  • Loading branch information
jokemanfire authored Sep 7, 2024
1 parent 20486f8 commit 36da95f
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions aml_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use aml::{AmlContext, DebugVerbosity};
use clap::{Arg, ArgAction, ArgGroup};
use std::{
collections::HashSet,
cell::RefCell,
collections::{HashMap, HashSet},
ffi::OsStr,
fs::{self, File},
io::{Read, Write},
Expand All @@ -30,19 +31,23 @@ enum CompilationOutcome {
}

fn main() -> std::io::Result<()> {
log::set_logger(&Logger).unwrap();
log::set_max_level(log::LevelFilter::Trace);

let matches = clap::Command::new("aml_tester")
let mut cmd = clap::Command::new("aml_tester")
.version("v0.1.0")
.author("Isaac Woods")
.about("Compiles and tests ASL files")
.arg(Arg::new("no_compile").long("no-compile").action(ArgAction::SetTrue).help("Don't compile asl to aml"))
.arg(Arg::new("reset").long("reset").action(ArgAction::SetTrue).help("Clear namespace after each file"))
.arg(Arg::new("path").short('p').long("path").required(false).action(ArgAction::Set).value_name("DIR"))
.arg(Arg::new("files").action(ArgAction::Append).value_name("FILE.{asl,aml}"))
.group(ArgGroup::new("files_list").args(["path", "files"]).required(true))
.get_matches();
.group(ArgGroup::new("files_list").args(["path", "files"]).required(true));
if std::env::args().count() <= 1 {
cmd.print_help()?;
return Ok(());
}
log::set_logger(&Logger).unwrap();
log::set_max_level(log::LevelFilter::Trace);

let matches = cmd.get_matches();

// Get an initial list of files - may not work correctly on non-UTF8 OsString
let files: Vec<String> = if matches.contains_id("path") {
Expand Down Expand Up @@ -110,17 +115,23 @@ fn main() -> std::io::Result<()> {

// Make a list of the files we have processed, and skip them if we see them again
let mut dedup_list: HashSet<PathBuf> = HashSet::new();

let summaries: RefCell<HashSet<(PathBuf, &str)>> = RefCell::new(HashSet::new());
// Filter down to the final list of AML files
let aml_files = compiled_files
.iter()
.filter_map(|outcome| match outcome {
CompilationOutcome::IsAml(path) => Some(path.clone()),
CompilationOutcome::Newer(path) => Some(path.clone()),
CompilationOutcome::Succeeded(path) => Some(path.clone()),
CompilationOutcome::Ignored | CompilationOutcome::Failed(_) | CompilationOutcome::NotCompiled(_) => {
CompilationOutcome::Failed(path) => {
summaries.borrow_mut().insert((path.clone(), "COMPILE FAILED"));
None
}
CompilationOutcome::NotCompiled(path) => {
summaries.borrow_mut().insert((path.clone(), "NotCompiled"));
None
}
CompilationOutcome::Ignored => None,
})
.filter(|path| {
if dedup_list.contains(path) {
Expand All @@ -138,7 +149,7 @@ fn main() -> std::io::Result<()> {
print!("Testing AML file: {:?}... ", file_entry);
std::io::stdout().flush().unwrap();

let mut file = File::open(file_entry).unwrap();
let mut file = File::open(&file_entry).unwrap();
let mut contents = Vec::new();
file.read_to_end(&mut contents).unwrap();

Expand All @@ -152,18 +163,25 @@ fn main() -> std::io::Result<()> {
Ok(()) => {
println!("{}OK{}", termion::color::Fg(termion::color::Green), termion::style::Reset);
println!("Namespace: {:#?}", context.namespace);
summaries.borrow_mut().insert((file_entry, "PASS"));
(passed + 1, failed)
}

Err(err) => {
println!("{}Failed ({:?}){}", termion::color::Fg(termion::color::Red), err, termion::style::Reset);
println!("Namespace: {:#?}", context.namespace);
summaries.borrow_mut().insert((file_entry, "PARSE FAIL"));
(passed, failed + 1)
}
}
});

println!("Test results: {} passed, {} failed", passed, failed);
// Print summaries
println!("Summary:");
for (file, status) in summaries.borrow().iter() {
println!("{:<50}: {}", file.to_str().unwrap(), status);
}
println!("\nTest results:\n\tpassed:{}\n\tfailed:{}", passed, failed);
Ok(())
}

Expand Down

0 comments on commit 36da95f

Please sign in to comment.