Skip to content

Refactor current tests and start to use assert_cmd #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
47f09f9
tests/gnu/arch: change to assert_cli as CLI assertion util
Jul 12, 2018
80d4ed9
tests/gnu/base32: change to assert_cli as CLI assertion util
Jul 12, 2018
b0cc44b
tests: use new_cli macro to simplify creating assert command
Jul 12, 2018
6061fcd
tests/gnu/base64: change to assert_cli as CLI assertion util
Jul 12, 2018
7547355
tests: set tests/fixtures/util as current dir for assert cli
Jul 13, 2018
abdb172
tests/posix/cat: change to assert_cli as CLI assertion util
Jul 13, 2018
a4d6e33
tests: revert setting the default dir but provide a macro to get fixt…
Jul 13, 2018
105839f
tests: use assert_cmd and predicates instead of assert_cli
Jul 13, 2018
95b3766
tests: update assert_cmd and predicates and fix API changes
mssun Jul 20, 2018
a3fb6ec
tests/posix/test_head: start to use assert_cmd
mssun Jul 20, 2018
b36360d
tests/posix/test_head: forgot to assert success status
mssun Jul 20, 2018
f72f8bd
tests/posix/chmod: rewrite chmod testcases
Jul 31, 2018
a31a9ad
tests/posix/cat: delete unused mod
Jul 31, 2018
ead136e
tests/posix/sleep: rewrite sleep test cases
Jul 31, 2018
d085c75
Merge master changes into tests/refactor
Jul 31, 2018
126b03b
tests/posix/echo: rewrite echo with assert_cmd
Jul 31, 2018
1d28625
tests/posix/false: rewrite false with assert_cmd
Jul 31, 2018
2be4106
tests/posix/true: rewrite true with assert_cmd
Jul 31, 2018
48fd4cd
tests/posix/sleep: relax diff time
Jul 31, 2018
e5f8f17
tests/posix/sh: rewrite testcases of sh using assert_cmd
Jul 31, 2018
3de2bf7
CI: fix coverage script for libmesabox refactor
Jul 31, 2018
2a54f58
tests: delete tests framework and unused macros
Jul 31, 2018
0c9293a
CI: polish and simplify run-cov script
Aug 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 180 additions & 12 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ env_logger = { version = "0.5.11", optional = true }
tempfile = "3.0.2"
libc = "0.2.40"
lazy_static = "1.0.1"
assert_cmd = "0.6.0"
assert_fs = "0.3.0"
predicates = "0.5.2"

[profile.release]
lto = true
Expand Down
25 changes: 25 additions & 0 deletions ci/libmesabox-cov-rustc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -e

get_crate_name()
{
while [[ $# -gt 1 ]] ; do
v=$1
case $v in
--crate-name)
echo $2
return
;;
esac
shift
done
}

case $(get_crate_name "$@") in
libmesabox)
EXTRA=$COVERAGE_OPTIONS
;;
*)
;;
esac

exec "$@" $EXTRA
File renamed without changes.
17 changes: 9 additions & 8 deletions ci/run-cov
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

for path in /usr/lib/llvm-3.8/lib/clang/3.8.[0-9]/lib/linux/; do LLVM_PATH=$path; done
export COVERAGE_OPTIONS="-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Cpasses=insert-gcov-profiling -Zno-landing-pads -L$LLVM_PATH -lclang_rt.profile-x86_64"
export RUSTC_WRAPPER="./ci/cov-rustc"
export CARGO_INCREMENTAL=0

LCOVOPT="--gcov-tool ./ci/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert"
Expand All @@ -12,25 +11,27 @@ LCOV="/usr/local/bin/lcov"
rm -rf *.info *.gcda *.gcno
cargo clean

# unit tests
cargo rustc --all-features --profile test --lib
rm ./target/debug/mesabox-*.d
./target/debug/mesabox-*
${LCOV} ${LCOVOPT} --capture --directory . --base-directory . -o mesabox.info
# unit tests of libmesabox
export RUSTC_WRAPPER="./ci/libmesabox-cov-rustc"
cargo rustc --package libmesabox --all-features --profile test --lib
rm ./target/debug/libmesabox-*.d
./target/debug/libmesabox-*
${LCOV} ${LCOVOPT} --capture --directory . --base-directory . -o libmesabox.info

# cleanup target
rm -rf *.gcda *.gcno
cargo clean

# integration tests
export RUSTC_WRAPPER="./ci/mesabox-cov-rustc"
cargo rustc --all-features --test tests
rm ./target/debug/tests-*.d
./target/debug/tests-*
${LCOV} ${LCOVOPT} --capture --directory . --base-directory . -o tests.info

# combining and filtering
${LCOV} ${LCOVOPT} --add mesabox.info --add tests.info -o coverage.info
${LCOV} ${LCOVOPT} --extract coverage.info `find "$(cd src; pwd)" -name "*.rs"` -o final.info
${LCOV} ${LCOVOPT} --add libmesabox.info --add tests.info -o coverage.info
${LCOV} ${LCOVOPT} --extract coverage.info `find "$(cd src; pwd)" "$(cd libmesabox; pwd)" -name "*.rs"` -o final.info

