diff --git a/Cargo.lock b/Cargo.lock index fc8ee1c..eea7a63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,20 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "assert_cmd" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a88b6bd5df287567ffdf4ddf4d33060048e1068308e5f62d81c6f9824a045a48" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -151,6 +165,18 @@ dependencies = [ "syn", ] +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" + +[[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" @@ -346,6 +372,7 @@ dependencies = [ name = "opentally" version = "0.1.0" dependencies = [ + "assert_cmd", "clap", "console_error_panic_hook", "csv", @@ -376,6 +403,32 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" +[[package]] +name = "predicates" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df" +dependencies = [ + "difference", + "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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +dependencies = [ + "predicates-core", + "treeline", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -494,6 +547,12 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd05616119e612a8041ef58f2b578906cc2531a6069047ae092cfb86a325d835" +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + [[package]] name = "unicode-segmentation" version = "1.7.1" @@ -518,6 +577,15 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "wasm-bindgen" version = "0.2.74" diff --git a/Cargo.toml b/Cargo.toml index 110e3e5..76fb725 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,9 @@ num-bigint = "0.4.0" num-rational = "0.4.0" paste = "1.0.5" +# For tests [target.'cfg(not(target_arch = "wasm32"))'.dependencies] +assert_cmd = "1.0.5" csv = "1.1.6" flate2 = "1.0" xmltree = "0.10.3" diff --git a/coverage.sh b/coverage.sh new file mode 100755 index 0000000..bf11a9a --- /dev/null +++ b/coverage.sh @@ -0,0 +1,14 @@ +#!/bin/bash +mkdir -p target/coverage/prof +rm target/coverage/prof/*.profraw + +export RUSTC=./rustc_bs.sh +export RUSTFLAGS="-Zinstrument-coverage -Copt-level=0 -Clink-dead-code" +export LLVM_PROFILE_FILE="target/coverage/prof/opentally-%p-%m.profraw" +export CARGO_TARGET_DIR=target/coverage +cargo test + +grcov target/coverage/prof --binary-path target/coverage/debug -t html -o target/coverage/html \ + --ignore src/numbers/rational_num.rs \ + --ignore src/stv/wasm.rs \ + --ignore 'tests/*' diff --git a/rustc_bs.sh b/rustc_bs.sh new file mode 100755 index 0000000..a847e10 --- /dev/null +++ b/rustc_bs.sh @@ -0,0 +1,3 @@ +#!/bin/bash +RUSTC_BOOTSTRAP=1 rustc $@ + diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..945e87c --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,27 @@ +/* OpenTally: Open-source election vote counting + * Copyright © 2021 Lee Yingtong Li (RunasSudo) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +use assert_cmd::prelude::*; + +use std::process::Command; + +#[test] +fn cli_ers97() { + Command::cargo_bin("opentally").expect("Cargo Error") + .args(&["stv", "tests/data/ers97.blt", "--numbers", "fixed", "--decimals", "5", "--round-tvs", "2", "--round-weights", "2", "--round-votes", "2", "--round-quota", "2", "--quota", "droop_exact", "--quota-mode", "ers97", "--surplus", "eg", "--transferable-only", "--exclusion", "by_value"]) + .assert().success(); +}