12
12
use aml:: { AmlContext , DebugVerbosity } ;
13
13
use clap:: { Arg , ArgAction , ArgGroup } ;
14
14
use std:: {
15
- collections:: HashSet ,
15
+ cell:: RefCell ,
16
+ collections:: { HashMap , HashSet } ,
16
17
ffi:: OsStr ,
17
18
fs:: { self , File } ,
18
19
io:: { Read , Write } ,
@@ -30,19 +31,23 @@ enum CompilationOutcome {
30
31
}
31
32
32
33
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" )
37
35
. version ( "v0.1.0" )
38
36
. author ( "Isaac Woods" )
39
37
. about ( "Compiles and tests ASL files" )
40
38
. arg ( Arg :: new ( "no_compile" ) . long ( "no-compile" ) . action ( ArgAction :: SetTrue ) . help ( "Don't compile asl to aml" ) )
41
39
. arg ( Arg :: new ( "reset" ) . long ( "reset" ) . action ( ArgAction :: SetTrue ) . help ( "Clear namespace after each file" ) )
42
40
. arg ( Arg :: new ( "path" ) . short ( 'p' ) . long ( "path" ) . required ( false ) . action ( ArgAction :: Set ) . value_name ( "DIR" ) )
43
41
. 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 ( ) ;
46
51
47
52
// Get an initial list of files - may not work correctly on non-UTF8 OsString
48
53
let files: Vec < String > = if matches. contains_id ( "path" ) {
@@ -110,17 +115,23 @@ fn main() -> std::io::Result<()> {
110
115
111
116
// Make a list of the files we have processed, and skip them if we see them again
112
117
let mut dedup_list: HashSet < PathBuf > = HashSet :: new ( ) ;
113
-
118
+ let summaries : RefCell < HashSet < ( PathBuf , & str ) > > = RefCell :: new ( HashSet :: new ( ) ) ;
114
119
// Filter down to the final list of AML files
115
120
let aml_files = compiled_files
116
121
. iter ( )
117
122
. filter_map ( |outcome| match outcome {
118
123
CompilationOutcome :: IsAml ( path) => Some ( path. clone ( ) ) ,
119
124
CompilationOutcome :: Newer ( path) => Some ( path. clone ( ) ) ,
120
125
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" ) ) ;
122
128
None
123
129
}
130
+ CompilationOutcome :: NotCompiled ( path) => {
131
+ summaries. borrow_mut ( ) . insert ( ( path. clone ( ) , "NotCompiled" ) ) ;
132
+ None
133
+ }
134
+ CompilationOutcome :: Ignored => None ,
124
135
} )
125
136
. filter ( |path| {
126
137
if dedup_list. contains ( path) {
@@ -138,7 +149,7 @@ fn main() -> std::io::Result<()> {
138
149
print ! ( "Testing AML file: {:?}... " , file_entry) ;
139
150
std:: io:: stdout ( ) . flush ( ) . unwrap ( ) ;
140
151
141
- let mut file = File :: open ( file_entry) . unwrap ( ) ;
152
+ let mut file = File :: open ( & file_entry) . unwrap ( ) ;
142
153
let mut contents = Vec :: new ( ) ;
143
154
file. read_to_end ( & mut contents) . unwrap ( ) ;
144
155
@@ -152,18 +163,25 @@ fn main() -> std::io::Result<()> {
152
163
Ok ( ( ) ) => {
153
164
println ! ( "{}OK{}" , termion:: color:: Fg ( termion:: color:: Green ) , termion:: style:: Reset ) ;
154
165
println ! ( "Namespace: {:#?}" , context. namespace) ;
166
+ summaries. borrow_mut ( ) . insert ( ( file_entry, "PASS" ) ) ;
155
167
( passed + 1 , failed)
156
168
}
157
169
158
170
Err ( err) => {
159
171
println ! ( "{}Failed ({:?}){}" , termion:: color:: Fg ( termion:: color:: Red ) , err, termion:: style:: Reset ) ;
160
172
println ! ( "Namespace: {:#?}" , context. namespace) ;
173
+ summaries. borrow_mut ( ) . insert ( ( file_entry, "PARSE FAIL" ) ) ;
161
174
( passed, failed + 1 )
162
175
}
163
176
}
164
177
} ) ;
165
178
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) ;
167
185
Ok ( ( ) )
168
186
}
169
187
0 commit comments