Skip to content

Commit

Permalink
test(generate): it works
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed May 16, 2019
1 parent fb9a671 commit ee2be85
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
14 changes: 8 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ walkdir = "2"
chrono = "0.4.6"

[dev-dependencies]
assert_cmd = "0.10.2"
assert_cmd = "0.11"
lazy_static = "1.1.0"
predicates = "1.0.0"
tempfile = "3"
Expand Down
16 changes: 4 additions & 12 deletions tests/all/generate.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
use assert_cmd::prelude::*;
use std::str;
use utils;

#[test]
fn new_with_no_name_errors() {
let fixture = utils::fixture::not_a_crate();
fixture.install_local_cargo_generate();
fixture.wasm_pack().arg("new").assert().failure();
}

#[test]
fn new_with_provided_name() {
fn new_with_name_succeeds() {
let fixture = utils::fixture::not_a_crate();
let cmd = fixture
.wasm_pack()
.arg("new")
.arg("--name")
.arg("ferris")
.assert();

let output = cmd.get_output();

assert!(str::from_utf8(&output.stdout).unwrap().contains("ferris"));
fixture.install_local_cargo_generate();
fixture.wasm_pack().arg("new").arg("hello").assert().success();
}
29 changes: 28 additions & 1 deletion tests/all/utils/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,32 @@ impl Fixture {
download().unwrap().binary("wasm-bindgen").unwrap()
}

/// Install a local cargo-generate for this fixture.
///
/// Takes care not to re-install for every fixture, but only the one time
/// for the whole test suite.
pub fn install_local_cargo_generate(&self) -> PathBuf {
static INSTALL_CARGO_GENERATE: Once = ONCE_INIT;
let cache = self.cache();

let download = || {
if let Ok(download) =
install::download_prebuilt(&Tool::CargoGenerate, &cache, "latest", true)
{
return Ok(download);
}

install::cargo_install(Tool::CargoGenerate, &cache, "latest", true)
};

// Only one thread can perform the actual download, and then afterwards
// everything will hit the cache so we can run the same path.
INSTALL_CARGO_GENERATE.call_once(|| {
download().unwrap();
});
download().unwrap().binary("cargo-generate").unwrap()
}

/// Download `geckodriver` and return its path.
///
/// Takes care to ensure that only one `geckodriver` is downloaded for the whole
Expand Down Expand Up @@ -298,7 +324,8 @@ impl Fixture {
/// directory and using the test cache.
pub fn wasm_pack(&self) -> Command {
use assert_cmd::prelude::*;
let mut cmd = Command::main_binary().unwrap();
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))
.unwrap();
cmd.current_dir(&self.path);
cmd.env("WASM_PACK_CACHE", self.cache_dir());
cmd
Expand Down

0 comments on commit ee2be85

Please sign in to comment.