Skip to content

Commit

Permalink
Merge pull request #521 from fitzgen/cargo-test-double-print
Browse files Browse the repository at this point in the history
Only print `cargo test` output the once
  • Loading branch information
fitzgen authored Jan 23, 2019
2 parents 0939c12 + f5f9d40 commit bedbf3d
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 19 deletions.
89 changes: 89 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ binary-install = { version = "0.0.1", path = "./binary-install" }
walkdir = "2"

[dev-dependencies]
assert_cmd = "0.10.2"
predicates = "1.0.0"
tempfile = "3"

[features]
Expand Down
14 changes: 14 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Getting and configuring wasm-pack's binary cache.

use binary_install::Cache;
use std::env;
use std::path::Path;

/// Get wasm-pack's binary cache.
pub fn get_wasm_pack_cache() -> Result<Cache, failure::Error> {
if let Ok(path) = env::var("WASM_PACK_CACHE") {
Ok(Cache::at(Path::new(&path)))
} else {
Cache::new("wasm-pack")
}
}
3 changes: 2 additions & 1 deletion src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use binary_install::{Cache, Download};
use bindgen;
use build;
use cache;
use command::utils::{create_pkg_dir, set_crate_path};
use emoji;
use failure::Error;
Expand Down Expand Up @@ -180,7 +181,7 @@ impl Build {
mode: build_opts.mode,
out_dir,
bindgen: None,
cache: Cache::new("wasm_pack")?,
cache: cache::get_wasm_pack_cache()?,
extra_options: build_opts.extra_options,
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/command/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::build::BuildMode;
use binary_install::Cache;
use bindgen;
use build;
use cache;
use command::utils::set_crate_path;
use console::style;
use emoji;
Expand Down Expand Up @@ -132,7 +133,7 @@ impl Test {
}

Ok(Test {
cache: Cache::new("wasm_pack")?,
cache: cache::get_wasm_pack_cache()?,
crate_path,
crate_data,
node,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern crate walkdir;

pub mod bindgen;
pub mod build;
pub mod cache;
pub mod child;
pub mod command;
pub mod emoji;
Expand Down
7 changes: 7 additions & 0 deletions src/progressbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ impl ProgressOutput {

let mut spinner = self.spinner.write();
*spinner = Self::progressbar(message);

if !atty::is(atty::Stream::Stderr) {
// `indicatif` won't print any output if `stderr` is not a tty, so
// to ensure that our output is still emitted, we print it manually
// here.
eprintln!("{}", message)
}
}

fn add_message(&self, msg: &str) {
Expand Down
24 changes: 9 additions & 15 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod webdriver;

use child;
use failure::{self, ResultExt};
use log::info;
use std::ffi::OsStr;
use std::path::Path;
use std::process::Command;
Expand All @@ -17,20 +16,15 @@ where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
let output = {
let mut cmd = Command::new("cargo");
cmd.envs(envs);
cmd.current_dir(path).arg("test");
if release {
cmd.arg("--release");
}
cmd.arg("--target").arg("wasm32-unknown-unknown");
child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?
};

for line in output.lines() {
info!("test output: {}", line);
println!("{}", line);
let mut cmd = Command::new("cargo");
cmd.envs(envs);
cmd.current_dir(path).arg("test");
if release {
cmd.arg("--release");
}
cmd.arg("--target").arg("wasm32-unknown-unknown");
child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?;

// NB: `child::run` took care of ensuring that test output gets printed.
Ok(())
}
2 changes: 2 additions & 0 deletions tests/all/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extern crate assert_cmd;
extern crate failure;
extern crate predicates;
#[macro_use]
extern crate lazy_static;
#[macro_use]
Expand Down
42 changes: 42 additions & 0 deletions tests/all/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use assert_cmd::prelude::*;
use failure::Error;
use predicates::prelude::*;
use std::env;
use utils::fixture;
use wasm_pack::command::{build, test, Command};
Expand Down Expand Up @@ -334,3 +336,43 @@ fn cdylib_not_required() {
});
fixture.run(cmd).unwrap();
}

#[test]
fn test_output_is_printed_once() {
let fixture = fixture::Fixture::new();
fixture
.readme()
.cargo_toml("wbg-test-node")
.hello_world_src_lib()
.file(
"tests/node.rs",
r#"
extern crate wasm_bindgen;
extern crate wasm_bindgen_test;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen_test]
fn pass() {
log("YABBA DABBA DOO");
assert_eq!(1, 2);
}
"#,
);

fixture
.wasm_pack()
.arg("test")
.arg("--node")
.assert()
.stderr(predicate::function(|err: &str| {
err.matches("YABBA DABBA DOO").count() == 1
}))
.failure();
}
Loading

0 comments on commit bedbf3d

Please sign in to comment.