Skip to content

Commit 36da95f

Browse files
authored
aml_tester:Make cli print more pretty (#221)
if args<=1 print help info, and add summary info
1 parent 20486f8 commit 36da95f

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

aml_tester/src/main.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use aml::{AmlContext, DebugVerbosity};
1313
use clap::{Arg, ArgAction, ArgGroup};
1414
use std::{
15-
collections::HashSet,
15+
cell::RefCell,
16+
collections::{HashMap, HashSet},
1617
ffi::OsStr,
1718
fs::{self, File},
1819
io::{Read, Write},
@@ -30,19 +31,23 @@ enum CompilationOutcome {
3031
}
3132

3233
fn main() -> std::io::Result<()> {
33-
log::set_logger(&Logger).unwrap();
34-
log::set_max_level(log::LevelFilter::Trace);
35-
36-
let matches = clap::Command::new("aml_tester")
34+
let mut cmd = clap::Command::new("aml_tester")
3735
.version("v0.1.0")
3836
.author("Isaac Woods")
3937
.about("Compiles and tests ASL files")
4038
.arg(Arg::new("no_compile").long("no-compile").action(ArgAction::SetTrue).help("Don't compile asl to aml"))
4139
.arg(Arg::new("reset").long("reset").action(ArgAction::SetTrue).help("Clear namespace after each file"))
4240
.arg(Arg::new("path").short('p').long("path").required(false).action(ArgAction::Set).value_name("DIR"))
4341
.arg(Arg::new("files").action(ArgAction::Append).value_name("FILE.{asl,aml}"))
44-
.group(ArgGroup::new("files_list").args(["path", "files"]).required(true))
45-
.get_matches();
42+
.group(ArgGroup::new("files_list").args(["path", "files"]).required(true));
43+
if std::env::args().count() <= 1 {
44+
cmd.print_help()?;
45+
return Ok(());
46+
}
47+
log::set_logger(&Logger).unwrap();
48+
log::set_max_level(log::LevelFilter::Trace);
49+
50+
let matches = cmd.get_matches();
4651

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

111116
// Make a list of the files we have processed, and skip them if we see them again
112117
let mut dedup_list: HashSet<PathBuf> = HashSet::new();
113-
118+
let summaries: RefCell<HashSet<(PathBuf, &str)>> = RefCell::new(HashSet::new());
114119
// Filter down to the final list of AML files
115120
let aml_files = compiled_files
116121
.iter()
117122
.filter_map(|outcome| match outcome {
118123
CompilationOutcome::IsAml(path) => Some(path.clone()),
119124
CompilationOutcome::Newer(path) => Some(path.clone()),
120125
CompilationOutcome::Succeeded(path) => Some(path.clone()),
121-
CompilationOutcome::Ignored | CompilationOutcome::Failed(_) | CompilationOutcome::NotCompiled(_) => {
126+
CompilationOutcome::Failed(path) => {
127+
summaries.borrow_mut().insert((path.clone(), "COMPILE FAILED"));
122128
None
123129
}
130+
CompilationOutcome::NotCompiled(path) => {
131+
summaries.borrow_mut().insert((path.clone(), "NotCompiled"));
132+
None
133+
}
134+
CompilationOutcome::Ignored => None,
124135
})
125136
.filter(|path| {
126137
if dedup_list.contains(path) {
@@ -138,7 +149,7 @@ fn main() -> std::io::Result<()> {
138149
print!("Testing AML file: {:?}... ", file_entry);
139150
std::io::stdout().flush().unwrap();
140151

141-
let mut file = File::open(file_entry).unwrap();
152+
let mut file = File::open(&file_entry).unwrap();
142153
let mut contents = Vec::new();
143154
file.read_to_end(&mut contents).unwrap();
144155

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

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

166-
println!("Test results: {} passed, {} failed", passed, failed);
179+
// Print summaries
180+
println!("Summary:");
181+
for (file, status) in summaries.borrow().iter() {
182+
println!("{:<50}: {}", file.to_str().unwrap(), status);
183+
}
184+
println!("\nTest results:\n\tpassed:{}\n\tfailed:{}", passed, failed);
167185
Ok(())
168186
}
169187

0 commit comments

Comments
 (0)