about summary refs log tree commit diff
diff options
context:
space:
mode:
authordvermd <315743+dvermd@users.noreply.github.com>2025-08-10 08:23:11 +0200
committerdvermd <315743+dvermd@users.noreply.github.com>2025-08-10 08:30:33 +0200
commit307ebca295428fc14718ebae874e816f06532145 (patch)
treec04c8db5b8845e35779fc70d390d7d6e83ea30b7
parentf0ab82feb16b328abd8b1c7ba729d9a4223c6415 (diff)
run rustfmt on tests/run/*.rs
-rw-r--r--build_system/src/fmt.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/build_system/src/fmt.rs b/build_system/src/fmt.rs
index 7e6594f50f9..91535f217e3 100644
--- a/build_system/src/fmt.rs
+++ b/build_system/src/fmt.rs
@@ -1,7 +1,7 @@
 use std::ffi::OsStr;
 use std::path::Path;
 
-use crate::utils::run_command_with_output;
+use crate::utils::{run_command_with_output, walk_dir};
 
 fn show_usage() {
     println!(
@@ -32,5 +32,31 @@ pub fn run() -> Result<(), String> {
         if check { &[&"cargo", &"fmt", &"--check"] } else { &[&"cargo", &"fmt"] };
 
     run_command_with_output(cmd, Some(Path::new(".")))?;
-    run_command_with_output(cmd, Some(Path::new("build_system")))
+    run_command_with_output(cmd, Some(Path::new("build_system")))?;
+
+    run_rustfmt_recursively("tests/run", check)
+}
+
+fn run_rustfmt_recursively<P>(dir: P, check: bool) -> Result<(), String>
+where
+    P: AsRef<Path>,
+{
+    walk_dir(
+        dir,
+        &mut |dir| run_rustfmt_recursively(dir, check),
+        &mut |file_path| {
+            if file_path.extension().filter(|ext| ext == &OsStr::new("rs")).is_some() {
+                let rustfmt_cmd: &[&dyn AsRef<OsStr>] = if check {
+                    &[&"rustfmt", &"--check", &file_path]
+                } else {
+                    &[&"rustfmt", &file_path]
+                };
+
+                run_command_with_output(rustfmt_cmd, Some(Path::new(".")))
+            } else {
+                Ok(())
+            }
+        },
+        true,
+    )
 }