Basic test harness

trunk
Alona EM 2021-12-27 03:35:57 +00:00
parent ebf46fc9e6
commit c1eb1ed61e
13 changed files with 349 additions and 6 deletions

257
Cargo.lock generated
View File

@ -29,6 +29,20 @@ dependencies = [
"term",
]
[[package]]
name = "assert_cmd"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e996dc7940838b7ef1096b882e29ec30a3149a3a443cdc8dba19ed382eca1fe2"
dependencies = [
"bstr",
"doc-comment",
"predicates",
"predicates-core",
"predicates-tree",
"wait-timeout",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -73,6 +87,17 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
]
[[package]]
name = "cc"
version = "1.0.72"
@ -105,6 +130,19 @@ dependencies = [
"winapi",
]
[[package]]
name = "console"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi",
]
[[package]]
name = "const-random"
version = "0.1.13"
@ -158,6 +196,12 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
[[package]]
name = "difflib"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
[[package]]
name = "dirs-next"
version = "2.0.0"
@ -179,6 +223,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "doc-comment"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "either"
version = "1.6.1"
@ -194,6 +244,12 @@ dependencies = [
"log",
]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "endian-type"
version = "0.1.2"
@ -244,12 +300,27 @@ dependencies = [
"wasi",
]
[[package]]
name = "globset"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd"
dependencies = [
"aho-corasick",
"bstr",
"fnv",
"log",
"regex",
]
[[package]]
name = "handball"
version = "0.1.0"
dependencies = [
"assert_cmd",
"chumsky",
"debug2",
"insta",
"lalrpop",
"lalrpop-util",
"logos",
@ -282,6 +353,23 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "insta"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86c4e56d571b4cc829f0ce71506bd865a90369eeab5f3d3657ba96230beb8012"
dependencies = [
"console",
"globset",
"lazy_static",
"serde",
"serde_json",
"serde_yaml",
"similar",
"uuid",
"walkdir",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -300,6 +388,12 @@ dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "lalrpop"
version = "0.19.6"
@ -344,6 +438,12 @@ version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "lock_api"
version = "0.4.5"
@ -485,6 +585,33 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "predicates"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95e5a7689e456ab905c22c2b48225bb921aba7c8dfa58440d68ba13f6222a715"
dependencies = [
"difflib",
"itertools",
"predicates-core",
]
[[package]]
name = "predicates-core"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
[[package]]
name = "predicates-tree"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "338c7be2905b732ae3984a2f40032b5e94fd8f52505b186c7d4d68d193445df7"
dependencies = [
"predicates-core",
"termtree",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
@ -549,6 +676,12 @@ dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "regex-syntax"
version = "0.6.25"
@ -595,12 +728,76 @@ dependencies = [
"syn",
]
[[package]]
name = "ryu"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
dependencies = [
"indexmap",
"ryu",
"serde",
"yaml-rust",
]
[[package]]
name = "similar"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3"
[[package]]
name = "siphasher"
version = "0.3.7"
@ -666,6 +863,22 @@ dependencies = [
"winapi",
]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "termtree"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13a4ec180a2de59b57434704ccfad967f789b12737738798fa08798cd5824c16"
[[package]]
name = "tiny-keccak"
version = "2.0.2"
@ -705,6 +918,32 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
name = "wait-timeout"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
dependencies = [
"libc",
]
[[package]]
name = "walkdir"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
"winapi",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
@ -727,6 +966,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
@ -775,3 +1023,12 @@ name = "windows_x86_64_msvc"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f2b8c7cbd3bfdddd9ab98769f9746a7fad1bca236554cd032b78d768bc0e89f"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

View File

@ -7,11 +7,18 @@ edition = "2021"
[dependencies]
chumsky = "0.6.0"
debug2 = { git = "https://github.com/adotinthevoid/debug2", rev="8b14afb90fc1d9ce470792ea393a9ab821a9e07f" }
# fs-err = "2.6.0"
lalrpop-util = { version = "0.19.6", features = ["lexer"] }
logos = "0.12.0"
debug2 = { git = "https://github.com/adotinthevoid/debug2", rev="8b14afb90fc1d9ce470792ea393a9ab821a9e07f" }
rustyline = "9.1.1"
rustyline-derive = "0.6.0"
[build-dependencies]
lalrpop = "0.19.6"
[features]
[dev-dependencies]
assert_cmd = "2.0.2"
insta = { version = "1.9.0", features = ["glob"] }

View File

@ -2,5 +2,5 @@ fn main() {
lalrpop::Configuration::new()
.generate_in_source_tree()
.process()
.unwrap();
.expect("handball lalrpop failed");
}

View File

@ -3,6 +3,12 @@ use std::rc::Rc;
grammar<'s>();
match {
r"\s*" => { }, // The default whitespace skipping is disabled an `ignore pattern` is specified
r";[^\n\r]*[\n\r]*" => { }, // Skip `;` comments
_
}
pub(crate) Trees = Tree+;
pub(crate) Tree: Tree = {

View File

@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.19.6"
// sha3: b5707c83e9c9ace17f4933f72414e7dc8f862030bd939bf761b94fa5414ee
// sha3: 44b62ddba83dfa68ba81984aa4db1583d1e3d6bdab9f86bff4d7442243f0d965
use crate::{Tree, Literal, Lambda};
use std::rc::Rc;
#[allow(unused_extern_crates)]
@ -2479,7 +2479,8 @@ mod __intern_token {
("^(define)", false),
("^(if)", false),
("^(lambda \\()", false),
(r"^(\s*)", true),
("^(;[\u{0}-\t\u{b}-\u{c}\u{e}-\u{10ffff}]*[\n\r]*)", true),
("^([\t-\r \u{85}\u{a0}\u{1680}\u{2000}-\u{200a}\u{2028}-\u{2029}\u{202f}\u{205f}\u{3000}]*)", true),
];
__lalrpop_util::lexer::MatcherBuilder::new(__strs.iter().copied()).unwrap()
}

View File

@ -4,6 +4,10 @@
mod grammar;
#[cfg(test)]
mod tests;
// use debug2::dbg;
use rustyline::validate::{
MatchingBracketValidator, ValidationContext, ValidationResult, Validator,
@ -377,3 +381,5 @@ impl Validator for InputValidator {
self.brackets.validate(ctx)
}
}

View File

@ -0,0 +1,21 @@
---
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

View File

@ -0,0 +1,17 @@
---
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

View File

@ -3,12 +3,11 @@
(displayln (+))
(displayln (+ 1))
(displayln (+ 1 2 3 4))
(displayln (+))
(displayln (- 1))
(displayln (- 1 2 3 4))
(displayln (* 1))
(displayln (* 7))
(displayln (* 1 2))
(displayln (*))

View File

@ -1,3 +1,5 @@
;; TODO: Enable when ready
(display (real? 2.5+0.0i))
(newline)
(display (real? 2.5+0i))

27
src/tests.rs Normal file
View File

@ -0,0 +1,27 @@
// use fs_err as fs;
/*
# Why are the tests in src
the way insta glob works is it finds the dir the file is in, and then
looks at all children, and then checks if they have a match. This means we
cant use .. in the glob, as parents arnt generated.
A potential solution would be to update insta to use CARGO_MAINIFEST_DIR
as the base, and add file!() to the glob, but I'd need to update insta
upstream for this
*/
#[test]
fn pass() {
insta::glob!("test/pass/**.scm", |p| {
let cmd = assert_cmd::Command::cargo_bin("handball")
.unwrap()
.arg(p)
.assert()
.success();
assert_eq!(cmd.get_output().stderr, Vec::<u8>::new());
insta::assert_snapshot!(String::from_utf8(cmd.get_output().stdout.clone()).unwrap());
})
}