summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/Cargo.toml4
-rw-r--r--rust/src/tester.rs57
2 files changed, 61 insertions, 0 deletions
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 442a9ac..8cece05 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -16,3 +16,7 @@ path = "src/lib.rs"
[[bin]]
name = "lambda"
path = "src/main.rs"
+
+[[bin]]
+name = "tester"
+path = "src/tester.rs"
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<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)
+}