From 28ce8685050159024e0209660f4f3e3becf6616d Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Sat, 6 Feb 2021 23:57:04 -0500 Subject: [PATCH] [test] Add a filecheck program --- Cargo.lock | 87 +++++++++++++++++++++++++++++++++++++-- Cargo.toml | 1 + ivy-examples/fibonacci.vy | 34 ++++++++++++++- src/bin/filecheck.rs | 47 +++++++++++++++++++++ 4 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 src/bin/filecheck.rs diff --git a/Cargo.lock b/Cargo.lock index 4a9c04c..426b279 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -68,6 +77,16 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c70ece3a2affa9eda5d916d778fe80fe2b7357aeb2d7b38f35286cfa983571d0" +[[package]] +name = "filecheck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe00b427b7c4835f8b82170eb7b9a63634376b63d73b9a9093367e82570bbaa" +dependencies = [ + "regex", + "thiserror", +] + [[package]] name = "getrandom" version = "0.1.14" @@ -102,6 +121,7 @@ name = "ivy" version = "0.2.0" dependencies = [ "ess", + "filecheck", "pretty", "structopt", "tempfile", @@ -113,6 +133,18 @@ version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +[[package]] +name = "memchr" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" + +[[package]] +name = "once_cell" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" + [[package]] name = "ppv-lite86" version = "0.2.6" @@ -142,9 +174,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.9" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] @@ -205,6 +237,24 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "regex" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" + [[package]] name = "remove_dir_all" version = "0.5.2" @@ -245,9 +295,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.16" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" +checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2", "quote", @@ -277,6 +327,35 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thiserror" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + [[package]] name = "typed-arena" version = "2.0.1" diff --git a/Cargo.toml b/Cargo.toml index 49aa5b5..2f1cd84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ ess = "0.4.2" pretty = "0.9" structopt = "=0.3.5" tempfile = "3.1" +filecheck = "0.5" diff --git a/ivy-examples/fibonacci.vy b/ivy-examples/fibonacci.vy index 2a9fe0e..8140533 100644 --- a/ivy-examples/fibonacci.vy +++ b/ivy-examples/fibonacci.vy @@ -1,3 +1,35 @@ +; nextln: 0 +; nextln: 1 +; nextln: 1 +; nextln: 2 +; nextln: 3 +; nextln: 5 +; nextln: 8 +; nextln: 13 +; nextln: 21 +; nextln: 34 +; nextln: 55 +; nextln: 89 +; nextln: 144 +; nextln: 233 +; nextln: 377 +; nextln: 610 +; nextln: 987 +; nextln: 1597 +; nextln: 2584 +; nextln: 4181 +; nextln: 6765 +; nextln: 10946 +; nextln: 17711 +; nextln: 28657 +; nextln: 46368 +; nextln: 75025 +; nextln: 121393 +; nextln: 196418 +; nextln: 317811 +; nextln: 514229 +; nextln: 0 + (let ([nil (lam (c n) (n))] [cons (lam (x y) (lam (c n) (c x y)))] [head true] @@ -7,6 +39,6 @@ [if (lam (c t f) ((c t f)))]) ([fix (lam (recur a b l n) (if (<= n 0) - [lam () l] + [lam () (let [(_ (debug 0))] l)] [lam () (recur b (+ (debug a) b) (cons a l) (- n 1))]))] 0 1 nil 30)) diff --git a/src/bin/filecheck.rs b/src/bin/filecheck.rs new file mode 100644 index 0000000..8f1e131 --- /dev/null +++ b/src/bin/filecheck.rs @@ -0,0 +1,47 @@ +use filecheck; +use std::{io::prelude::*, process}; + +fn main() { + let fname = match std::env::args().nth(1) { + Some(fname) => fname, + None => { + println!("Usage: filecheck "); + process::exit(1); + } + }; + + let text = match std::fs::read_to_string(&fname) { + Ok(text) => text, + Err(err) => { + println!("Error: failed to read '{}':\n{}", fname, err); + process::exit(1); + } + }; + + let checker = match filecheck::CheckerBuilder::new().text(&text) { + Ok(builder) => builder.finish(), + Err(err) => { + println!("Error parsing check directives: {}", err); + process::exit(1); + } + }; + + let mut buffer = String::new(); + if let Err(err) = std::io::stdin().read_to_string(&mut buffer) { + println!("Error reading from stdin: {}", err); + process::exit(1); + } + + let (success, explanation) = match checker.explain(&buffer, &()) { + Ok(res) => res, + Err(err) => { + println!("Error checking: {}", err); + process::exit(1); + } + }; + + if !success { + println!("{}", explanation); + process::exit(1); + } +} -- 2.43.2