Skip to content

Commit

Permalink
Moved the version test to the wasmer-cli's tests/ directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jun 16, 2023
1 parent 0765ffd commit b3bfc7b
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 142 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

89 changes: 19 additions & 70 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,84 +125,33 @@ unix_mode = "0.1.3"
[features]
# Don't add the compiler features in default, please add them on the Makefile
# since we might want to autoconfigure them depending on the availability on the host.
default = [
"sys",
"wat",
"wast",
"compiler",
"wasmer-artifact-create",
"static-artifact-create",
]
default = ["sys", "wat", "wast", "compiler", "wasmer-artifact-create", "static-artifact-create"]
backend = []
coredump = [
"wasm-coredump-builder",
]
sys = [
"compiler",
"wasmer-vm",
]
jsc = [
"backend",
"wasmer/jsc",
"wasmer/std"
]
coredump = ["wasm-coredump-builder"]
sys = ["compiler", "wasmer-vm"]
jsc = ["backend", "wasmer/jsc", "wasmer/std"]
wast = ["wasmer-wast"]
host-net = [ "virtual-net/host-net" ]
host-net = ["virtual-net/host-net"]
wat = ["wasmer/wat"]
compiler = [
"backend",
"wasmer/compiler",
"wasmer-compiler/translator",
"wasmer-compiler/compiler"
]
wasmer-artifact-create = ["compiler",
"wasmer/wasmer-artifact-load",
"wasmer/wasmer-artifact-create",
"wasmer-compiler/wasmer-artifact-load",
"wasmer-compiler/wasmer-artifact-create",
"wasmer-object",
]
static-artifact-create = ["compiler",
"wasmer/static-artifact-load",
"wasmer/static-artifact-create",
"wasmer-compiler/static-artifact-load",
"wasmer-compiler/static-artifact-create",
"wasmer-object",
]
wasmer-artifact-load = ["compiler",
"wasmer/wasmer-artifact-load",
"wasmer-compiler/wasmer-artifact-load",
]
static-artifact-load = ["compiler",
"wasmer/static-artifact-load",
"wasmer-compiler/static-artifact-load",
]
experimental-io-devices = [
"wasmer-wasix-experimental-io-devices",
]
singlepass = [
"wasmer-compiler-singlepass",
"compiler",
]
cranelift = [
"wasmer-compiler-cranelift",
"compiler",
]
llvm = [
"wasmer-compiler-llvm",
"compiler",
]
compiler = ["backend", "wasmer/compiler", "wasmer-compiler/translator", "wasmer-compiler/compiler"]
wasmer-artifact-create = ["compiler", "wasmer/wasmer-artifact-load", "wasmer/wasmer-artifact-create", "wasmer-compiler/wasmer-artifact-load", "wasmer-compiler/wasmer-artifact-create", "wasmer-object"]
static-artifact-create = ["compiler", "wasmer/static-artifact-load", "wasmer/static-artifact-create", "wasmer-compiler/static-artifact-load", "wasmer-compiler/static-artifact-create", "wasmer-object"]
wasmer-artifact-load = ["compiler", "wasmer/wasmer-artifact-load", "wasmer-compiler/wasmer-artifact-load"]
static-artifact-load = ["compiler", "wasmer/static-artifact-load", "wasmer-compiler/static-artifact-load"]
experimental-io-devices = ["wasmer-wasix-experimental-io-devices"]
singlepass = ["wasmer-compiler-singlepass", "compiler"]
cranelift = ["wasmer-compiler-cranelift", "compiler"]
llvm = ["wasmer-compiler-llvm", "compiler"]
disable-all-logging = ["wasmer-wasix/disable-all-logging", "log/release_max_level_off"]
headless = []
headless-minimal = ["headless", "disable-all-logging"]

