From 04261b4798a73118f5266801fca9bf3d7ca95bdf Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Sun, 29 Sep 2024 12:54:38 +0200 Subject: [wip] Draft tester program The goal is to have a simple CLI that will repeatedly run sequence of tests against a known (Rest-ish) API, until all tests are "green". --- rust/src/tester.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 rust/src/tester.rs (limited to 'rust/src') diff --git a/rust/src/tester.rs b/rust/src/tester.rs new file mode 100644 index 0000000..15ca468 --- /dev/null +++ b/rust/src/tester.rs @@ -0,0 +1,57 @@ +use std::{ + fs, + path::{Path, PathBuf}, +}; + +pub fn main() { + let args: Vec = std::env::args().collect(); + if args.len() > 1 { + let run = traverse(&args) + .and_then(|paths| run_test(&paths)) + .expect("Failed to traverse directory"); + println!("{:?}", run) + } +} + +fn traverse(args: &[String]) -> Result, String> { + let mut files: Vec = Vec::new(); + for arg in args.iter().skip(1) { + let entries = fs::read_dir(arg).map_err(|e| e.to_string())?; + for entry in entries { + let dir = entry.map_err(|e| e.to_string())?; + let f = dir.metadata().map_err(|e| e.to_string())?; + if f.is_dir() { + files.push(dir.path()); + } + } + } + Ok(files) +} + +#[derive(Debug)] +struct TestRun { + file: String, + test_result: bool, + duration: u64, +} + +fn run_test(files: &Vec) -> Result, String> { + let mut result = Vec::new(); + for file in files { + let mut inp = file.clone(); + let mut outp = file.clone(); + inp.push("input"); + outp.push("output"); + let (test_result, duration) = run_test_case(&inp, &outp); + result.push(TestRun { + file: inp.as_path().to_str().unwrap().to_string(), + test_result, + duration, + }); + } + Ok(result) +} + +fn run_test_case(inp: &std::path::PathBuf, outp: &std::path::PathBuf) -> (bool, u64) { + (true, 1) +} -- cgit v1.2.3