# generate report if not in CI
if [[ "$CI" != true ]]; then
Expand Down
27 changes: 17 additions & 10 deletions tests/gnu/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@
// For a copy, see the LICENSE file.
//

use util::*;
use std::process::Command;
use assert_cmd::prelude::*;

const NAME: &str = "arch";

#[test]
#[cfg(target_arch = "x86_64")]
fn test_x86_64() {
new_ucmd!()
.succeeds()
.stdout_only("x86_64\n");
new_cmd!()
.assert()
.success()
.stdout("x86_64\n")
.stderr("");
}

#[test]
#[cfg(target_arch = "arm")]
fn test_arm() {
new_ucmd!()
.succeeds()
.stdout_only("arm\n");
new_cmd!()
.assert()
.success()
.stdout("arm\n")
.stderr("");
}

#[test]
#[cfg(target_arch = "aarch64")]
fn test_aarch64() {
new_ucmd!()
.succeeds()
.stdout_only("aarch64\n");
new_cmd!()
.assert()
.success()
.stdout("aarch64\n")
.stderr("");
}
83 changes: 47 additions & 36 deletions tests/gnu/base32.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright (c) 2018, The MesaLock Linux Project Contributors
// All rights reserved.
//
//
// This work is licensed under the terms of the BSD 3-Clause License.
// For a copy, see the LICENSE file.
//
Expand Down Expand Up @@ -32,86 +32,97 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

use util::*;
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;

const NAME: &str = "base32";

#[test]
fn test_encode() {
let input = "Hello, World!";
new_ucmd!()
.pipe_in(input)
.succeeds()
.stdout_only("JBSWY3DPFQQFO33SNRSCC===\n");
new_cmd!()
.with_stdin().buffer(input)
.assert()
.success()
.stdout("JBSWY3DPFQQFO33SNRSCC===\n")
.stderr("");
}

#[test]
fn test_decode() {
for decode_param in vec!["-d", "--decode"] {
let input = "JBSWY3DPFQQFO33SNRSCC===\n";
new_ucmd!()
new_cmd!()
.arg(decode_param)
.pipe_in(input)
.succeeds()
.stdout_only("Hello, World!");
.with_stdin().buffer(input)
.assert()
.success()
.stdout("Hello, World!")
.stderr("");
}
}

#[test]
fn test_garbage() {
let input = "aGVsbG8sIHdvcmxkIQ==\0";
new_ucmd!()
new_cmd!()
.arg("-d")
.pipe_in(input)
.fails()
.no_stdout()
.stderr_contains("invalid length at 16");
.with_stdin().buffer(input)
.assert()
.failure()
.stdout("")
.stderr(predicate::str::contains("invalid length at 16").from_utf8());
}

#[test]
fn test_ignore_garbage() {
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] {
let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n";
new_ucmd!()
.arg("-d")
.arg(ignore_garbage_param)
.pipe_in(input)
.succeeds()
.stdout_only("Hello, World!");
new_cmd!()
.args(&["-d", ignore_garbage_param])
.with_stdin().buffer(input)
.assert()
.success()
.stdout("Hello, World!")
.stderr("");
}
}

#[test]
fn test_wrap() {
for wrap_param in vec!["-w", "--wrap"] {
let input = "The quick brown fox jumps over the lazy dog.";
new_ucmd!()
.arg(wrap_param)
.arg("20")
.pipe_in(input)
.succeeds()
.stdout_only("KRUGKIDROVUWG2ZAMJZG\n653OEBTG66BANJ2W24DT\nEBXXMZLSEB2GQZJANRQX\nU6JAMRXWOLQ=\n");
new_cmd!()
.args(&[wrap_param, "20"])
.with_stdin().buffer(input)
.assert()
.success()
.stdout("KRUGKIDROVUWG2ZAMJZG\n653OEBTG66BANJ2W24DT\nEBXXMZLSEB2GQZJANRQX\nU6JAMRXWOLQ=\n")
.stderr("");
}
}

#[test]
fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] {
new_ucmd!()
new_cmd!()
.arg(wrap_param)
.fails()
.no_stdout()
.stderr_contains("requires a value but none was supplied\n");
.assert()
.failure()
.stdout("")
.stderr(predicate::str::contains("requires a value but none was supplied\n").from_utf8());
}
}

#[test]
fn test_wrap_bad_arg() {
for wrap_param in vec!["-w", "--wrap"] {
new_ucmd!()
.arg(wrap_param).arg("b")
.fails()
.no_stdout()
.stderr_contains("'b' is not a number\n");
new_cmd!()
.args(&[wrap_param, "b"])
.assert()
.failure()
.stdout("")
.stderr(predicate::str::contains("'b' is not a number\n").from_utf8());
}
}
Loading