clay-borg/tools/cb-sim/src/main.rs

77 lines
2.3 KiB
Rust
Raw Normal View History

//! cb-sim — scenario runner binary (GameKernel K17; precursor of `cb sim`).
//! Parses scenario files, dispatches each to its game by the `<game>/`
//! prefix of its `scenario` field, and executes it. Exit codes: 0 all
//! passed, 1 failures, 2 unknown game, 64 usage error.
use cb_game_runtime::{scenario, RunOutcome, ScenarioFile};
use games_ground::GroundState;
fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
if args.is_empty() {
eprintln!("usage: cb-sim <scenario.yaml>...");
std::process::exit(64);
}
let mut unknown_game = false;
let mut failed = false;
let mut passed = 0usize;
let mut covered: Vec<String> = Vec::new();
for path in &args {
let text = match std::fs::read_to_string(path) {
Ok(t) => t,
Err(e) => {
eprintln!("{path}: read error: {e}");
failed = true;
continue;
}
};
let sc = match ScenarioFile::from_yaml(&text) {
Err(e) => {
eprintln!("{path}: parse error: {e}");
failed = true;
continue;
}
Ok(sc) => sc,
};
let outcome = match sc.scenario.split('/').next() {
Some("ground") => scenario::run::<GroundState>(&sc),
_ => {
println!("SKIP {} — no game registered for this prefix", sc.scenario);
unknown_game = true;
continue;
}
};
match outcome {
RunOutcome::Passed { covers } => {
println!(
"PASS {} covers={}{}",
sc.scenario,
covers.join(","),
if sc.provisional { " provisional" } else { "" }
);
covered.extend(covers);
passed += 1;
}
RunOutcome::Failed { reason } => {
println!("FAIL {}{reason}", sc.scenario);
failed = true;
}
}
}
covered.sort();
covered.dedup();
println!("{passed} passed, {} rules covered", covered.len());
if failed {
std::process::exit(1);
}
if unknown_game {
std::process::exit(2);
}
}