Skip to content

Commit

Permalink
Merge pull request #534 from rustwasm/fitzgen-use-assert-cmd-everywhere
Browse files Browse the repository at this point in the history
rebase + cargo fmt Fitzgen use assert cmd everywhere
  • Loading branch information
ashleygwilliams authored Jan 29, 2019
2 parents 741bb01 + b0f47b9 commit dc97112
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 265 deletions.
2 changes: 1 addition & 1 deletion src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl CrateData {
pub fn warn_for_unused_keys(manifest_and_keys: &ManifestAndUnsedKeys) {
manifest_and_keys.unused_keys.iter().for_each(|path| {
PBAR.warn(&format!(
"\"{}\" is a unknown key and will be ignored. Please check your Cargo.toml.",
"\"{}\" is an unknown key and will be ignored. Please check your Cargo.toml.",
path
));
});
Expand Down
123 changes: 46 additions & 77 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
use assert_cmd::prelude::*;
use std::fs;
use std::path::Path;
use structopt::StructOpt;
use utils;
use wasm_pack::Cli;

#[test]
fn build_in_non_crate_directory_doesnt_panic() {
let fixture = utils::fixture::not_a_crate();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
let result = fixture.run(cli.cmd);
assert!(
result.is_err(),
"running wasm-pack in a non-crate directory should fail, but it should not panic"
);
let err = result.unwrap_err();
assert!(err
.iter_chain()
.any(|e| e.to_string().contains("missing a `Cargo.toml`")));
fixture
.wasm_pack()
.arg("build")
.assert()
.failure()
.stderr(predicates::str::contains("missing a `Cargo.toml`"));
}

#[test]
fn it_should_build_js_hello_world_example() {
let fixture = utils::fixture::js_hello_world();
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
fixture.wasm_pack().arg("build").assert().success();
}

#[test]
Expand Down Expand Up @@ -75,15 +59,14 @@ fn it_should_build_crates_in_a_workspace() {
#[wasm_bindgen]
pub fn hello() -> u32 { 42 }
"#,
);
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.join("blah").display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
)
.install_local_wasm_bindgen();
fixture
.wasm_pack()
.current_dir(&fixture.path.join("blah"))
.arg("build")
.assert()
.success();
}

#[test]
Expand Down Expand Up @@ -116,28 +99,21 @@ fn renamed_crate_name_works() {
#[wasm_bindgen]
pub fn one() -> u32 { 1 }
"#,
);
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
)
.install_local_wasm_bindgen();
fixture.wasm_pack().arg("build").assert().success();
}

#[test]
fn it_should_build_nested_project_with_transitive_dependencies() {
let fixture = utils::fixture::transitive_dependencies();
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.join("main").display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
fixture
.wasm_pack()
.current_dir(fixture.path.join("main"))
.arg("build")
.assert()
.success();
}

#[test]
Expand All @@ -149,14 +125,12 @@ fn build_different_profiles() {
.iter()
.cloned()
{
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
profile,
&fixture.path.display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
fixture
.wasm_pack()
.arg("build")
.arg(profile)
.assert()
.success();
}
}

Expand Down Expand Up @@ -208,17 +182,15 @@ fn build_with_and_without_wasm_bindgen_debug() {
pub fn take(self) {}
}
"#,
);

let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
"--dev",
&fixture.path.display().to_string(),
])
.unwrap();
)
.install_local_wasm_bindgen();

fixture.run(cli.cmd).unwrap();
fixture
.wasm_pack()
.arg("build")
.arg("--dev")
.assert()
.success();

let contents = fs::read_to_string(fixture.path.join("pkg/whatever.js")).unwrap();
assert_eq!(
Expand All @@ -233,14 +205,11 @@ fn build_with_and_without_wasm_bindgen_debug() {
fn build_with_arbitrary_cargo_options() {
let fixture = utils::fixture::js_hello_world();
fixture.install_local_wasm_bindgen();

let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.display().to_string(),
"--",
"--no-default-features",
])
.unwrap();
fixture.run(cli.cmd).unwrap();
fixture
.wasm_pack()
.arg("build")
.arg("--")
.arg("--no-default-features")
.assert()
.success();
}
51 changes: 22 additions & 29 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use assert_cmd::prelude::*;
use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;

use structopt::StructOpt;

use utils::{self, fixture};
use wasm_pack::{self, license, manifest, readme, Cli};
use wasm_pack::{self, license, manifest, readme};

#[test]
fn it_gets_the_crate_name_default_path() {
Expand Down Expand Up @@ -370,22 +368,15 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() {
debug-js-glue = "not a boolean"
"#,
);

let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
"--dev",
&fixture.path.display().to_string(),
])
.unwrap();

let result = fixture.run(cli.cmd);
assert!(result.is_err());

let err = result.unwrap_err();
assert!(err.iter_chain().any(|c| c
.to_string()
.contains("package.metadata.wasm-pack.profile.dev.wasm-bindgen.debug")));
fixture
.wasm_pack()
.arg("build")
.arg("--dev")
.assert()
.failure()
.stderr(predicates::str::contains(
"package.metadata.wasm-pack.profile.dev.wasm-bindgen.debug",
));
}

#[test]
Expand Down Expand Up @@ -415,15 +406,17 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() {
debug-js-glue = true
"#,
)
.hello_world_src_lib();

let result = manifest::CrateData::parse_crate_data(&fixture.path.join("Cargo.toml"));

assert!(result.is_ok());

let manifest::ManifestAndUnsedKeys { unused_keys, .. } = result.unwrap();

assert!(unused_keys.contains("package.metadata.wasm-pack.profile.production"));
.hello_world_src_lib()
.install_local_wasm_bindgen();
fixture
.wasm_pack()
.arg("build")
.assert()
.success()
.stdout(predicates::str::contains(
"[WARN]: \"package.metadata.wasm-pack.profile.production\" is an unknown key and will \
be ignored. Please check your Cargo.toml.",
));
}

#[test]
Expand Down
Loading

0 comments on commit dc97112

Please sign in to comment.