Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 73 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{fs::File, process};
use std::{
fs::{self},
process,
};

use walkman::{
config::TestConfig,
Expand All @@ -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,
Expand All @@ -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);
}
}
Expand Down
Loading