Skip to content

Commit 307ebca

Browse files
committed
run rustfmt on tests/run/*.rs
1 parent f0ab82f commit 307ebca

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

build_system/src/fmt.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::OsStr;
22
use std::path::Path;
33

4-
use crate::utils::run_command_with_output;
4+
use crate::utils::{run_command_with_output, walk_dir};
55

66
fn show_usage() {
77
println!(
@@ -32,5 +32,31 @@ pub fn run() -> Result<(), String> {
3232
if check { &[&"cargo", &"fmt", &"--check"] } else { &[&"cargo", &"fmt"] };
3333

3434
run_command_with_output(cmd, Some(Path::new(".")))?;
35-
run_command_with_output(cmd, Some(Path::new("build_system")))
35+
run_command_with_output(cmd, Some(Path::new("build_system")))?;
36+
37+
run_rustfmt_recursively("tests/run", check)
38+
}
39+
40+
fn run_rustfmt_recursively<P>(dir: P, check: bool) -> Result<(), String>
41+
where
42+
P: AsRef<Path>,
43+
{
44+
walk_dir(
45+
dir,
46+
&mut |dir| run_rustfmt_recursively(dir, check),
47+
&mut |file_path| {
48+
if file_path.extension().filter(|ext| ext == &OsStr::new("rs")).is_some() {
49+
let rustfmt_cmd: &[&dyn AsRef<OsStr>] = if check {
50+
&[&"rustfmt", &"--check", &file_path]
51+
} else {
52+
&[&"rustfmt", &file_path]
53+
};
54+
55+
run_command_with_output(rustfmt_cmd, Some(Path::new(".")))
56+
} else {
57+
Ok(())
58+
}
59+
},
60+
true,
61+
)
3662
}

0 commit comments

Comments
 (0)