From d04ee6c04c44926a57bf5f7b7f9f6435156886d4 Mon Sep 17 00:00:00 2001 From: Pauan Date: Fri, 26 Jul 2019 18:40:29 +0200 Subject: [PATCH] Adding in unit tests for --quiet and --log-level --- tests/all/log_level.rs | 91 ++++++++++++++++++++++++++++++++++++++++++ tests/all/main.rs | 1 + 2 files changed, 92 insertions(+) create mode 100644 tests/all/log_level.rs diff --git a/tests/all/log_level.rs b/tests/all/log_level.rs new file mode 100644 index 0000000..ea129a0 --- /dev/null +++ b/tests/all/log_level.rs @@ -0,0 +1,91 @@ +use assert_cmd::prelude::*; +use predicates::boolean::PredicateBooleanExt; +use predicates::prelude::predicate::str::contains; +use predicates::reflection::PredicateReflection; +use predicates::Predicate; +use utils; + +fn matches_info() -> impl Predicate + PredicateReflection { + contains("[INFO]: Checking for the Wasm target...") + .and(contains("[INFO]: Compiling to Wasm...")) + .and(contains("[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory")) + .and(contains("[INFO]: Installing wasm-bindgen...")) + .and(contains("[INFO]: Optimizing wasm binaries with `wasm-opt`...")) + .and(contains("[INFO]: :-) Done in ")) + .and(contains("[INFO]: :-) Your wasm pkg is ready to publish at ")) +} + +fn matches_warn() -> impl Predicate + PredicateReflection { + contains(":-) [WARN]: origin crate has no README") +} + +fn matches_cargo() -> impl Predicate + PredicateReflection { + contains("Finished release [optimized] target(s) in ") +} + +#[test] +fn quiet() { + utils::fixture::Fixture::new() + .cargo_toml("js-hello-world") + .hello_world_src_lib() + .wasm_pack() + .arg("--quiet") + .arg("build") + .assert() + .success() + .stdout("") + .stderr(""); +} + +#[test] +fn log_level_info() { + utils::fixture::Fixture::new() + .cargo_toml("js-hello-world") + .hello_world_src_lib() + .wasm_pack() + .arg("--log-level") + .arg("info") + .arg("build") + .assert() + .success() + .stdout("") + .stderr(matches_cargo().and(matches_warn()).and(matches_info())); +} + +#[test] +fn log_level_warn() { + utils::fixture::Fixture::new() + .cargo_toml("js-hello-world") + .hello_world_src_lib() + .wasm_pack() + .arg("--log-level") + .arg("warn") + .arg("build") + .assert() + .success() + .stdout("") + .stderr( + matches_cargo() + .and(matches_warn()) + .and(matches_info().not()), + ); +} + +#[test] +fn log_level_error() { + utils::fixture::Fixture::new() + .cargo_toml("js-hello-world") + .hello_world_src_lib() + .wasm_pack() + .arg("--log-level") + .arg("error") + .arg("build") + .assert() + .success() + .stdout("") + .stderr( + matches_cargo() + .and(matches_warn().not()) + .and(matches_info().not()), + ); +} diff --git a/tests/all/main.rs b/tests/all/main.rs index 5abc58d..30ce2f9 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -16,6 +16,7 @@ mod download; mod generate; mod license; mod lockfile; +mod log_level; mod manifest; mod readme; mod test;