Skip to content

Commit

Permalink
Add integration test, use different spinner library to fix #3346
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 24, 2022
1 parent 5d1d4f3 commit 351b0a6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 59 deletions.
76 changes: 40 additions & 36 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -166,6 +166,9 @@ http = [
"serde",
]

[target.'cfg(target_os = "windows")'.dependencies]
colored = "2.0.0"

[package.metadata.binstall]
pkg-fmt = "tgz"

Expand Down
31 changes: 16 additions & 15 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,17 +645,20 @@ impl Run {
}
}

fn start_spinner(msg: String) -> Option<spinner::SpinnerHandle> {
fn start_spinner(msg: String) -> Option<spinoff::Spinner> {
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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -765,8 +767,8 @@ fn try_lookup_command(sv: &mut SplitVersion) -> Result<PackageDownloadInfo, anyh

for registry in wasmer_registry::get_all_available_registries().unwrap_or_default() {
let result = wasmer_registry::query_command_from_registry(&registry, &sv.package);
if sp.is_some() {
print!("\r");
if let Some(s) = sp.take() {
s.clear();
}
let _ = std::io::stdout().flush();
let command = sv.package.clone();
Expand All @@ -779,8 +781,7 @@ fn try_lookup_command(sv: &mut SplitVersion) -> Result<PackageDownloadInfo, anyh
}

if let Some(sp) = sp.take() {
sp.close();
print!("\r");
sp.clear();
}
let _ = std::io::stdout().flush();
Err(anyhow::anyhow!("command {sv} not found"))
Expand Down Expand Up @@ -944,7 +945,7 @@ fn try_run_url(
})?;

if let Some(sp) = sp {
sp.close();
sp.clear();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pub fn query_package_from_registry(

let v = response.package_version.as_ref().ok_or_else(|| {
QueryPackageError::ErrorSendingQuery(format!(
"Invalid response for crate {name:?}: no manifest"
"Invalid response for crate {name:?}: no package version: {response:#?}"
))
})?;

Expand Down
11 changes: 5 additions & 6 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,10 @@ fn run_no_start_wasm_report_error() -> 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!(
Expand All @@ -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() {
Expand Down

0 comments on commit 351b0a6

Please sign in to comment.