From 5d1d4f3116b21dc3abfedd7fd1a4f4e9ea8eccad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 17:09:53 +0100 Subject: [PATCH 01/29] Fix #3366 - file paths could get interpreted as URLs in wasmer run --- lib/cli/src/commands/run.rs | 38 ++++++++++++++++++++--------- lib/registry/src/lib.rs | 3 ++- tests/integration/cli/tests/run.rs | 39 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 52c597287ea..c3de8add84b 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -828,11 +828,6 @@ pub(crate) fn try_run_package_or_file( ) -> Result<(), anyhow::Error> { let debug_msgs_allowed = isatty::stdout_isatty(); - if let Ok(url) = url::Url::parse(&format!("{}", r.path.display())) { - let result = try_run_url(&url, args, r, debug); - return result; - } - // Check "r.path" is a file or a package / command name if r.path.exists() { if r.path.is_dir() && r.path.join("wapm.toml").exists() { @@ -848,6 +843,18 @@ pub(crate) fn try_run_package_or_file( return r.execute(); } + // c:// might be parsed as a URL on Windows + let url_string = format!("{}", r.path.display()); + if url_string.starts_with("http") { + if let Ok(url) = url::Url::parse(&url_string) { + match try_run_url(&url, args, r, debug) { + Err(ExecuteLocalPackageError::BeforeExec(_)) => {} + Err(ExecuteLocalPackageError::DuringExec(e)) => return Err(e), + Ok(o) => return Ok(o), + } + } + } + let package = format!("{}", r.path.display()); let mut is_fake_sv = false; @@ -915,9 +922,15 @@ pub(crate) fn try_run_package_or_file( try_autoinstall_package(args, &sv, package_download_info, r.force_install) } -fn try_run_url(url: &Url, _args: &[String], r: &Run, _debug: bool) -> Result<(), anyhow::Error> { - let checksum = wasmer_registry::get_remote_webc_checksum(url) - .map_err(|e| anyhow::anyhow!("error fetching {url}: {e}"))?; +fn try_run_url( + url: &Url, + _args: &[String], + r: &Run, + _debug: bool, +) -> Result<(), ExecuteLocalPackageError> { + let checksum = wasmer_registry::get_remote_webc_checksum(url).map_err(|e| { + ExecuteLocalPackageError::BeforeExec(anyhow::anyhow!("error fetching {url}: {e}")) + })?; let packages = wasmer_registry::get_all_installed_webc_packages(); @@ -926,7 +939,9 @@ fn try_run_url(url: &Url, _args: &[String], r: &Run, _debug: bool) -> Result<(), let result = wasmer_registry::install_webc_package(url, &checksum); - result.map_err(|e| anyhow::anyhow!("error fetching {url}: {e}"))?; + result.map_err(|e| { + ExecuteLocalPackageError::BeforeExec(anyhow::anyhow!("error fetching {url}: {e}")) + })?; if let Some(sp) = sp { sp.close(); @@ -936,10 +951,11 @@ fn try_run_url(url: &Url, _args: &[String], r: &Run, _debug: bool) -> Result<(), let webc_dir = wasmer_registry::get_webc_dir(); let webc_install_path = webc_dir - .context("Error installing package: no webc dir")? + .context("Error installing package: no webc dir") + .map_err(ExecuteLocalPackageError::BeforeExec)? .join(checksum); let mut r = r.clone(); r.path = webc_install_path; - r.execute() + r.execute().map_err(ExecuteLocalPackageError::DuringExec) } diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index 4da04f8f851..f08ed15cc6a 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -1136,7 +1136,8 @@ pub fn get_checksum_hash(bytes: &[u8]) -> String { /// file is already installed before downloading it pub fn get_remote_webc_checksum(url: &Url) -> Result { let request_max_bytes = webc::WebC::get_signature_offset_start() + 4 + 1024 + 8 + 8; - let data = get_webc_bytes(url, Some(0..request_max_bytes)).context("get_webc_bytes failed")?; + let data = get_webc_bytes(url, Some(0..request_max_bytes)) + .context("get_webc_bytes failed on {url}")?; let checksum = webc::WebC::get_checksum_bytes(&data) .map_err(|e| anyhow::anyhow!("{e}")) .context("get_checksum_bytes failed")? diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 2de8a173956..eae2422cd25 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -546,3 +546,42 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { assert_eq!(result.contains("Can not find any export functions."), true); Ok(()) } + + +// Test that changes to wapm run don't break wasmer run +#[test] +fn test_wapm_run_works() -> anyhow::Result<()> { + let output = Command::new("wapm") + .arg("install") + .arg("cowsay") + .output()?; + + if !output.status.success() { + bail!( + "wapm install cowsay failed with: stdout: {}\n\nstderr: {}", + std::str::from_utf8(&output.stdout) + .expect("stdout is not utf8! need to handle arbitrary bytes"), + std::str::from_utf8(&output.stderr) + .expect("stderr is not utf8! need to handle arbitrary bytes") + ); + } + + let output = Command::new("wapm") + .arg("run") + .arg("cowsay") + .arg("hello") + .env("WAPM_RUNTIME".to_string(), format!("{}", get_wasmer_path().display())) + .output()?; + + if !output.status.success() { + bail!( + "wapm install cowsay failed with: stdout: {}\n\nstderr: {}", + std::str::from_utf8(&output.stdout) + .expect("stdout is not utf8! need to handle arbitrary bytes"), + std::str::from_utf8(&output.stderr) + .expect("stderr is not utf8! need to handle arbitrary bytes") + ); + } + + Ok(()) +} From 351b0a6e4ced11ea90131c0d0f76f051b2ec43a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 17:25:43 +0100 Subject: [PATCH 02/29] Add integration test, use different spinner library to fix #3346 --- Cargo.lock | 76 ++++++++++++++++-------------- lib/cli/Cargo.toml | 5 +- lib/cli/src/commands/run.rs | 31 ++++++------ lib/registry/src/lib.rs | 2 +- tests/integration/cli/tests/run.rs | 11 ++--- 5 files changed, 66 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc962bfc7cb..d56101e4d82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,12 +46,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30275ad0ad84ec1c06dde3b3f7d23c6006b7d76d61a85e7060b426b747eff70d" - [[package]] name = "any_ascii" version = "0.1.7" @@ -878,16 +872,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "dirs" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" -dependencies = [ - "cfg-if 0.1.10", - "dirs-sys", -] - [[package]] name = "dirs" version = "4.0.0" @@ -1879,6 +1863,12 @@ dependencies = [ "syn", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matchers" version = "0.1.0" @@ -2309,7 +2299,7 @@ dependencies = [ "csv", "encode_unicode 1.0.0", "lazy_static", - "term 0.7.0", + "term", "unicode-width", ] @@ -3098,13 +3088,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] -name = "spinner" -version = "0.5.0" +name = "spinoff" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3a7cd01625b7e43e62815677d692cb59b221c2fdc2853d1eb86a260ee0c272" +checksum = "812db6f40551bdcdb10e1d2070ec33f69805d2bfb7e59426c7d14e7e1b4194dd" dependencies = [ - "ansi_term", - "term 0.6.1", + "colored 2.0.0", + "maplit", + "once_cell", + "strum", ] [[package]] @@ -3177,6 +3169,28 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.0", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "subtle" version = "2.4.1" @@ -3241,16 +3255,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "term" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" -dependencies = [ - "dirs 2.0.2", - "winapi", -] - [[package]] name = "term" version = "0.7.0" @@ -3316,7 +3320,7 @@ dependencies = [ "getopts", "libc", "num_cpus", - "term 0.7.0", + "term", ] [[package]] @@ -4019,7 +4023,7 @@ dependencies = [ "clap 3.2.23", "colored 2.0.0", "dialoguer", - "dirs 4.0.0", + "dirs", "distance", "fern", "http_req", @@ -4032,7 +4036,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "spinner", + "spinoff", "target-lexicon 0.12.5", "tempdir", "tempfile", @@ -4260,7 +4264,7 @@ name = "wasmer-registry" version = "3.0.1" dependencies = [ "anyhow", - "dirs 4.0.0", + "dirs", "flate2", "futures-util", "graphql_client", diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 40d5e2f8efa..a137bd37b0b 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -43,7 +43,7 @@ wasmer-vfs = { version = "=3.0.1", path = "../vfs", default-features = false, f atty = "0.2" colored = "2.0" anyhow = "1.0" -spinner = "0.5.0" +spinoff = "0.5.4" clap = { version = "3.2.22", features = ["derive", "env"] } # For the function names autosuggestion distance = "0.4" @@ -166,6 +166,9 @@ http = [ "serde", ] +[target.'cfg(target_os = "windows")'.dependencies] +colored = "2.0.0" + [package.metadata.binstall] pkg-fmt = "tgz" diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index c3de8add84b..cc854f08633 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -645,17 +645,20 @@ impl Run { } } -fn start_spinner(msg: String) -> Option { +fn start_spinner(msg: String) -> Option { if !isatty::stdout_isatty() { return None; } - Some( - spinner::SpinnerBuilder::new(msg) - .spinner(vec![ - "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷", " ", "⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈", - ]) - .start(), - ) + #[cfg(target_os = "windows")] + { + use colored::control; + let _ = control::enable_virtual_terminal(true); + } + Some(spinoff::Spinner::new( + spinoff::Spinners::Dots, + msg, + spinoff::Color::White, + )) } /// Before looking up a command from the registry, try to see if we have @@ -706,8 +709,7 @@ pub(crate) fn try_autoinstall_package( force_install, ); if let Some(sp) = sp.take() { - sp.close(); - print!("\r"); + sp.clear(); } let _ = std::io::stdout().flush(); let (_, package_dir) = match result { @@ -765,8 +767,8 @@ fn try_lookup_command(sv: &mut SplitVersion) -> Result Result anyhow::Result<()> { Ok(()) } - // Test that changes to wapm run don't break wasmer run #[test] fn test_wapm_run_works() -> anyhow::Result<()> { - let output = Command::new("wapm") - .arg("install") - .arg("cowsay") - .output()?; + let output = Command::new("wapm").arg("install").arg("cowsay").output()?; if !output.status.success() { bail!( @@ -570,7 +566,10 @@ fn test_wapm_run_works() -> anyhow::Result<()> { .arg("run") .arg("cowsay") .arg("hello") - .env("WAPM_RUNTIME".to_string(), format!("{}", get_wasmer_path().display())) + .env( + "WAPM_RUNTIME".to_string(), + format!("{}", get_wasmer_path().display()), + ) .output()?; if !output.status.success() { From 3e4a08f1e8da81d7e09179c42c8181fa7eee46e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= <12084016+fschutt@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:32:01 +0100 Subject: [PATCH 03/29] Use with_context with proper formatting Co-authored-by: Michael Bryan --- lib/registry/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index b256a72f32c..5d27986710f 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -1137,7 +1137,7 @@ pub fn get_checksum_hash(bytes: &[u8]) -> String { pub fn get_remote_webc_checksum(url: &Url) -> Result { let request_max_bytes = webc::WebC::get_signature_offset_start() + 4 + 1024 + 8 + 8; let data = get_webc_bytes(url, Some(0..request_max_bytes)) - .context("get_webc_bytes failed on {url}")?; + .with_context(|| format!("get_webc_bytes failed on {url}"))?; let checksum = webc::WebC::get_checksum_bytes(&data) .map_err(|e| anyhow::anyhow!("{e}")) .context("get_checksum_bytes failed")? From 8674d8ceea8a8680c824cb69b7c0450cd0d5fded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 19:34:24 +0100 Subject: [PATCH 04/29] Adress review comments and fix test --- lib/cli/src/commands/run.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index cc854f08633..994ac02ecb2 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -652,7 +652,7 @@ fn start_spinner(msg: String) -> Option { #[cfg(target_os = "windows")] { use colored::control; - let _ = control::enable_virtual_terminal(true); + let _ = control::set_virtual_terminal(true); } Some(spinoff::Spinner::new( spinoff::Spinners::Dots, @@ -846,8 +846,8 @@ pub(crate) fn try_run_package_or_file( // c:// might be parsed as a URL on Windows let url_string = format!("{}", r.path.display()); - if url_string.starts_with("http") { - if let Ok(url) = url::Url::parse(&url_string) { + if let Ok(url) = url::Url::parse(&url_string) { + if url.scheme() == "http" || url.scheme() == "https" { match try_run_url(&url, args, r, debug) { Err(ExecuteLocalPackageError::BeforeExec(_)) => {} Err(ExecuteLocalPackageError::DuringExec(e)) => return Err(e), From 4ec584c0b84d4a0420ab8e4504e04e3ec486f10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 19:39:49 +0100 Subject: [PATCH 05/29] Install cowsay properly --- tests/integration/cli/tests/run.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 64bfcac9e93..4da2a69bbc2 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -550,7 +550,13 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { // Test that changes to wapm run don't break wasmer run #[test] fn test_wapm_run_works() -> anyhow::Result<()> { - let output = Command::new("wapm").arg("install").arg("cowsay").output()?; + let temp_dir = tempfile::tempdir()?; + let path = temp_dir.path(); + let output = Command::new("wapm") + .arg("install") + .arg("cowsay") + .current_dir(&path) + .output()?; if !output.status.success() { bail!( @@ -566,6 +572,7 @@ fn test_wapm_run_works() -> anyhow::Result<()> { .arg("run") .arg("cowsay") .arg("hello") + .current_dir(&path) .env( "WAPM_RUNTIME".to_string(), format!("{}", get_wasmer_path().display()), From 2145c2d8f7c418509eafb18d8216818ec595a4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 19:42:03 +0100 Subject: [PATCH 06/29] Disable test from running locally --- tests/integration/cli/tests/run.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 4da2a69bbc2..414745924f8 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -550,6 +550,11 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { // Test that changes to wapm run don't break wasmer run #[test] fn test_wapm_run_works() -> anyhow::Result<()> { + // only run this test on the CI, not locally + if std::env::var("GITHUB_TOKEN").is_err() { + return Ok(()); + } + let temp_dir = tempfile::tempdir()?; let path = temp_dir.path(); let output = Command::new("wapm") From cded3ac210904ff1d3baefec5645f673c8a0ca2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 20:29:43 +0100 Subject: [PATCH 07/29] Install wapm before running integration tests --- .github/workflows/test-sys.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 9007ee55cc3..390c31a890a 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -206,7 +206,7 @@ jobs: if: matrix.run_test && matrix.os != 'windows-2019' shell: bash run: | - make build-wasmer && make build-capi && make package-capi && make package && export WASMER_DIR=`pwd`/package && make test-integration-cli + curl https://get.wasmer.io -sSfL | sh && make build-wasmer && make build-capi && make package-capi && make package && export WASMER_DIR=`pwd`/package && make test-integration-cli env: TARGET: ${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }}/release From 75aeeda6dca1687e3af9c2d56d59b124baada288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 20:52:19 +0100 Subject: [PATCH 08/29] Install wapm via cargo if not available (Windows) --- tests/integration/cli/tests/run.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 414745924f8..42cb2606957 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -555,6 +555,31 @@ fn test_wapm_run_works() -> anyhow::Result<()> { return Ok(()); } + if Command::new("wapm").arg("--version").output().is_err() + || !Command::new("wapm") + .arg("--version") + .output() + .unwrap() + .status + .success() + { + let _ = Command::new("cargo") + .arg("install") + .arg("wapm-cli") + .output(); + } + + if Command::new("wapm").arg("--version").output().is_err() + || !Command::new("wapm") + .arg("--version") + .output() + .unwrap() + .status + .success() + { + println!("warning: wapm is not installed even after running cargo install wapm-cli"); + } + let temp_dir = tempfile::tempdir()?; let path = temp_dir.path(); let output = Command::new("wapm") From b5c495213eac3f9fecc351a4091c9eb82e500776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 21:10:41 +0100 Subject: [PATCH 09/29] Remove dependency on wapm --- .github/workflows/test-sys.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 390c31a890a..9007ee55cc3 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -206,7 +206,7 @@ jobs: if: matrix.run_test && matrix.os != 'windows-2019' shell: bash run: | - curl https://get.wasmer.io -sSfL | sh && make build-wasmer && make build-capi && make package-capi && make package && export WASMER_DIR=`pwd`/package && make test-integration-cli + make build-wasmer && make build-capi && make package-capi && make package && export WASMER_DIR=`pwd`/package && make test-integration-cli env: TARGET: ${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }}/release From 3d4c34bae0a77bd6db77ba5385734f7c8b54d424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 21:22:09 +0100 Subject: [PATCH 10/29] Undo installing wapm automatically --- tests/integration/cli/tests/run.rs | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 42cb2606957..169f1042783 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -549,37 +549,12 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { // Test that changes to wapm run don't break wasmer run #[test] -fn test_wapm_run_works() -> anyhow::Result<()> { +fn test_wasmer_run_complex_url() -> anyhow::Result<()> { // only run this test on the CI, not locally if std::env::var("GITHUB_TOKEN").is_err() { return Ok(()); } - if Command::new("wapm").arg("--version").output().is_err() - || !Command::new("wapm") - .arg("--version") - .output() - .unwrap() - .status - .success() - { - let _ = Command::new("cargo") - .arg("install") - .arg("wapm-cli") - .output(); - } - - if Command::new("wapm").arg("--version").output().is_err() - || !Command::new("wapm") - .arg("--version") - .output() - .unwrap() - .status - .success() - { - println!("warning: wapm is not installed even after running cargo install wapm-cli"); - } - let temp_dir = tempfile::tempdir()?; let path = temp_dir.path(); let output = Command::new("wapm") From b5be6791ca0679abd4c9010a9fba7013613a7309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 21:40:00 +0100 Subject: [PATCH 11/29] Remove dependency on wapm in unit tests --- tests/integration/cli/tests/run.rs | 49 +++++++++++++----------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 169f1042783..e67027cd9ee 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -547,41 +547,34 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { Ok(()) } -// Test that changes to wapm run don't break wasmer run +// Test that wasmer can run a complex path #[test] fn test_wasmer_run_complex_url() -> anyhow::Result<()> { - // only run this test on the CI, not locally - if std::env::var("GITHUB_TOKEN").is_err() { - return Ok(()); - } - let temp_dir = tempfile::tempdir()?; - let path = temp_dir.path(); - let output = Command::new("wapm") - .arg("install") - .arg("cowsay") - .current_dir(&path) - .output()?; - - if !output.status.success() { - bail!( - "wapm install cowsay failed with: stdout: {}\n\nstderr: {}", - std::str::from_utf8(&output.stdout) - .expect("stdout is not utf8! need to handle arbitrary bytes"), - std::str::from_utf8(&output.stderr) - .expect("stderr is not utf8! need to handle arbitrary bytes") + let path = temp_dir.path().to_path_buf(); + let root = std::env::home_dir().unwrap_or(path); + #[cfg(target_os = "windows")] + { + // wasmer run used to fail on c:\Users\username\wapm_packages\ ... + let root_str = format!("{}", root.display()); + assert!( + root_str.starts_with("c:\\") || root_str.starts_with("C://"), + "windows path is not complex enough" ); } + std::fs::copy(wasi_test_wasm_path(), root.join("qjs.wasm")).unwrap(); - let output = Command::new("wapm") + println!( + "running wasmer run {} -- -q", + root.join("qjs.wasm").display() + ); + + let output = Command::new("wasmer") .arg("run") - .arg("cowsay") - .arg("hello") - .current_dir(&path) - .env( - "WAPM_RUNTIME".to_string(), - format!("{}", get_wasmer_path().display()), - ) + .arg(root.join("qjs.wasm")) + .arg("--") + .arg("-q") + .current_dir(&root) .output()?; if !output.status.success() { From 6eca5b9c7f9a0b7c7bdf5f4f4acc96cd75024398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 22:01:23 +0100 Subject: [PATCH 12/29] Do not use home_dir --- .gitignore | 1 + tests/integration/cli/tests/run.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24affcea4df..427df446a7c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ api-docs-repo/ /src/windows-installer/WasmerInstaller.exe /lib/c-api/wasmer.h .xwin-cache +/temp-wasmer-run-complex-url # Generated by tests on Android /avd /core diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index e67027cd9ee..b1b597a31ae 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -552,7 +552,7 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { fn test_wasmer_run_complex_url() -> anyhow::Result<()> { let temp_dir = tempfile::tempdir()?; let path = temp_dir.path().to_path_buf(); - let root = std::env::home_dir().unwrap_or(path); + let root = get_repo_root_path().unwrap().join("temp-wasmer-run-complex-url"); #[cfg(target_os = "windows")] { // wasmer run used to fail on c:\Users\username\wapm_packages\ ... From 95d77d5852ea36322ad2d6ccb45debec2d6e89e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 22:04:32 +0100 Subject: [PATCH 13/29] Update wrong error message --- tests/integration/cli/tests/run.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index b1b597a31ae..141c8b18e5c 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -552,7 +552,9 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { fn test_wasmer_run_complex_url() -> anyhow::Result<()> { let temp_dir = tempfile::tempdir()?; let path = temp_dir.path().to_path_buf(); - let root = get_repo_root_path().unwrap().join("temp-wasmer-run-complex-url"); + let root = get_repo_root_path() + .unwrap() + .join("temp-wasmer-run-complex-url"); #[cfg(target_os = "windows")] { // wasmer run used to fail on c:\Users\username\wapm_packages\ ... @@ -569,17 +571,19 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { root.join("qjs.wasm").display() ); - let output = Command::new("wasmer") - .arg("run") - .arg(root.join("qjs.wasm")) - .arg("--") - .arg("-q") - .current_dir(&root) - .output()?; + let mut cmd = Command::new("wasmer"); + cmd.arg("run"); + cmd.arg(root.join("qjs.wasm")); + cmd.arg("--"); + cmd.arg("-q"); + + println!("running command: {cmd:?}"); + + let output = cmd.current_dir(&root).output()?; if !output.status.success() { bail!( - "wapm install cowsay failed with: stdout: {}\n\nstderr: {}", + "wasmer run qjs.wasm failed with: stdout: {}\n\nstderr: {}", std::str::from_utf8(&output.stdout) .expect("stdout is not utf8! need to handle arbitrary bytes"), std::str::from_utf8(&output.stderr) From ddf1903ac3efdd647324545dc5bf3cff11461cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 22:45:49 +0100 Subject: [PATCH 14/29] Fix unit test --- tests/integration/cli/tests/run.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 141c8b18e5c..00c18d42b02 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -564,6 +564,14 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { "windows path is not complex enough" ); } + + println!( + "copying from {} to {}", + wasi_test_wasm_path(), + root.join("qjs.wasm").display() + ); + std::fs::create_dir_all(&root).unwrap(); + println!("copying..."); std::fs::copy(wasi_test_wasm_path(), root.join("qjs.wasm")).unwrap(); println!( From 429229fb880881b89c6198f6f5574896cc25b4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 23:01:05 +0100 Subject: [PATCH 15/29] Remove unnecessary fs::copy --- tests/integration/cli/tests/run.rs | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 00c18d42b02..66da0e21dd5 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -550,44 +550,27 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { // Test that wasmer can run a complex path #[test] fn test_wasmer_run_complex_url() -> anyhow::Result<()> { - let temp_dir = tempfile::tempdir()?; - let path = temp_dir.path().to_path_buf(); - let root = get_repo_root_path() - .unwrap() - .join("temp-wasmer-run-complex-url"); + let wasm_test_path = wasi_test_wasm_path(); #[cfg(target_os = "windows")] { // wasmer run used to fail on c:\Users\username\wapm_packages\ ... - let root_str = format!("{}", root.display()); assert!( - root_str.starts_with("c:\\") || root_str.starts_with("C://"), - "windows path is not complex enough" + wasm_test_path.starts_with("c:\\") || wasm_test_path.starts_with("C://"), + "wasm_test_path path is not complex enough" ); } - println!( - "copying from {} to {}", - wasi_test_wasm_path(), - root.join("qjs.wasm").display() - ); - std::fs::create_dir_all(&root).unwrap(); - println!("copying..."); - std::fs::copy(wasi_test_wasm_path(), root.join("qjs.wasm")).unwrap(); - - println!( - "running wasmer run {} -- -q", - root.join("qjs.wasm").display() - ); + println!("running wasmer run {wasm_test_path} -- -q"); let mut cmd = Command::new("wasmer"); cmd.arg("run"); - cmd.arg(root.join("qjs.wasm")); + cmd.arg(&wasm_test_path); cmd.arg("--"); cmd.arg("-q"); println!("running command: {cmd:?}"); - let output = cmd.current_dir(&root).output()?; + let output = cmd.output()?; if !output.status.success() { bail!( From 4b4214d8889193203af9cd175b612c9df982f62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 24 Nov 2022 23:01:44 +0100 Subject: [PATCH 16/29] Remove unnecessary line from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 427df446a7c..24affcea4df 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ api-docs-repo/ /src/windows-installer/WasmerInstaller.exe /lib/c-api/wasmer.h .xwin-cache -/temp-wasmer-run-complex-url # Generated by tests on Android /avd /core From 4040320b1ad0dc19e0e00b78d4177729d2081f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 00:55:43 +0100 Subject: [PATCH 17/29] Make sure that the test is being run on Windows --- .github/workflows/test-sys.yaml | 17 +++++++++++++++++ tests/integration/cli/tests/run.rs | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 9007ee55cc3..1cea9687915 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -213,6 +213,23 @@ jobs: CARGO_TARGET: --target ${{ matrix.target }} WAPM_DEV_TOKEN: ${{ secrets.WAPM_DEV_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Test integration CLI + if: matrix.run_test && matrix.os == 'windows-2019' + shell: bash + run: | + make build-wasmer && + make build-capi && + make package-capi && + make package && + export WASMER_DIR=`pwd`/package && + cargo test --package wasmer-integration-tests-cli --test run -- test_wasmer_run_complex_url --exact --nocapture + env: + TARGET: ${{ matrix.target }} + TARGET_DIR: target/${{ matrix.target }}/release + CARGO_TARGET: --target ${{ matrix.target }} + WAPM_DEV_TOKEN: ${{ secrets.WAPM_DEV_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # cargo test --package wasmer-integration-tests-cli --test run -- test_wasmer_run_complex_url --exact --nocapture #- name: Test integration CLI # if: matrix.run_test && matrix.os == 'windows-2019' # shell: bash diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 66da0e21dd5..6e8d6b7f5bc 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -6,19 +6,23 @@ use std::process::Command; use wasmer_integration_tests_cli::{get_repo_root_path, get_wasmer_path, ASSET_PATH, C_ASSET_PATH}; fn wasi_test_python_path() -> String { - format!("{}/{}", C_ASSET_PATH, "python-0.1.0.wasmer") + let slash = if C_ASSET_PATH.ends_with('/') { "" } else { "/" }; + format!("{}{slash}{}", C_ASSET_PATH, "python-0.1.0.wasmer") } fn wasi_test_wasm_path() -> String { - format!("{}/{}", C_ASSET_PATH, "qjs.wasm") + let slash = if C_ASSET_PATH.ends_with('/') { "" } else { "/" }; + format!("{}{slash}{}", C_ASSET_PATH, "qjs.wasm") } fn test_no_imports_wat_path() -> String { - format!("{}/{}", ASSET_PATH, "fib.wat") + let slash = if ASSET_PATH.ends_with('/') { "" } else { "/" }; + format!("{}{slash}{}", ASSET_PATH, "fib.wat") } fn test_no_start_wat_path() -> String { - format!("{}/{}", ASSET_PATH, "no_start.wat") + let slash = if ASSET_PATH.ends_with('/') { "" } else { "/" }; + format!("{}{slash}{}", ASSET_PATH, "no_start.wat") } #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -564,7 +568,7 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { let mut cmd = Command::new("wasmer"); cmd.arg("run"); - cmd.arg(&wasm_test_path); + cmd.arg(wasi_test_wasm_path()); cmd.arg("--"); cmd.arg("-q"); From 3db9ac63360f8497c89e8ae5cf68dec2273b049f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 12:17:07 +0100 Subject: [PATCH 18/29] Fix "wasmer" -> get_wasmer_path() --- tests/integration/cli/tests/run.rs | 32 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 6e8d6b7f5bc..db9a9e4f243 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -1,28 +1,24 @@ //! Basic tests for the `run` subcommand use anyhow::bail; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; use wasmer_integration_tests_cli::{get_repo_root_path, get_wasmer_path, ASSET_PATH, C_ASSET_PATH}; -fn wasi_test_python_path() -> String { - let slash = if C_ASSET_PATH.ends_with('/') { "" } else { "/" }; - format!("{}{slash}{}", C_ASSET_PATH, "python-0.1.0.wasmer") +fn wasi_test_python_path() -> PathBuf { + Path::new(C_ASSET_PATH).join("python-0.1.0.wasmer") } -fn wasi_test_wasm_path() -> String { - let slash = if C_ASSET_PATH.ends_with('/') { "" } else { "/" }; - format!("{}{slash}{}", C_ASSET_PATH, "qjs.wasm") +fn wasi_test_wasm_path() -> PathBuf { + Path::new(C_ASSET_PATH).join("qjs.wasm") } -fn test_no_imports_wat_path() -> String { - let slash = if ASSET_PATH.ends_with('/') { "" } else { "/" }; - format!("{}{slash}{}", ASSET_PATH, "fib.wat") +fn test_no_imports_wat_path() -> PathBuf { + Path::new(ASSET_PATH).join("fib.wat") } -fn test_no_start_wat_path() -> String { - let slash = if ASSET_PATH.ends_with('/') { "" } else { "/" }; - format!("{}{slash}{}", ASSET_PATH, "no_start.wat") +fn test_no_start_wat_path() -> PathBuf { + Path::new(ASSET_PATH).join("no_start.wat") } #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -564,16 +560,18 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { ); } - println!("running wasmer run {wasm_test_path} -- -q"); + println!( + "running {} run {} -- -q", + get_wasmer_path().display(), + wasm_test_path.display() + ); - let mut cmd = Command::new("wasmer"); + let mut cmd = Command::new(get_wasmer_path()); cmd.arg("run"); cmd.arg(wasi_test_wasm_path()); cmd.arg("--"); cmd.arg("-q"); - println!("running command: {cmd:?}"); - let output = cmd.output()?; if !output.status.success() { From 854f9be08d1f2b6177f54f76cf38366af1c39e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 12:57:51 +0100 Subject: [PATCH 19/29] Fix Makefile on Windows --- .github/workflows/test-sys.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 1cea9687915..f440ede6fda 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -218,15 +218,11 @@ jobs: shell: bash run: | make build-wasmer && - make build-capi && - make package-capi && - make package && - export WASMER_DIR=`pwd`/package && cargo test --package wasmer-integration-tests-cli --test run -- test_wasmer_run_complex_url --exact --nocapture env: TARGET: ${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }}/release - CARGO_TARGET: --target ${{ matrix.target }} + CARGO_TARGET: --target x86_64-pc-windows-msvc WAPM_DEV_TOKEN: ${{ secrets.WAPM_DEV_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # cargo test --package wasmer-integration-tests-cli --test run -- test_wasmer_run_complex_url --exact --nocapture From 19696929c8eef8e88459ef9d0a45357a296d1911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 14:03:59 +0100 Subject: [PATCH 20/29] Windows: make path complex by canonicalizing --- tests/integration/cli/tests/run.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index db9a9e4f243..5ab6b6280a1 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -551,9 +551,11 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { #[test] fn test_wasmer_run_complex_url() -> anyhow::Result<()> { let wasm_test_path = wasi_test_wasm_path(); + let wasm_test_path = wasm_test_path.canonicalize().unwrap_or(wasm_test_path); #[cfg(target_os = "windows")] { // wasmer run used to fail on c:\Users\username\wapm_packages\ ... + println!("wasm test path: {}", wasm_test_path.display()); assert!( wasm_test_path.starts_with("c:\\") || wasm_test_path.starts_with("C://"), "wasm_test_path path is not complex enough" @@ -568,7 +570,7 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { let mut cmd = Command::new(get_wasmer_path()); cmd.arg("run"); - cmd.arg(wasi_test_wasm_path()); + cmd.arg(wasm_test_path); cmd.arg("--"); cmd.arg("-q"); From 6d559c242f6393a0884165aadf42673a3f30a1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 14:36:37 +0100 Subject: [PATCH 21/29] Fix wasmer_run_complex_url on Windows GitHub CI --- tests/integration/cli/tests/run.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 5ab6b6280a1..826d4037c77 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -552,12 +552,16 @@ fn run_no_start_wasm_report_error() -> anyhow::Result<()> { fn test_wasmer_run_complex_url() -> anyhow::Result<()> { let wasm_test_path = wasi_test_wasm_path(); let wasm_test_path = wasm_test_path.canonicalize().unwrap_or(wasm_test_path); + let mut wasm_test_path = format!("{}", wasm_test_path.display()); + if wasm_test_path.starts_with(r#"\\?\"#) { + wasm_test_path = wasm_test_path.replacen(r#"\\?\"#, "", 1); + } #[cfg(target_os = "windows")] { // wasmer run used to fail on c:\Users\username\wapm_packages\ ... println!("wasm test path: {}", wasm_test_path.display()); assert!( - wasm_test_path.starts_with("c:\\") || wasm_test_path.starts_with("C://"), + wasm_test_path.contains(":\\"), "wasm_test_path path is not complex enough" ); } From c352e1cf3633b682f8f4d968e0991f06afa70b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 15:02:57 +0100 Subject: [PATCH 22/29] Fix compilation error in complex_url test --- tests/integration/cli/tests/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 826d4037c77..bbc4c039b65 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -569,7 +569,7 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { println!( "running {} run {} -- -q", get_wasmer_path().display(), - wasm_test_path.display() + wasm_test_path ); let mut cmd = Command::new(get_wasmer_path()); From 9285031e46f510625528754d5dc785511026f67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 15:04:43 +0100 Subject: [PATCH 23/29] Remove temporary out.tar.gz --- tests/integration/cli/tests/run.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index bbc4c039b65..7bcb9582685 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -192,11 +192,7 @@ fn test_wasmer_create_exe_pirita_works() -> anyhow::Result<()> { "packaging /package to .tar.gz: {}", tmp_targz_path.display() ); - package_directory( - &package_path, - &std::path::Path::new("./out.tar.gz").to_path_buf(), - ); - std::fs::copy("./out.tar.gz", &tmp_targz_path).unwrap(); + package_directory(&package_path, &tmp_targz_path); println!("packaging done"); println!( "tmp tar gz path: {} - exists: {:?}", From 808bcca53737246b0df065afd84c3a0c158e74a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 15:41:49 +0100 Subject: [PATCH 24/29] Fix last compile error on Windows --- tests/integration/cli/tests/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 7bcb9582685..1f922cd62da 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -555,7 +555,7 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { #[cfg(target_os = "windows")] { // wasmer run used to fail on c:\Users\username\wapm_packages\ ... - println!("wasm test path: {}", wasm_test_path.display()); + println!("wasm test path: {wasm_test_path}"); assert!( wasm_test_path.contains(":\\"), "wasm_test_path path is not complex enough" From 468c587414c45111d0b9e54a6236ce9b26d0be4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 16:38:27 +0100 Subject: [PATCH 25/29] Windows: test that path actually conflicts with URL --- tests/integration/cli/tests/run.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 1f922cd62da..df1c85513fa 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -554,10 +554,13 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { } #[cfg(target_os = "windows")] { + wasm_test_path = wasm_test_path.replace("D:\\", "D://"); + wasm_test_path = wasm_test_path.replace("C:\\", "C://"); + wasm_test_path = wasm_test_path.replace("c:\\", "c://"); // wasmer run used to fail on c:\Users\username\wapm_packages\ ... println!("wasm test path: {wasm_test_path}"); assert!( - wasm_test_path.contains(":\\"), + wasm_test_path.contains("://"), "wasm_test_path path is not complex enough" ); } From fda1a3fa075491567918d1432860fdd1e53ea967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 17:19:24 +0100 Subject: [PATCH 26/29] Replace \\ with / on Windows --- tests/integration/cli/tests/run.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index df1c85513fa..e7a777905c1 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -1,6 +1,6 @@ //! Basic tests for the `run` subcommand -use anyhow::bail; +use anyhow::{bail, Context}; use std::path::{Path, PathBuf}; use std::process::Command; use wasmer_integration_tests_cli::{get_repo_root_path, get_wasmer_path, ASSET_PATH, C_ASSET_PATH}; @@ -557,6 +557,7 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { wasm_test_path = wasm_test_path.replace("D:\\", "D://"); wasm_test_path = wasm_test_path.replace("C:\\", "C://"); wasm_test_path = wasm_test_path.replace("c:\\", "c://"); + wasm_test_path = wasm_test_path.replace("\\", "/"); // wasmer run used to fail on c:\Users\username\wapm_packages\ ... println!("wasm test path: {wasm_test_path}"); assert!( @@ -571,13 +572,30 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { wasm_test_path ); + println!( + "current dir {:?}", + get_repo_root_path().map(|o| o.canonicalize()) + ); + println!( + "file exists: {:?}", + get_repo_root_path() + .map(|o| o.join("lib/c-api/examples/assets/qjs.wasm").exists()) + .unwrap_or(false) + ); + let mut cmd = Command::new(get_wasmer_path()); cmd.arg("run"); cmd.arg(wasm_test_path); cmd.arg("--"); cmd.arg("-q"); - let output = cmd.output()?; + let cmd_str = format!("{cmd:?}"); + let output = cmd.output().with_context(|| { + anyhow::anyhow!( + "failed to run {cmd_str} with {}", + get_wasmer_path().display() + ) + })?; if !output.status.success() { bail!( From 1594c88146304e931da6a0c2084179173f1807c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 18:15:11 +0100 Subject: [PATCH 27/29] Debug why Windows can't find qjs.wasm --- tests/integration/cli/tests/run.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index e7a777905c1..74019b161a0 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -576,13 +576,22 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { "current dir {:?}", get_repo_root_path().map(|o| o.canonicalize()) ); + let expected_file = get_repo_root_path().map(|o| o.join("lib/c-api/examples/assets/qjs.wasm")); println!( - "file exists: {:?}", - get_repo_root_path() - .map(|o| o.join("lib/c-api/examples/assets/qjs.wasm").exists()) - .unwrap_or(false) + "file {:?} exists: {:?}", + expected_file, + expected_file.as_ref().map(|o| o.exists()).unwrap_or(false) + ); + println!( + "wasmer path {:?} exists: {:?}", + get_wasmer_path(), + get_wasmer_path().exists() + ); + println!( + "qjs file path {:?} exists: {:?}", + Path::new(&wasm_test_path), + Path::new(&wasm_test_path).exists() ); - let mut cmd = Command::new(get_wasmer_path()); cmd.arg("run"); cmd.arg(wasm_test_path); From a0668f92ea387aea38e33828c1ee4658aab337c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 18:48:49 +0100 Subject: [PATCH 28/29] Get better at locating wasmer.exe for running integration tests --- tests/integration/cli/Cargo.toml | 1 + tests/integration/cli/src/assets.rs | 43 +++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/integration/cli/Cargo.toml b/tests/integration/cli/Cargo.toml index ed384c5a8c6..9f9beedf6d5 100644 --- a/tests/integration/cli/Cargo.toml +++ b/tests/integration/cli/Cargo.toml @@ -16,6 +16,7 @@ target-lexicon = "0.12.4" [dependencies] anyhow = "1" tempfile = "3" +target-lexicon = "0.12.5" [features] default = ["webc_runner"] diff --git a/tests/integration/cli/src/assets.rs b/tests/integration/cli/src/assets.rs index 53f15bd7997..b341bbb69c1 100644 --- a/tests/integration/cli/src/assets.rs +++ b/tests/integration/cli/src/assets.rs @@ -63,21 +63,58 @@ pub fn get_wasmer_path() -> PathBuf { ret = PathBuf::from(format!("{}wasmer", WASMER_TARGET_PATH2)); } if !ret.exists() { - match get_repo_root_path() { + ret = match get_repo_root_path() { Some(s) => { #[cfg(target_os = "windows")] { - return s.join("target").join("release").join("wasmer.exe"); + s.join("target").join("release").join("wasmer.exe") } #[cfg(not(target_os = "windows"))] { - return s.join("target").join("release").join("wasmer"); + s.join("target").join("release").join("wasmer") } } None => { panic!("Could not find wasmer executable path! {:?}", ret); } + }; + } + + if !ret.exists() { + ret = match get_repo_root_path() { + Some(s) => { + #[cfg(target_os = "windows")] + { + s.join("target") + .join(target_lexicon::HOST.to_string()) + .join("release") + .join("wasmer.exe") + } + #[cfg(not(target_os = "windows"))] + { + s.join("target") + .join(target_lexicon::HOST.to_string()) + .join("release") + .join("wasmer") + } + } + None => { + panic!("Could not find wasmer executable path! {:?}", ret); + } + }; + } + + if !ret.exists() { + if let Some(root) = get_repo_root_path() { + use std::process::Stdio; + let _ = std::process::Command::new("ls") + .arg(root.join("target")) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .stdin(Stdio::null()) + .output(); } + panic!("cannot find wasmer / wasmer.exe for integration test!"); } ret } From 83a38542dc8d07f677539cb584a67011200019d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 25 Nov 2022 21:01:19 +0100 Subject: [PATCH 29/29] Remove printlns in test_wasmer_run_complex_url --- tests/integration/cli/tests/run.rs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index 74019b161a0..8146e55789b 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -559,39 +559,12 @@ fn test_wasmer_run_complex_url() -> anyhow::Result<()> { wasm_test_path = wasm_test_path.replace("c:\\", "c://"); wasm_test_path = wasm_test_path.replace("\\", "/"); // wasmer run used to fail on c:\Users\username\wapm_packages\ ... - println!("wasm test path: {wasm_test_path}"); assert!( wasm_test_path.contains("://"), "wasm_test_path path is not complex enough" ); } - println!( - "running {} run {} -- -q", - get_wasmer_path().display(), - wasm_test_path - ); - - println!( - "current dir {:?}", - get_repo_root_path().map(|o| o.canonicalize()) - ); - let expected_file = get_repo_root_path().map(|o| o.join("lib/c-api/examples/assets/qjs.wasm")); - println!( - "file {:?} exists: {:?}", - expected_file, - expected_file.as_ref().map(|o| o.exists()).unwrap_or(false) - ); - println!( - "wasmer path {:?} exists: {:?}", - get_wasmer_path(), - get_wasmer_path().exists() - ); - println!( - "qjs file path {:?} exists: {:?}", - Path::new(&wasm_test_path), - Path::new(&wasm_test_path).exists() - ); let mut cmd = Command::new(get_wasmer_path()); cmd.arg("run"); cmd.arg(wasm_test_path);