summaryrefslogtreecommitdiff
path: root/rust/src/tester.rs
blob: 15ca468d4b2f1b52e6bf5ebc57276a4bb76d3ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::{
    fs,
    path::{Path, PathBuf},
};

pub fn main() {
    let args: Vec<String> = 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<Vec<PathBuf>, String> {
    let mut files: Vec<PathBuf> = 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<PathBuf>) -> Result<Vec<TestRun>, 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)
}