forked from Crockan/MercuryToolbox
106 lines
2.9 KiB
Rust
106 lines
2.9 KiB
Rust
//! Integration tests for the `asmmember` command.
|
|
|
|
use assert_cmd::Command;
|
|
use predicates::prelude::*;
|
|
use serde_json::Value;
|
|
use std::path::PathBuf;
|
|
|
|
fn cargo_command() -> Command {
|
|
Command::cargo_bin("asmmember").expect("binary")
|
|
}
|
|
|
|
fn workspace_root() -> PathBuf {
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("..")
|
|
.join("..")
|
|
.canonicalize()
|
|
.expect("workspace root")
|
|
}
|
|
|
|
fn managed_fixture_dir() -> PathBuf {
|
|
workspace_root()
|
|
.join("fixtures")
|
|
.join("managed")
|
|
.join("bin")
|
|
}
|
|
|
|
fn fixture_assembly() -> PathBuf {
|
|
managed_fixture_dir().join("GameAssembly.dll")
|
|
}
|
|
|
|
#[test]
|
|
fn help_includes_examples_and_binding_usage() {
|
|
let mut command = cargo_command();
|
|
command
|
|
.arg("--help")
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("--assembly"))
|
|
.stdout(predicate::str::contains("--binding"))
|
|
.stdout(predicate::str::contains("--user-code-only"))
|
|
.stdout(predicate::str::contains("ConvertFrom-Json"));
|
|
}
|
|
|
|
#[test]
|
|
fn emits_methods_fields_and_properties_as_json() {
|
|
let mut command = cargo_command();
|
|
let output = command
|
|
.arg("--assembly")
|
|
.arg(fixture_assembly())
|
|
.arg("Game.UI.Windows.Windows.SpaceCraftConstructionWindow")
|
|
.arg("--match")
|
|
.arg("Build|Project|Launch|Queue|Complete")
|
|
.arg("--binding")
|
|
.arg("public,nonpublic,instance,static")
|
|
.arg("--user-code-only")
|
|
.arg("--json")
|
|
.assert()
|
|
.success()
|
|
.get_output()
|
|
.stdout
|
|
.clone();
|
|
let payload = serde_json::from_slice::<Value>(&output).expect("json payload");
|
|
let entries = payload.as_array().expect("array payload");
|
|
assert!(
|
|
entries
|
|
.iter()
|
|
.any(|entry| entry["kind"] == "method" && entry["name"] == "StartProject")
|
|
);
|
|
assert!(
|
|
entries
|
|
.iter()
|
|
.any(|entry| entry["kind"] == "field" && entry["name"] == "_buildTicks")
|
|
);
|
|
assert!(
|
|
entries
|
|
.iter()
|
|
.any(|entry| entry["kind"] == "property" && entry["name"] == "ProjectName")
|
|
);
|
|
assert!(!entries.iter().any(|entry| {
|
|
entry["kind"] == "field"
|
|
&& entry["name"]
|
|
.as_str()
|
|
.is_some_and(|name| name.contains("BackingField"))
|
|
}));
|
|
}
|
|
|
|
#[test]
|
|
fn supports_type_names_from_powershell_pipeline() {
|
|
let binary = assert_cmd::cargo::cargo_bin("asmmember");
|
|
let assembly = fixture_assembly();
|
|
let script = format!(
|
|
"'Game.UI.Windows.Windows.SpaceCraftConstructionWindow' | & '{}' --assembly '{}' --input-format lines --match Project --json",
|
|
binary.display(),
|
|
assembly.display()
|
|
);
|
|
|
|
let mut command = Command::new("pwsh");
|
|
command
|
|
.arg("-NoProfile")
|
|
.arg("-Command")
|
|
.arg(script)
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("\"name\":\"StartProject\""));
|
|
}
|