Skip to content

Commit

Permalink
tests/integration/cli: fix tests failing
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Aug 21, 2022
1 parent 306347e commit 8844994
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ test-examples:
$(CARGO_BINARY) test $(CARGO_TARGET) --release $(compiler_features) --features wasi --examples

test-integration:
$(CARGO_BINARY) test $(CARGO_TARGET) --no-fail-fast -p wasmer-integration-tests-cli
$(CARGO_BINARY) test $(CARGO_TARGET) --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture

test-integration-ios:
$(CARGO_BINARY) test $(CARGO_TARGET) -p wasmer-integration-tests-ios
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
println!(
"cargo:rustc-env=TARGET={}",
"cargo:rustc-env=CARGO_BUILD_TARGET={}",
std::env::var("TARGET").unwrap()
);
}
68 changes: 22 additions & 46 deletions tests/integration/cli/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,49 @@ use std::path::PathBuf;

pub const C_ASSET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../lib/c-api/examples/assets"
"/../../../lib/c-api/examples/assets/"
);
pub const ASSET_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../tests/examples");
pub const ASSET_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../tests/examples/");

pub const WASMER_INCLUDE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../lib/c-api");
pub const WASMER_INCLUDE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../lib/c-api/");

#[cfg(feature = "debug")]
pub const WASMER_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/debug/wasmer");

#[cfg(not(feature = "debug"))]
pub const WASMER_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/release/wasmer"
);

pub const WASMER_TARGET_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/debug/");
#[cfg(feature = "debug")]
pub const WASMER_TARGET_PATH: &str = concat!(
pub const WASMER_TARGET_PATH_2: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../",
env!("CARGO_CFG_TARGET"),
"/debug/wasmer"
"/../../../target/",
env!("CARGO_BUILD_TARGET"),
"/debug/"
);

/* env var TARGET is set by tests/integration/cli/build.rs on compile-time */

#[cfg(not(feature = "debug"))]
pub const WASMER_TARGET_PATH: &str = concat!(
pub const WASMER_TARGET_PATH: &str =
concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/release/");
#[cfg(not(feature = "debug"))]
pub const WASMER_TARGET_PATH2: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/",
env!("TARGET"),
"/release/wasmer"
env!("CARGO_BUILD_TARGET"),
"/release/"
);

#[cfg(not(windows))]
pub const LIBWASMER_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/release/libwasmer.a"
);
pub const LIBWASMER_FILENAME: &str = "libwasmer.a";

#[cfg(windows)]
pub const LIBWASMER_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/release/wasmer.lib"
);

#[cfg(not(windows))]
pub const LIBWASMER_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target",
env!("TARGET"),
"/release/libwasmer.a"
);

#[cfg(windows)]
pub const LIBWASMER_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../",
env!("TARGET"),
"/release/wasmer.lib"
);
pub const LIBWASMER_PATH: &str = "wasmer.lib";

