From 19eb33ef04103ca4a6eb4af3e1940c2a5779e1ad Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 1 Oct 2024 09:47:37 +0200 Subject: Output tester's result in JSON --- rust/src/tester.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'rust/src') diff --git a/rust/src/tester.rs b/rust/src/tester.rs index 019989b..eb66d4e 100644 --- a/rust/src/tester.rs +++ b/rust/src/tester.rs @@ -1,3 +1,4 @@ +use serde::{Deserialize, Serialize}; use std::{ fs::{self, read_to_string, File}, path::PathBuf, @@ -13,9 +14,20 @@ pub fn main() { let run = traverse(&args) .and_then(|paths| run_test(&proc, &paths)) .expect("Failed to traverse directory"); - println!("{:?}", run) + println!("{}", serde_json::to_string_pretty(&run).unwrap()); } else { - println!("Usage: tester +"); + println!( + r#"Usage: tester [options] + + +Options: + -p, --process The process to run. If the given process is not a + an absolute path, it will be resolved against the + PATH environment variable. + -j, --json Output the results in JSON format (default: false) + -h, --help Display this help message + -v, --version Display the version of the tester +"# + ); } } @@ -34,13 +46,13 @@ fn traverse(args: &[String]) -> Result, String> { Ok(files) } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum TestResult { TestSucceeded, TestFailed(String, String), } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct TestRun { file: String, test_result: TestResult, -- cgit v1.2.3