Skip to content

Commit b328d82

Browse files
committed
Autoformat aml_tester, update CI to use new CLI interface
1 parent 0b3a35d commit b328d82

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: cargo test --all
3737

3838
- name: Run AML test suite
39-
run: cargo run --bin aml_tester -- -p tests
39+
run: cargo run --bin aml_tester -- -p tests --reset

aml_tester/src/main.rs

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*/
1111

1212
use aml::{AmlContext, DebugVerbosity};
13-
use clap::{Arg, ArgGroup, ArgAction};
13+
use clap::{Arg, ArgAction, ArgGroup};
1414
use std::{
15+
collections::HashSet,
1516
ffi::OsStr,
1617
fs::{self, File},
1718
io::{Read, Write},
1819
path::{Path, PathBuf},
1920
process::Command,
20-
collections::HashSet,
2121
};
2222

2323
enum CompilationOutcome {
@@ -48,17 +48,21 @@ fn main() -> std::io::Result<()> {
4848
let files: Vec<String> = if matches.contains_id("path") {
4949
let dir_path = Path::new(matches.get_one::<String>("path").unwrap());
5050
println!("Running tests in directory: {:?}", dir_path);
51-
fs::read_dir(dir_path)?.filter_map(| entry | if entry.is_ok() {
52-
Some(entry.unwrap().path().to_string_lossy().to_string())
53-
} else {
54-
None
55-
}).collect()
51+
fs::read_dir(dir_path)?
52+
.filter_map(|entry| {
53+
if entry.is_ok() {
54+
Some(entry.unwrap().path().to_string_lossy().to_string())
55+
} else {
56+
None
57+
}
58+
})
59+
.collect()
5660
} else {
57-
matches.get_many::<String>("files").unwrap_or_default().map(| name | name.to_string()).collect()
61+
matches.get_many::<String>("files").unwrap_or_default().map(|name| name.to_string()).collect()
5862
};
5963

6064
// Make sure all files exist, propagate error if it occurs
61-
files.iter().fold(Ok(()), | result: std::io::Result<()>, file | {
65+
files.iter().fold(Ok(()), |result: std::io::Result<()>, file| {
6266
let path = Path::new(file);
6367
if !path.is_file() {
6468
println!("Not a regular file: {}", file);
@@ -80,42 +84,52 @@ fn main() -> std::io::Result<()> {
8084
Err(_) => false,
8185
};
8286

83-
let compiled_files: Vec<CompilationOutcome> = files.iter().map(| name | resolve_and_compile(name, can_compile).unwrap()).collect();
87+
let compiled_files: Vec<CompilationOutcome> =
88+
files.iter().map(|name| resolve_and_compile(name, can_compile).unwrap()).collect();
8489

8590
// Check if compilation should have happened but did not
86-
if user_wants_compile && compiled_files.iter().any(| outcome | matches!(outcome, CompilationOutcome::NotCompiled(_))) {
87-
panic!("`iasl` is not installed, but we want to compile some ASL files! Pass --no-compile, or install `iasl`");
91+
if user_wants_compile
92+
&& compiled_files.iter().any(|outcome| matches!(outcome, CompilationOutcome::NotCompiled(_)))
93+
{
94+
panic!(
95+
"`iasl` is not installed, but we want to compile some ASL files! Pass --no-compile, or install `iasl`"
96+
);
8897
}
8998
// Report compilation results
9099
if user_wants_compile {
91-
let (passed, failed) = compiled_files.iter()
92-
.fold((0, 0), | (passed, failed), outcome | match outcome {
93-
CompilationOutcome::Succeeded(_) => (passed + 1, failed),
94-
CompilationOutcome::Failed(_) => (passed, failed + 1),
95-
_ => (passed, failed),
100+
let (passed, failed) = compiled_files.iter().fold((0, 0), |(passed, failed), outcome| match outcome {
101+
CompilationOutcome::Succeeded(_) => (passed + 1, failed),
102+
CompilationOutcome::Failed(_) => (passed, failed + 1),
103+
_ => (passed, failed),
96104
});
97105
if passed + failed > 0 {
98106
println!("Compiled {} ASL files: {} passed, {} failed.", passed + failed, passed, failed);
107+
println!();
99108
}
100109
}
101110

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

105114
// Filter down to the final list of AML files
106-
let aml_files = compiled_files.iter()
107-
.filter_map(| outcome | match outcome {
115+
let aml_files = compiled_files
116+
.iter()
117+
.filter_map(|outcome| match outcome {
108118
CompilationOutcome::IsAml(path) => Some(path.clone()),
109119
CompilationOutcome::Newer(path) => Some(path.clone()),
110120
CompilationOutcome::Succeeded(path) => Some(path.clone()),
111-
CompilationOutcome::Ignored | CompilationOutcome::Failed(_) | CompilationOutcome::NotCompiled(_) => None,
121+
CompilationOutcome::Ignored | CompilationOutcome::Failed(_) | CompilationOutcome::NotCompiled(_) => {
122+
None
123+
}
112124
})
113-
.filter(| path | if dedup_list.contains(path) {
114-
false
115-
} else {
116-
dedup_list.insert(path.clone());
117-
true
118-
});
125+
.filter(|path| {
126+
if dedup_list.contains(path) {
127+
false
128+
} else {
129+
dedup_list.insert(path.clone());
130+
true
131+
}
132+
});
119133

120134
let user_wants_reset = matches.get_flag("reset");
121135
let mut context = AmlContext::new(Box::new(Handler), DebugVerbosity::None);
@@ -129,7 +143,7 @@ fn main() -> std::io::Result<()> {
129143
file.read_to_end(&mut contents).unwrap();
130144

131145
const AML_TABLE_HEADER_LENGTH: usize = 36;
132-
146+
133147
if user_wants_reset {
134148
context = AmlContext::new(Box::new(Handler), DebugVerbosity::None);
135149
}
@@ -178,14 +192,14 @@ fn resolve_and_compile(name: &str, can_compile: bool) -> std::io::Result<Compila
178192
// If the aml is more recent than the asl, use the existing aml
179193
// Otherwise continue to compilation
180194
if asl_last_modified <= aml_last_modified {
181-
return Ok(CompilationOutcome::Newer(aml_path))
195+
return Ok(CompilationOutcome::Newer(aml_path));
182196
}
183197
}
184198

185199
if !can_compile {
186200
return Ok(CompilationOutcome::NotCompiled(path));
187201
}
188-
202+
189203
// Compile the ASL file using `iasl`
190204
println!("Compiling file: {}", name);
191205
let output = Command::new("iasl").arg(name).output()?;

0 commit comments

Comments
 (0)