/// Get the path to the `libwasmer.a` static library.
pub fn get_libwasmer_path() -> PathBuf {
let mut ret = PathBuf::from(
env::var("WASMER_TEST_LIBWASMER_PATH").unwrap_or_else(|_| LIBWASMER_PATH.to_string()),
env::var("WASMER_TEST_LIBWASMER_PATH")
.unwrap_or_else(|_| format!("{}{}", WASMER_TARGET_PATH, LIBWASMER_FILENAME)),
);
if !ret.exists() {
ret = PathBuf::from(LIBWASMER_TARGET_PATH.to_string());
ret = PathBuf::from(format!("{}{}", WASMER_TARGET_PATH2, LIBWASMER_FILENAME));
}
if !ret.exists() {
panic!("Could not find libwasmer path! {:?}", ret);
Expand All @@ -81,10 +56,11 @@ pub fn get_libwasmer_path() -> PathBuf {
/// Get the path to the `wasmer` executable to be used in this test.
pub fn get_wasmer_path() -> PathBuf {
let mut ret = PathBuf::from(
env::var("WASMER_TEST_WASMER_PATH").unwrap_or_else(|_| WASMER_PATH.to_string()),
env::var("WASMER_TEST_WASMER_PATH")
.unwrap_or_else(|_| format!("{}wasmer", WASMER_TARGET_PATH)),
);
if !ret.exists() {
ret = PathBuf::from(WASMER_TARGET_PATH.to_string());
ret = PathBuf::from(format!("{}wasmer", WASMER_TARGET_PATH2));
}
if !ret.exists() {
panic!("Could not find wasmer executable path! {:?}", ret);
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use anyhow::bail;
use std::process::Command;
use wasmer_integration_tests_cli::{ASSET_PATH, C_ASSET_PATH, WASMER_PATH};
use wasmer_integration_tests_cli::{get_wasmer_path, ASSET_PATH, C_ASSET_PATH};

fn wasi_test_wasm_path() -> String {
format!("{}/{}", C_ASSET_PATH, "qjs.wasm")
Expand All @@ -18,7 +18,7 @@ fn test_no_start_wat_path() -> String {

#[test]
fn run_wasi_works() -> anyhow::Result<()> {
let output = Command::new(WASMER_PATH)
let output = Command::new(get_wasmer_path())
.arg("run")
.arg(wasi_test_wasm_path())
.arg("--")
Expand All @@ -44,7 +44,7 @@ fn run_wasi_works() -> anyhow::Result<()> {

#[test]
fn run_no_imports_wasm_works() -> anyhow::Result<()> {
let output = Command::new(WASMER_PATH)
let output = Command::new(get_wasmer_path())
.arg("run")
.arg(test_no_imports_wat_path())
.output()?;
Expand Down Expand Up @@ -82,7 +82,7 @@ fn run_invoke_works_with_nomain_wasi() -> anyhow::Result<()> {
let random = rand::random::<u64>();
let module_file = std::env::temp_dir().join(&format!("{random}.wat"));
std::fs::write(&module_file, wasi_wat.as_bytes()).unwrap();
let output = Command::new(WASMER_PATH)
let output = Command::new(get_wasmer_path())
.arg("run")
.arg(&module_file)
.output()?;
Expand All @@ -94,7 +94,7 @@ fn run_invoke_works_with_nomain_wasi() -> anyhow::Result<()> {
panic!();
}

let output = Command::new(WASMER_PATH)
let output = Command::new(get_wasmer_path())
.arg("run")
.arg("--invoke")
.arg("_start")
Expand All @@ -114,7 +114,7 @@ fn run_invoke_works_with_nomain_wasi() -> anyhow::Result<()> {

#[test]
fn run_no_start_wasm_report_error() -> anyhow::Result<()> {
let output = Command::new(WASMER_PATH)
let output = Command::new(get_wasmer_path())
.arg("run")
.arg(test_no_start_wat_path())
.output()?;
Expand Down
12 changes: 7 additions & 5 deletions tests/integration/cli/tests/version.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use anyhow::bail;
use std::process::Command;
use wasmer_integration_tests_cli::WASMER_PATH;
use wasmer_integration_tests_cli::get_wasmer_path;

const WASMER_VERSION: &str = env!("CARGO_PKG_VERSION");

#[test]
fn version_string_is_correct() -> anyhow::Result<()> {
let expected_version_output = format!("wasmer {}\n", WASMER_VERSION);
let wasmer_path = get_wasmer_path();

let outputs = [
Command::new(WASMER_PATH).arg("--version").output()?,
Command::new(WASMER_PATH).arg("-V").output()?,
Command::new(&wasmer_path).arg("--version").output()?,
Command::new(&wasmer_path).arg("-V").output()?,
];

for output in &outputs {
Expand All @@ -34,10 +35,11 @@ fn version_string_is_correct() -> anyhow::Result<()> {
#[test]
fn help_text_contains_version() -> anyhow::Result<()> {
let expected_version_output = format!("wasmer {}", WASMER_VERSION);
let wasmer_path = get_wasmer_path();

let outputs = [
Command::new(WASMER_PATH).arg("--help").output()?,
Command::new(WASMER_PATH).arg("-h").output()?,
Command::new(&wasmer_path).arg("--help").output()?,
Command::new(&wasmer_path).arg("-h").output()?,
];

for output in &outputs {
Expand Down

0 comments on commit 8844994

Please sign in to comment.