From 4c4928ea9f1a33be04952266f270f6c6f3870873 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Mon, 27 Dec 2021 15:53:56 +0000 Subject: [PATCH] Refractor tests --- ...handball__tests__pass@lambda-calc.scm.snap | 21 ------------ .../handball__tests__pass@math.scm.snap | 17 ---------- .../handball__tests__run-pass@funcs.scm.snap | 10 ++++++ ...ball__tests__run-pass@lambda-calc.scm.snap | 21 ++++++++++++ .../handball__tests__run-pass@math.scm.snap | 17 ++++++++++ src/test/run-pass/funcs.scm | 12 +++++++ src/test/{pass => run-pass}/lambda-calc.scm | 0 src/test/{pass => run-pass}/math.scm | 0 src/test/{pass => run-pass}/real-i0.scm-todo | 0 src/tests.rs | 32 ++++++++++++++++--- 10 files changed, 88 insertions(+), 42 deletions(-) delete mode 100644 src/snapshots/handball__tests__pass@lambda-calc.scm.snap delete mode 100644 src/snapshots/handball__tests__pass@math.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@funcs.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@lambda-calc.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@math.scm.snap create mode 100644 src/test/run-pass/funcs.scm rename src/test/{pass => run-pass}/lambda-calc.scm (100%) rename src/test/{pass => run-pass}/math.scm (100%) rename src/test/{pass => run-pass}/real-i0.scm-todo (100%) diff --git a/src/snapshots/handball__tests__pass@lambda-calc.scm.snap b/src/snapshots/handball__tests__pass@lambda-calc.scm.snap deleted file mode 100644 index b58f786..0000000 --- a/src/snapshots/handball__tests__pass@lambda-calc.scm.snap +++ /dev/null @@ -1,21 +0,0 @@ ---- -source: src/tests.rs -assertion_line: 27 -expression: "String::from_utf8(cmd.get_output().stdout.clone()).unwrap()" - ---- -1.0 -0.0 --1.0 -0.0 -1.0 -1.0 -0.0 -0.0 -0.0 -1.0 -1.0 -1.0 -0.0 -1.0 - diff --git a/src/snapshots/handball__tests__pass@math.scm.snap b/src/snapshots/handball__tests__pass@math.scm.snap deleted file mode 100644 index 6fb0bf1..0000000 --- a/src/snapshots/handball__tests__pass@math.scm.snap +++ /dev/null @@ -1,17 +0,0 @@ ---- -source: src/tests.rs -assertion_line: 27 -expression: "String::from_utf8(cmd.get_output().stdout.clone()).unwrap()" - ---- -0.0 -1.0 -10.0 --1.0 --8.0 -7.0 -2.0 -1.0 -0.1 -1.0 - diff --git a/src/snapshots/handball__tests__run-pass@funcs.scm.snap b/src/snapshots/handball__tests__run-pass@funcs.scm.snap new file mode 100644 index 0000000..b002e9e --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@funcs.scm.snap @@ -0,0 +1,10 @@ +--- +source: src/tests.rs +assertion_line: 47 +expression: run-pass funcs.scm + +--- +5.0 +11.0 +14.0 + diff --git a/src/snapshots/handball__tests__run-pass@lambda-calc.scm.snap b/src/snapshots/handball__tests__run-pass@lambda-calc.scm.snap new file mode 100644 index 0000000..edb1701 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@lambda-calc.scm.snap @@ -0,0 +1,21 @@ +--- +source: src/tests.rs +assertion_line: 47 +expression: run-pass lambda-calc.scm + +--- +1.0 +0.0 +-1.0 +0.0 +1.0 +1.0 +0.0 +0.0 +0.0 +1.0 +1.0 +1.0 +0.0 +1.0 + diff --git a/src/snapshots/handball__tests__run-pass@math.scm.snap b/src/snapshots/handball__tests__run-pass@math.scm.snap new file mode 100644 index 0000000..e26a004 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@math.scm.snap @@ -0,0 +1,17 @@ +--- +source: src/tests.rs +assertion_line: 47 +expression: run-pass math.scm + +--- +0.0 +1.0 +10.0 +-1.0 +-8.0 +7.0 +2.0 +1.0 +0.1 +1.0 + diff --git a/src/test/run-pass/funcs.scm b/src/test/run-pass/funcs.scm new file mode 100644 index 0000000..58c1e2d --- /dev/null +++ b/src/test/run-pass/funcs.scm @@ -0,0 +1,12 @@ +#lang scheme + +(define (displayln x) (display x) (newline)) + +(define add1 +) +(displayln (add1 2 3)) + +(define add2 (lambda (a b) (+ a b))) +(displayln (add2 5 6)) + +(define (add3 a b) (+ a b)) +(displayln (add3 5 9)) \ No newline at end of file diff --git a/src/test/pass/lambda-calc.scm b/src/test/run-pass/lambda-calc.scm similarity index 100% rename from src/test/pass/lambda-calc.scm rename to src/test/run-pass/lambda-calc.scm diff --git a/src/test/pass/math.scm b/src/test/run-pass/math.scm similarity index 100% rename from src/test/pass/math.scm rename to src/test/run-pass/math.scm diff --git a/src/test/pass/real-i0.scm-todo b/src/test/run-pass/real-i0.scm-todo similarity index 100% rename from src/test/pass/real-i0.scm-todo rename to src/test/run-pass/real-i0.scm-todo diff --git a/src/tests.rs b/src/tests.rs index 2b484db..f261f4c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,3 +1,5 @@ +use std::path::{Path, PathBuf}; + // use fs_err as fs; /* @@ -13,15 +15,37 @@ upstream for this */ #[test] -fn pass() { - insta::glob!("test/pass/**.scm", |p| { +fn run_pass() { + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + + insta::glob!("test/run-pass/**.scm", |p| { + let p = PathBuf::from( + p.canonicalize() + .unwrap() + .to_str() + .unwrap() + .replace("\\\\?\\", ""), // Work around IDK on windows + ); + let cmd = assert_cmd::Command::cargo_bin("handball") .unwrap() - .arg(p) + .arg(&p) .assert() .success(); + dbg!(&p, p.components().collect::>()); + + dbg!(&p, manifest_dir); + + let p = p.strip_prefix(manifest_dir).unwrap(); + let p = p.strip_prefix("src/test/run-pass").unwrap(); + let p = p.to_str().unwrap(); + assert_eq!(cmd.get_output().stderr, Vec::::new()); - insta::assert_snapshot!(String::from_utf8(cmd.get_output().stdout.clone()).unwrap()); + insta::assert_snapshot!( + "run-pass", + String::from_utf8(cmd.get_output().stdout.clone()).unwrap(), + &format!("run-pass {}", p) + ); }) }