1212use aml:: { AmlContext , DebugVerbosity } ;
1313use clap:: { Arg , ArgAction , ArgGroup } ;
1414use 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
3233fn 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 ! ( "\n Test results:\n \t passed:{}\n \t failed:{}" , passed, failed) ;
167185 Ok ( ( ) )
168186}
169187
0 commit comments