From f2bbb05c284d0c71d3631dc26f5739a8613ea36e Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 5 Feb 2018 18:01:14 +0100 Subject: [PATCH 1/6] add assert_cli and simple test --- Cargo.lock | 298 ++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 1 + Dockerfile | 4 +- tests/add.code | 6 + tests/integration.rs | 15 +++ 5 files changed, 306 insertions(+), 18 deletions(-) create mode 100644 tests/add.code create mode 100644 tests/integration.rs diff --git a/Cargo.lock b/Cargo.lock index 4afb55fd..88503fd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,19 +1,3 @@ -[root] -name = "zokrates" -version = "0.1.0" -dependencies = [ - "bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "aho-corasick" version = "0.6.3" @@ -27,6 +11,19 @@ name = "ansi_term" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "assert_cli" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "skeptic 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.3" @@ -38,6 +35,27 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "backtrace" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bincode" version = "0.8.0" @@ -53,11 +71,43 @@ name = "bitflags" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bitflags" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "bytecount" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cargo_metadata" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cc" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "clap" version = "2.26.2" @@ -73,6 +123,51 @@ dependencies = [ "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "colored" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "difference" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "dtoa" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "environment" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "error-chain" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "gcc" version = "0.3.42" @@ -83,6 +178,11 @@ name = "glob" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "itoa" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -181,6 +281,14 @@ name = "num-traits" version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "pulldown-cmark" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.3.15" @@ -194,6 +302,16 @@ dependencies = [ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.31" @@ -224,11 +342,48 @@ name = "regex-syntax" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "remove_dir_all" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-serialize" version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "serde" version = "1.0.15" @@ -253,6 +408,32 @@ dependencies = [ "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde_json" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "skeptic" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytecount 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_metadata 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "strsim" version = "0.6.0" @@ -276,6 +457,15 @@ dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tempdir" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "remove_dir_all 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "term_size" version = "0.3.0" @@ -347,26 +537,88 @@ name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "walkdir" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "zokrates" +version = "0.1.0" +dependencies = [ + "assert_cli 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" +"checksum assert_cli 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "72342c21057a3cb5f7c2d849bf7999a83795434dd36d74fa8c24680581bd1930" "checksum atty 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21e50800ec991574876040fff8ee46b136a53e985286fbe6a3bdfe6421b78860" +"checksum backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbbf59b1c43eefa8c3ede390fcc36820b4999f7914104015be25025e0d62af2" +"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661" "checksum bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" +"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" +"checksum bytecount 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af27422163679dea46a1a7239dffff64d3dcdc3ba5fe9c49c789fbfe0eb949de" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" +"checksum cargo_metadata 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1f56ec3e469bca7c276f2eea015aa05c5e381356febdbb0683c2580189604537" +"checksum cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0" +"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2" +"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc" +"checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8" +"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" +"checksum environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4b14e20978669064c33b4c1e0fb4083412e40fe56cbea2eae80fd7591503ee" +"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "291055c78f59ca3d84c99026c9501c469413d386bb46be1e1cf1d285cd1db3b0" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" +"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417" "checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" @@ -379,19 +631,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" "checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf" "checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" +"checksum pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a656fdb8b6848f896df5e478a0eb9083681663e37dcb77dd16981ff65329fe8b" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" +"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" +"checksum remove_dir_all 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d2f806b0fcdabd98acd380dc8daef485e22bcb7cddc811d1337967f2528cf5" +"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" +"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" +"checksum semver 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bee2bc909ab2d8d60dab26e8cad85b25d795b14603a0dcb627b78b9d30b6454b" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "6a7046c9d4c6c522d10b2d098f9bebe2bef227e0e74044d8c1bfcf6b476af799" "checksum serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1afcaae083fd1c46952a315062326bc9957f182358eb7da03b57ef1c688f7aa9" "checksum serde_derive_internals 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd381f6d01a6616cdba8530492d453b7761b456ba974e98768a18cad2cd76f58" +"checksum serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9db7266c7d63a4c4b7fe8719656ccdd51acf1bed6124b174f933b009fb10bcb" +"checksum skeptic 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c8431f8fca168e2db4be547bd8329eac70d095dff1444fee4b0fa0fabc7df75a" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" +"checksum tempdir 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f73eebdb68c14bcb24aef74ea96079830e7fa7b31a6106e42ea7ee887c1e134e" "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8e08afc40ae3459e4838f303e465aa50d823df8d7f83ca88108f6d3afe7edd" @@ -402,5 +664,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 9d25624f..59e2e206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ regex = "0.2" [dev-dependencies] glob = "0.2.11" +assert_cli = "0.5" [build-dependencies] gcc = "0.3.41" diff --git a/Dockerfile b/Dockerfile index af59e3d0..ce3a3089 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ RUN wget https://github.com/scipr-lab/libsnark/archive/$libsnarkcommit.zip \ && ./prepare-depends.sh RUN curl https://sh.rustup.rs -sSf | \ - sh -s -- --default-toolchain nightly-2017-03-20 -y + sh -s -- --default-toolchain nightly-2018-02-05 -y ENV PATH=/root/.cargo/bin:$PATH @@ -31,4 +31,4 @@ ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib COPY . /root/ZoKrates RUN cd ZoKrates \ - && cargo build --release + && cargo build --release --features nolibsnark diff --git a/tests/add.code b/tests/add.code new file mode 100644 index 00000000..b5138449 --- /dev/null +++ b/tests/add.code @@ -0,0 +1,6 @@ +// only using add, no need to flatten +def main(): + b = a + 5 + c = a + b + a + 4 + d = a + c + a + b + return b + c + d diff --git a/tests/integration.rs b/tests/integration.rs new file mode 100644 index 00000000..de25667d --- /dev/null +++ b/tests/integration.rs @@ -0,0 +1,15 @@ +extern crate assert_cli; + +#[cfg(test)] +mod integration { + use assert_cli; + + #[test] + fn without_arg() { + assert_cli::Assert::command(&["cargo", "run", "--features", "nolibsnark", "--", "compile", "-i", "./tests/add.code"]) + .fails() + .and() + .stderr().contains("Semantic analysis failed with: a is undefined") + .unwrap(); + } +} \ No newline at end of file From bc808390df71c37c92e3ce818488f36f8eed542c Mon Sep 17 00:00:00 2001 From: schaeff Date: Thu, 15 Feb 2018 21:41:46 +0100 Subject: [PATCH 2/6] remove nolibsnark flag --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1b7fe263..529ef2d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,4 +31,4 @@ ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib COPY . /root/ZoKrates RUN cd ZoKrates \ - && cargo build --release --features nolibsnark + && cargo build --release From d9b043cdd6caf0dd33fd80f792a61e09e7ee3394 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 26 Feb 2018 11:48:25 +0100 Subject: [PATCH 3/6] add expected, change witness to btree --- .DS_Store | Bin 0 -> 8196 bytes src/absy.rs | 12 ++-- src/main.rs | 2 +- tests/.DS_Store | Bin 0 -> 6148 bytes tests/code/.DS_Store | Bin 0 -> 6148 bytes tests/{ => code}/add.code | 0 tests/code/simple_add.code | 3 + tests/code/simple_add.expected.out.code | 2 + tests/code/simple_add.expected.witness | 4 ++ tests/integration.rs | 72 ++++++++++++++++++++++-- 10 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 .DS_Store create mode 100644 tests/.DS_Store create mode 100644 tests/code/.DS_Store rename tests/{ => code}/add.code (100%) create mode 100644 tests/code/simple_add.code create mode 100644 tests/code/simple_add.expected.out.code create mode 100644 tests/code/simple_add.expected.witness diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..01423ae0e189722b4ea92de25262ef64f9b531c6 GIT binary patch literal 8196 zcmeHM&2G~`82mO#ixX5438a>rFGw7sD5gTFsw#yvJ@kNt2!aEk){aeT;n-2^5FiBQ z!aE>%0$zm+M;?R+fZ3l$&L-i|1FB#@X?NE4jJ=*+d-FL AZYA=)7#3x#9#DykL1 zkMpt=1-0iokU>xMiUJx^NIi;|*k*@uz&KzWFb)_8j02a!0j$|PtTpStJZfs=fN|iz zbb!AfY!r@7g)@ob)qzT+0KgJ0I!Fb*s`z;pL4s*_I%brZN<6Um zgSC%x`^|t z^>8P3sKotfnxB8vWYF{}TGSNWB~3f$)l1Ps&8Nb5O=ID^$Q$&oPXqKU(C?*qpz(`f zh2$;vM7aMc=YE+U(GlIJHa!5=adux*@Nvj1O7LeysXku9`;|OzoDS6ZfAa=Wm}ZT} z4^}9aHa4$VR>i7pRbF(?l5r<8ljM;@@OvQ<8*-kePC?CsTTXLom6vnP(@G-~$UdyVO| zY;E6i4vtUzZ{JPcPd|LdT_c!UD(ITrp4VT{nmh5jGmN7o?r{N15$+7ByXd2sYk7Y* zDN}PTSn`t3u{^g7ZlFfq6>V)Miy4+zY)BSroyq6b8s { impl Prog { // only main flattened function is relevant here, as all other functions are unrolled into it #[allow(dead_code)] // I don't want to remove this - pub fn get_witness(&self, inputs: Vec) -> HashMap { + pub fn get_witness(&self, inputs: Vec) -> BTreeMap { let main = self.functions.iter().find(|x| x.id == "main").unwrap(); assert!(main.arguments.len() == inputs.len()); main.get_witness(inputs) @@ -69,9 +69,9 @@ pub struct Function { impl Function { // for flattened functions - pub fn get_witness(&self, inputs: Vec) -> HashMap { + pub fn get_witness(&self, inputs: Vec) -> BTreeMap { assert!(self.arguments.len() == inputs.len()); - let mut witness = HashMap::new(); + let mut witness = BTreeMap::new(); witness.insert("~one".to_string(), T::one()); for (i, arg) in self.arguments.iter().enumerate() { witness.insert(arg.id.to_string(), inputs[i].clone()); @@ -289,7 +289,7 @@ impl Expression { } } - fn solve(&self, inputs: &mut HashMap) -> T { + fn solve(&self, inputs: &mut BTreeMap) -> T { match *self { Expression::Number(ref x) => x.clone(), Expression::Identifier(ref var) => { @@ -502,7 +502,7 @@ impl Condition { } } - fn solve(&self, inputs: &mut HashMap) -> bool { + fn solve(&self, inputs: &mut BTreeMap) -> bool { match *self { Condition::Lt(ref lhs, ref rhs) => lhs.solve(inputs) < rhs.solve(inputs), Condition::Le(ref lhs, ref rhs) => lhs.solve(inputs) <= rhs.solve(inputs), diff --git a/src/main.rs b/src/main.rs index fd42cd42..711f253b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,7 +253,7 @@ fn main() { hrofb.flush().expect("Unable to flush buffer."); // debugging output - //println!("Compiled program:\n{}", program_flattened); + println!("Compiled program:\n{}", program_flattened); println!( diff --git a/tests/.DS_Store b/tests/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8c6f54d06e2208882a66f8ce17d78ab7604a887d GIT binary patch literal 6148 zcmeHKOG*Sm41JmD#eg8Q(`7AP3ErR>#)WGypz}cn#%b}h@9TIPkEAajg>HMRpd?Uv zsY+7S{h%uy0J3=5TmW+bGY&;jV?=a$)HR9VDN%Hft9`p(?b{XSy5V0Cef9=xwAf%f zc>Y)V&fZPzRgSU40ngat4v)B{wPW4^=bSzDbLC`^J7x4e9{N#}w?UL0lPVcV29kkf zAQ|{k23WIIW=D>xlYwL)8TevA?}x&nSOYspyE>?>1t2zDHlc05{=}jS#2VN+a)lzE zO7v8T7DJ+Q5KpJSMttY!=@2`a`^3qg&5K0iA;rQW)iHH4kPP%0(B79a*ZP0SPieHt zw~$oHKr--O8IWdqyHZe0cEPdoeIWS=r|9sAC%j;V26sP91I*bf#ff3qU?3O>2DS|7_aRXgE63h2e>!M# z2|(1}$SiDYEuk^Vv2yGUIYJQ&C0eL>i6Iuw{^Wj@V{d5T5HCK&R~D~OB(Ki-Q+9_` zhGBz&U|`6=kv*20|F3t~|HGho3I>9Kf5m`I=eP42kL0;^bU4kmiF!{}QNP}B8^T6T g#q`xwd`8W}{-h0J<=7jthY~*mnT9aIz@IYk0h-rv<^TWy literal 0 HcmV?d00001 diff --git a/tests/add.code b/tests/code/add.code similarity index 100% rename from tests/add.code rename to tests/code/add.code diff --git a/tests/code/simple_add.code b/tests/code/simple_add.code new file mode 100644 index 00000000..5754b009 --- /dev/null +++ b/tests/code/simple_add.code @@ -0,0 +1,3 @@ +// only using add, no need to flatten +def main(a, b): + return a + b diff --git a/tests/code/simple_add.expected.out.code b/tests/code/simple_add.expected.out.code new file mode 100644 index 00000000..578e28c1 --- /dev/null +++ b/tests/code/simple_add.expected.out.code @@ -0,0 +1,2 @@ +def main(a,b): + return (a + b) diff --git a/tests/code/simple_add.expected.witness b/tests/code/simple_add.expected.witness new file mode 100644 index 00000000..c0218725 --- /dev/null +++ b/tests/code/simple_add.expected.witness @@ -0,0 +1,4 @@ +a 1 +b 2 +~one 1 +~out_0 3 diff --git a/tests/integration.rs b/tests/integration.rs index de25667d..bbcdf900 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -3,13 +3,75 @@ extern crate assert_cli; #[cfg(test)] mod integration { use assert_cli; + use std::fs::{File}; + use std::path::Path; + use std::io; + use std::io::prelude::*; + use std::fs::{self}; + + // one possible implementation of walking a directory only visiting files + fn visit_dirs(dir: &Path) -> io::Result<()> { + if dir.is_dir() { + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + visit_dirs(&path)?; + } else { + assert_eq!(path.into_os_string().into_string().unwrap(), "abc".to_string()); + } + } + } + Ok(()) + } #[test] - fn without_arg() { - assert_cli::Assert::command(&["cargo", "run", "--features", "nolibsnark", "--", "compile", "-i", "./tests/add.code"]) - .fails() - .and() - .stderr().contains("Semantic analysis failed with: a is undefined") + fn simple_add() { + test_compile_and_witness("./tests/code/simple_add.code", "./tests/code/simple_add.expected.out.code", "-a 1 2", "./tests/code/simple_add.expected.witness") + } + + #[test] + fn t() { + visit_dirs(Path::new("./tests/code")); + } + + fn test_compile_and_witness(program_path: &str, expected_flattened_code_path: &str, arguments: &str, expected_witness_path: &str) { + let flattened_path = "./tests/tmp/out"; + let flattened_code_path = "./tests/tmp/out.code"; + let witness_path = "./tests/tmp/witness"; + + // compile + assert_cli::Assert::command(&["cargo", "run", "--", "compile", "-i", program_path, "-o", flattened_path]) + .succeeds() .unwrap(); + + // compile + assert_cli::Assert::command(&["cargo", "run", "--", "compute-witness", "-i", flattened_path, "-o", witness_path, "-a", "1", "2"]) + .succeeds() + .unwrap(); + + // load the expected result + let mut expected_flattened_code_file = File::open(expected_flattened_code_path).unwrap(); + let mut expected_flattened_code = String::new(); + expected_flattened_code_file.read_to_string(&mut expected_flattened_code); + + // load the expected witness + let mut expected_witness_file = File::open(expected_witness_path).unwrap(); + let mut expected_witness = String::new(); + expected_witness_file.read_to_string(&mut expected_witness); + + // load the actual result + let mut flattened_code_file = File::open(flattened_code_path).unwrap(); + let mut flattened_code = String::new(); + flattened_code_file.read_to_string(&mut flattened_code); + + // load the actual witness + let mut witness_file = File::open(witness_path).unwrap(); + let mut witness = String::new(); + witness_file.read_to_string(&mut witness); + + // check equality + assert_eq!(flattened_code, expected_flattened_code); + assert_eq!(witness, expected_witness); } } \ No newline at end of file From 276bfece29770c58683b03c11878405cb31bbf8c Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 26 Feb 2018 11:49:35 +0100 Subject: [PATCH 4/6] add .DS_Store to gitignore --- .DS_Store | Bin 8196 -> 0 bytes .gitignore | 2 ++ tests/.DS_Store | Bin 6148 -> 0 bytes tests/code/.DS_Store | Bin 6148 -> 0 bytes 4 files changed, 2 insertions(+) delete mode 100644 .DS_Store delete mode 100644 tests/.DS_Store delete mode 100644 tests/code/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 01423ae0e189722b4ea92de25262ef64f9b531c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHM&2G~`82mO#ixX5438a>rFGw7sD5gTFsw#yvJ@kNt2!aEk){aeT;n-2^5FiBQ z!aE>%0$zm+M;?R+fZ3l$&L-i|1FB#@X?NE4jJ=*+d-FL AZYA=)7#3x#9#DykL1 zkMpt=1-0iokU>xMiUJx^NIi;|*k*@uz&KzWFb)_8j02a!0j$|PtTpStJZfs=fN|iz zbb!AfY!r@7g)@ob)qzT+0KgJ0I!Fb*s`z;pL4s*_I%brZN<6Um zgSC%x`^|t z^>8P3sKotfnxB8vWYF{}TGSNWB~3f$)l1Ps&8Nb5O=ID^$Q$&oPXqKU(C?*qpz(`f zh2$;vM7aMc=YE+U(GlIJHa!5=adux*@Nvj1O7LeysXku9`;|OzoDS6ZfAa=Wm}ZT} z4^}9aHa4$VR>i7pRbF(?l5r<8ljM;@@OvQ<8*-kePC?CsTTXLom6vnP(@G-~$UdyVO| zY;E6i4vtUzZ{JPcPd|LdT_c!UD(ITrp4VT{nmh5jGmN7o?r{N15$+7ByXd2sYk7Y* zDN}PTSn`t3u{^g7ZlFfq6>V)Miy4+zY)BSroyq6b8s#)WGypz}cn#%b}h@9TIPkEAajg>HMRpd?Uv zsY+7S{h%uy0J3=5TmW+bGY&;jV?=a$)HR9VDN%Hft9`p(?b{XSy5V0Cef9=xwAf%f zc>Y)V&fZPzRgSU40ngat4v)B{wPW4^=bSzDbLC`^J7x4e9{N#}w?UL0lPVcV29kkf zAQ|{k23WIIW=D>xlYwL)8TevA?}x&nSOYspyE>?>1t2zDHlc05{=}jS#2VN+a)lzE zO7v8T7DJ+Q5KpJSMttY!=@2`a`^3qg&5K0iA;rQW)iHH4kPP%0(B79a*ZP0SPieHt zw~$oHKr--O8IWdqyHZe0cEPdoeIWS=r|9sAC%j;V26sP91I*bf#ff3qU?3O>2DS|7_aRXgE63h2e>!M# z2|(1}$SiDYEuk^Vv2yGUIYJQ&C0eL>i6Iuw{^Wj@V{d5T5HCK&R~D~OB(Ki-Q+9_` zhGBz&U|`6=kv*20|F3t~|HGho3I>9Kf5m`I=eP42kL0;^bU4kmiF!{}QNP}B8^T6T g#q`xwd`8W}{-h0J<=7jthY~*mnT9aIz@IYk0h-rv<^TWy From c0600779f228397b0e85cb32d717759d77e13c4a Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 26 Feb 2018 19:52:28 +0100 Subject: [PATCH 5/6] read arguments from json, walk folder to run tests --- Cargo.lock | 1 + Cargo.toml | 1 + tests/code/add.code | 6 --- tests/code/simple_add.arguments.json | 1 + tests/integration.rs | 71 +++++++++++++++------------- 5 files changed, 42 insertions(+), 38 deletions(-) delete mode 100644 tests/code/add.code create mode 100644 tests/code/simple_add.arguments.json diff --git a/Cargo.lock b/Cargo.lock index e6c8ac75..7407494d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -583,6 +583,7 @@ dependencies = [ "regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] diff --git a/Cargo.toml b/Cargo.toml index 59e2e206..539e5ee4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ clap = "2.26.2" # serialization and deserialization serde = "1.0" serde_derive = "1.0" +serde_json = "1.0" bincode = "0.8.0" regex = "0.2" diff --git a/tests/code/add.code b/tests/code/add.code deleted file mode 100644 index b5138449..00000000 --- a/tests/code/add.code +++ /dev/null @@ -1,6 +0,0 @@ -// only using add, no need to flatten -def main(): - b = a + 5 - c = a + b + a + 4 - d = a + c + a + b - return b + c + d diff --git a/tests/code/simple_add.arguments.json b/tests/code/simple_add.arguments.json new file mode 100644 index 00000000..fd8ef095 --- /dev/null +++ b/tests/code/simple_add.arguments.json @@ -0,0 +1 @@ +[1, 2] \ No newline at end of file diff --git a/tests/integration.rs b/tests/integration.rs index bbcdf900..cc6414cf 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,74 +1,81 @@ extern crate assert_cli; +extern crate serde_json; #[cfg(test)] mod integration { use assert_cli; use std::fs::{File}; use std::path::Path; - use std::io; use std::io::prelude::*; use std::fs::{self}; - - // one possible implementation of walking a directory only visiting files - fn visit_dirs(dir: &Path) -> io::Result<()> { + use serde_json; + use serde_json::Value; + + #[test] + fn test_compile_and_witness_dir() { + let dir = Path::new("./tests/code"); if dir.is_dir() { - for entry in fs::read_dir(dir)? { - let entry = entry?; + for entry in fs::read_dir(dir).unwrap() { + let entry = entry.unwrap(); let path = entry.path(); - if path.is_dir() { - visit_dirs(&path)?; - } else { - assert_eq!(path.into_os_string().into_string().unwrap(), "abc".to_string()); + if path.extension().unwrap() == "witness" { + let base = Path::new(Path::new(path.file_stem().unwrap()).file_stem().unwrap()); + let prog = dir.join(base).with_extension("code"); + let flat = dir.join(base).with_extension("expected.out.code"); + let witness = dir.join(base).with_extension("expected.witness"); + let args = dir.join(base).with_extension("arguments.json"); + test_compile_and_witness(&prog, &flat, &args, &witness); } } } - Ok(()) } - #[test] - fn simple_add() { - test_compile_and_witness("./tests/code/simple_add.code", "./tests/code/simple_add.expected.out.code", "-a 1 2", "./tests/code/simple_add.expected.witness") - } - - #[test] - fn t() { - visit_dirs(Path::new("./tests/code")); - } - - fn test_compile_and_witness(program_path: &str, expected_flattened_code_path: &str, arguments: &str, expected_witness_path: &str) { - let flattened_path = "./tests/tmp/out"; - let flattened_code_path = "./tests/tmp/out.code"; - let witness_path = "./tests/tmp/witness"; + fn test_compile_and_witness(program_path: &Path, expected_flattened_code_path: &Path, arguments_path: &Path, expected_witness_path: &Path) { + let flattened_path = Path::new("./tests/tmp/out"); + let flattened_code_path = Path::new("./tests/tmp/out.code"); + let witness_path = Path::new("./tests/tmp/witness"); // compile - assert_cli::Assert::command(&["cargo", "run", "--", "compile", "-i", program_path, "-o", flattened_path]) + assert_cli::Assert::command(&["cargo", "run", "--", "compile", "-i", program_path.to_str().unwrap(), "-o", flattened_path.to_str().unwrap()]) .succeeds() .unwrap(); - // compile - assert_cli::Assert::command(&["cargo", "run", "--", "compute-witness", "-i", flattened_path, "-o", witness_path, "-a", "1", "2"]) + // compute + let arguments: Value = serde_json::from_reader(File::open(arguments_path).unwrap()).unwrap(); + + let arguments_str_list: Vec = arguments.as_array().unwrap().iter().map(|i| match *i { + Value::Number(ref n) => n.to_string(), + _ => panic!(format!("Cannot read arguments. Check {}", arguments_path.to_str().unwrap())) + }).collect(); + + let mut compute = vec!["cargo", "run", "--", "compute-witness", "-i", flattened_path.to_str().unwrap(), "-o", witness_path.to_str().unwrap(), "-a"]; + + for arg in arguments_str_list.iter() { + compute.push(arg); + } + assert_cli::Assert::command(&compute) .succeeds() .unwrap(); // load the expected result let mut expected_flattened_code_file = File::open(expected_flattened_code_path).unwrap(); let mut expected_flattened_code = String::new(); - expected_flattened_code_file.read_to_string(&mut expected_flattened_code); + expected_flattened_code_file.read_to_string(&mut expected_flattened_code).unwrap(); // load the expected witness let mut expected_witness_file = File::open(expected_witness_path).unwrap(); let mut expected_witness = String::new(); - expected_witness_file.read_to_string(&mut expected_witness); + expected_witness_file.read_to_string(&mut expected_witness).unwrap(); // load the actual result let mut flattened_code_file = File::open(flattened_code_path).unwrap(); let mut flattened_code = String::new(); - flattened_code_file.read_to_string(&mut flattened_code); + flattened_code_file.read_to_string(&mut flattened_code).unwrap(); // load the actual witness let mut witness_file = File::open(witness_path).unwrap(); let mut witness = String::new(); - witness_file.read_to_string(&mut witness); + witness_file.read_to_string(&mut witness).unwrap(); // check equality assert_eq!(flattened_code, expected_flattened_code); From 7d0b517a34523109db7d1f9abeab19d5ed7dcbde Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 26 Feb 2018 21:10:28 +0100 Subject: [PATCH 6/6] reduce witness requirement to outputs only, setup and teardown folders --- tests/code/simple_add.expected.witness | 3 -- tests/code/simple_mul.arguments.json | 1 + tests/code/simple_mul.code | 2 + tests/code/simple_mul.expected.out.code | 3 ++ tests/code/simple_mul.expected.witness | 1 + tests/integration.rs | 60 ++++++++++++++++++------- 6 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 tests/code/simple_mul.arguments.json create mode 100644 tests/code/simple_mul.code create mode 100644 tests/code/simple_mul.expected.out.code create mode 100644 tests/code/simple_mul.expected.witness diff --git a/tests/code/simple_add.expected.witness b/tests/code/simple_add.expected.witness index c0218725..23b7f950 100644 --- a/tests/code/simple_add.expected.witness +++ b/tests/code/simple_add.expected.witness @@ -1,4 +1 @@ -a 1 -b 2 -~one 1 ~out_0 3 diff --git a/tests/code/simple_mul.arguments.json b/tests/code/simple_mul.arguments.json new file mode 100644 index 00000000..f26b6970 --- /dev/null +++ b/tests/code/simple_mul.arguments.json @@ -0,0 +1 @@ +[2, 3, 4] \ No newline at end of file diff --git a/tests/code/simple_mul.code b/tests/code/simple_mul.code new file mode 100644 index 00000000..f301d167 --- /dev/null +++ b/tests/code/simple_mul.code @@ -0,0 +1,2 @@ +def main(a, b, c): + return a * b * c diff --git a/tests/code/simple_mul.expected.out.code b/tests/code/simple_mul.expected.out.code new file mode 100644 index 00000000..b7887db8 --- /dev/null +++ b/tests/code/simple_mul.expected.out.code @@ -0,0 +1,3 @@ +def main(a,b,c): + sym_0 = (b * c) + return (a * sym_0) diff --git a/tests/code/simple_mul.expected.witness b/tests/code/simple_mul.expected.witness new file mode 100644 index 00000000..8eb3a8d7 --- /dev/null +++ b/tests/code/simple_mul.expected.witness @@ -0,0 +1 @@ +~out_0 24 \ No newline at end of file diff --git a/tests/integration.rs b/tests/integration.rs index cc6414cf..db1f41e4 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -8,10 +8,32 @@ mod integration { use std::path::Path; use std::io::prelude::*; use std::fs::{self}; + use std::panic; use serde_json; use serde_json::Value; + + fn setup() { + fs::create_dir("./tests/tmp").unwrap(); + } + + fn teardown() { + fs::remove_dir_all("./tests/tmp").unwrap(); + } #[test] + fn run_integration_tests() { + // see https://medium.com/@ericdreichert/test-setup-and-teardown-in-rust-without-a-framework-ba32d97aa5ab + setup(); + + let result = panic::catch_unwind(|| { + test_compile_and_witness_dir() + }); + + teardown(); + + assert!(result.is_ok()) + } + fn test_compile_and_witness_dir() { let dir = Path::new("./tests/code"); if dir.is_dir() { @@ -19,21 +41,26 @@ mod integration { let entry = entry.unwrap(); let path = entry.path(); if path.extension().unwrap() == "witness" { - let base = Path::new(Path::new(path.file_stem().unwrap()).file_stem().unwrap()); - let prog = dir.join(base).with_extension("code"); - let flat = dir.join(base).with_extension("expected.out.code"); - let witness = dir.join(base).with_extension("expected.witness"); - let args = dir.join(base).with_extension("arguments.json"); - test_compile_and_witness(&prog, &flat, &args, &witness); + let program_name = Path::new(Path::new(path.file_stem().unwrap()).file_stem().unwrap()); + let prog = dir.join(program_name).with_extension("code"); + let flat = dir.join(program_name).with_extension("expected.out.code"); + let witness = dir.join(program_name).with_extension("expected.witness"); + let args = dir.join(program_name).with_extension("arguments.json"); + test_compile_and_witness(program_name.to_str().unwrap(), &prog, &flat, &args, &witness); } } } } - fn test_compile_and_witness(program_path: &Path, expected_flattened_code_path: &Path, arguments_path: &Path, expected_witness_path: &Path) { - let flattened_path = Path::new("./tests/tmp/out"); - let flattened_code_path = Path::new("./tests/tmp/out.code"); - let witness_path = Path::new("./tests/tmp/witness"); + fn test_compile_and_witness(program_name: &str, program_path: &Path, expected_flattened_code_path: &Path, arguments_path: &Path, expected_witness_path: &Path) { + let tmp_base = Path::new("./tests/tmp/"); + let test_case_path = tmp_base.join(program_name); + let flattened_path = tmp_base.join(program_name).join("out"); + let flattened_code_path = tmp_base.join(program_name).join("out").with_extension("code"); + let witness_path = tmp_base.join(program_name).join("witness"); + + // create a tmp folder to store artifacts + fs::create_dir(test_case_path).unwrap(); // compile assert_cli::Assert::command(&["cargo", "run", "--", "compile", "-i", program_path.to_str().unwrap(), "-o", flattened_path.to_str().unwrap()]) @@ -53,32 +80,33 @@ mod integration { for arg in arguments_str_list.iter() { compute.push(arg); } + assert_cli::Assert::command(&compute) .succeeds() .unwrap(); // load the expected result - let mut expected_flattened_code_file = File::open(expected_flattened_code_path).unwrap(); + let mut expected_flattened_code_file = File::open(&expected_flattened_code_path).unwrap(); let mut expected_flattened_code = String::new(); expected_flattened_code_file.read_to_string(&mut expected_flattened_code).unwrap(); // load the expected witness - let mut expected_witness_file = File::open(expected_witness_path).unwrap(); + let mut expected_witness_file = File::open(&expected_witness_path).unwrap(); let mut expected_witness = String::new(); expected_witness_file.read_to_string(&mut expected_witness).unwrap(); // load the actual result - let mut flattened_code_file = File::open(flattened_code_path).unwrap(); + let mut flattened_code_file = File::open(&flattened_code_path).unwrap(); let mut flattened_code = String::new(); flattened_code_file.read_to_string(&mut flattened_code).unwrap(); // load the actual witness - let mut witness_file = File::open(witness_path).unwrap(); + let mut witness_file = File::open(&witness_path).unwrap(); let mut witness = String::new(); witness_file.read_to_string(&mut witness).unwrap(); // check equality - assert_eq!(flattened_code, expected_flattened_code); - assert_eq!(witness, expected_witness); + assert_eq!(flattened_code, expected_flattened_code, "Flattening failed for {}\n\nExpected\n\n{}\n\nGot\n\n{}", program_path.to_str().unwrap(), expected_flattened_code.as_str(), flattened_code.as_str()); + assert!(witness.contains(expected_witness.as_str()), "Witness generation failed for {}\n\nExpected\n\n{}\n\nGot\n\n{}", program_path.to_str().unwrap(), expected_witness.as_str(), witness.as_str()); } } \ No newline at end of file