From 55e6f19a27a37ed992db1255c1612d4cca1ea839 Mon Sep 17 00:00:00 2001 From: pepedinho <2spii94@gmail.com> Date: Mon, 11 May 2026 21:48:54 +0200 Subject: [PATCH] core: directory execution --- src/main.rs | 97 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21f9051..7b6f579 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ -use std::{fs::File, process}; +use std::{ + fs::{self}, + process, +}; use walkman::{ config::TestConfig, @@ -12,7 +15,7 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Cli { - test_file: String, + path: String, #[arg(long, default_value_t = false)] nui: bool, @@ -21,34 +24,80 @@ struct Cli { fn main() { let cli = Cli::parse(); - let file = match File::open(cli.test_file) { - Ok(f) => f, - Err(e) => { - eprintln!("Failed to open test file: {}", e); - process::exit(1); + let metadata = fs::metadata(&cli.path).unwrap_or_else(|e| { + eprintln!("Failed to read path {}: {}", cli.path, e); + process::exit(1); + }); + + let mut test_files = vec![]; + + if metadata.is_dir() { + for entry in fs::read_dir(&cli.path).expect("Failed to read directory") { + let entry = entry.expect("Failed to read entry"); + let path = entry.path(); + + if path.is_file() + && let Some(ext) = path.extension() + && (ext == "yml" || ext == "yaml") + { + test_files.push(path.to_string_lossy().to_string()); + } } - }; + test_files.sort(); - let config: TestConfig = match serde_yaml::from_reader(file) { - Ok(c) => c, - Err(e) => { - eprintln!("Invalid Yaml format : {}", e); - process::exit(1); + if test_files.is_empty() { + println!("No YAML tests files found in directory: {}", cli.path); + process::exit(0); } - }; + } else { + test_files.push(cli.path.clone()); + } - // let reporter = ConsoleReporter; - let mut runner = QemuRunner; + let mut all_passed = true; + let mut summary = Vec::new(); - let result = if cli.nui { - let reporter = ConsoleReporter; - runner.run(&config, &reporter) - } else { - let reporter = TuiReporter::new(&config); - runner.run(&config, &reporter) - }; + for test_file in &test_files { + let file = fs::File::open(test_file).unwrap_or_else(|e| { + eprintln!("Failed to open test file {}: {}", test_file, e); + process::exit(1); + }); + + let config: TestConfig = serde_yaml::from_reader(file).unwrap_or_else(|e| { + eprintln!("Invalid Yaml format in {}: {}", test_file, e); + process::exit(1); + }); + + let mut runner = QemuRunner; + + let result = if cli.nui { + let reporter = ConsoleReporter; + runner.run(&config, &reporter) + } else { + let reporter = TuiReporter::new(&config); + runner.run(&config, &reporter) + }; + + let success = result.is_ok(); + summary.push((config.name.clone(), success)); + + if !success { + all_passed = false; + } + } + + println!("\n=================================================="); + println!("πŸ“Ό WALKMAN TEST SUITE SUMMARY"); + println!("=================================================="); + for (name, success) in summary { + if success { + println!("\x1b[32m ▢● {}\x1b[0m", name); + } else { + println!("\x1b[31m ● {}\x1b[0m", name); + } + } + println!("==================================================\n"); - if result.is_err() { + if !all_passed { process::exit(1); } }