# Optional
enable-serde = [
"wasmer/enable-serde",
"wasmer-vm/enable-serde",
"wasmer-compiler/enable-serde",
"wasmer-wasix/enable-serde",
]
enable-serde = ["wasmer/enable-serde", "wasmer-vm/enable-serde", "wasmer-compiler/enable-serde", "wasmer-wasix/enable-serde"]

[dev-dependencies]
assert_cmd = "2.0.11"
predicates = "3.0.3"

[target.'cfg(target_os = "windows")'.dependencies]
colored = "2.0.0"
Expand Down
29 changes: 21 additions & 8 deletions lib/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,35 @@ fn wasmer_main_inner() -> Result<(), anyhow::Error> {
args.output.initialize_logging();
args.execute()
}
Err(e) if e.kind() == clap::error::ErrorKind::InvalidSubcommand => {
// Try to parse it as `wasmer some/package`
crate::logging::Output::default().initialize_logging();
Run::parse().execute()
}
Err(e) => {
if e.kind() == clap::error::ErrorKind::InvalidSubcommand {
if let Ok(run) = Run::try_parse() {
// Try to parse the command using the `wasmer some/package`
// shorthand. Note that this has discoverability issues
// because it's not shown as part of the main argument
// parser's help, but that's fine.
crate::logging::Output::default().initialize_logging();
run.execute();
}
}

e.exit();
}
}
}

/// Command-line arguments for the Wasmer CLI.
#[derive(Parser, Debug)]
#[clap(about, author)]
#[cfg_attr(feature = "headless", clap(name = "wasmer-headless"))]
#[cfg_attr(not(feature = "headless"), clap(name = "wasmer-headless"))]
#[clap(author, version)]
#[clap(disable_version_flag = true)] // handled manually
#[cfg_attr(feature = "headless", clap(
name = "wasmer-headless",
about = concat!("wasmer-headless ", env!("CARGO_PKG_VERSION")),
))]
#[cfg_attr(not(feature = "headless"), clap(
name = "wasmer",
about = concat!("wasmer ", env!("CARGO_PKG_VERSION")),
))]
pub struct Args {
/// Print version info and exit.
#[clap(short = 'V', long)]
Expand Down
68 changes: 68 additions & 0 deletions lib/cli/tests/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use assert_cmd::Command;

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

#[test]
fn short_version_string() {
let version_number = format!("wasmer {WASMER_VERSION}");

Command::cargo_bin("wasmer")
.unwrap()
.arg("--version")
.assert()
.success()
.stdout(predicates::str::contains(&version_number));

Command::cargo_bin("wasmer")
.unwrap()
.arg("-V")
.assert()
.success()
.stdout(predicates::str::contains(&version_number));
}

#[test]
fn long_version_string() {
let long_version_number = format!(
"wasmer {} ({} {})",
env!("CARGO_PKG_VERSION"),
env!("WASMER_BUILD_GIT_HASH_SHORT"),
env!("WASMER_BUILD_DATE")
);

Command::cargo_bin("wasmer")
.unwrap()
.arg("--version")
.arg("--verbose")
.assert()
.success()
.stdout(predicates::str::contains(&long_version_number))
.stdout(predicates::str::contains("binary:"));

Command::cargo_bin("wasmer")
.unwrap()
.arg("-Vv")
.assert()
.success()
.stdout(predicates::str::contains(&long_version_number))
.stdout(predicates::str::contains("binary:"));
}

#[test]
fn help_text_contains_version() {
let version_number = format!("wasmer {WASMER_VERSION}");

Command::cargo_bin("wasmer")
.unwrap()
.arg("-h")
.assert()
.success()
.stdout(predicates::str::contains(&version_number));

Command::cargo_bin("wasmer")
.unwrap()
.arg("--help")
.assert()
.success()
.stdout(predicates::str::contains(&version_number));
}
64 changes: 0 additions & 64 deletions tests/integration/cli/tests/version.rs

This file was deleted.

0 comments on commit b3bfc7b

Please sign in to comment.