forked from Crockan/MercuryToolbox
chore(release): prepare public source release
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
//! Integration tests for the `asmtype` command.
|
||||
|
||||
use assert_cmd::Command;
|
||||
use predicates::prelude::*;
|
||||
use serde_json::Value;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn cargo_command() -> Command {
|
||||
Command::cargo_bin("asmtype").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_pipeline_usage() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--help")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
predicate::str::contains(
|
||||
"asmtype .\\fixtures\\managed\\GameAssembly\\GameAssembly.csproj",
|
||||
)
|
||||
.not(),
|
||||
)
|
||||
.stdout(predicate::str::contains("asmtype .\\target\\"))
|
||||
.stdout(predicate::str::contains("ConvertFrom-Json"))
|
||||
.stdout(predicate::str::contains("--match"))
|
||||
.stdout(predicate::str::contains("--user-code-only"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filters_types_as_json() {
|
||||
let mut command = cargo_command();
|
||||
let output = command
|
||||
.arg(fixture_assembly())
|
||||
.arg("--match")
|
||||
.arg("SpaceCraft|Spacecraft")
|
||||
.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.len() >= 4, "expected at least 4 matching types");
|
||||
assert!(
|
||||
entries
|
||||
.iter()
|
||||
.any(|entry| entry["full_name"]
|
||||
== "Game.UI.Windows.Windows.SpaceCraftConstructionWindow")
|
||||
);
|
||||
assert!(
|
||||
entries.iter().any(|entry| entry["kind"] == "struct"
|
||||
&& entry["full_name"] == "Data.SpacecraftConstructData")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json_no_match_is_successful_empty_array_for_pipelines() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg(fixture_assembly())
|
||||
.arg("--match")
|
||||
.arg("^DefinitelyMissingType$")
|
||||
.arg("--json")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq("[]\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supports_powershell_pipeline_input() {
|
||||
let binary = assert_cmd::cargo::cargo_bin("asmtype");
|
||||
let input = fixture_assembly();
|
||||
let script = format!(
|
||||
"'{}' | & '{}' --input-format lines --match SpaceCraft --json",
|
||||
input.display(),
|
||||
binary.display()
|
||||
);
|
||||
|
||||
let mut command = Command::new("pwsh");
|
||||
command
|
||||
.arg("-NoProfile")
|
||||
.arg("-Command")
|
||||
.arg(script)
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains(
|
||||
"\"full_name\":\"Game.UI.Windows.Windows.SpaceCraftConstructionWindow\"",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_matched_members_hides_backing_fields_when_user_facing_hits_exist() {
|
||||
let mut command = cargo_command();
|
||||
let output = command
|
||||
.arg(fixture_assembly())
|
||||
.arg("--with-member-match")
|
||||
.arg("StartProject|QueueVehicle|k__BackingField")
|
||||
.arg("--show-matched-members")
|
||||
.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");
|
||||
let construction = entries
|
||||
.iter()
|
||||
.find(|entry| entry["full_name"] == "Game.UI.Windows.Windows.SpaceCraftConstructionWindow")
|
||||
.expect("construction row");
|
||||
assert_eq!(
|
||||
construction["matched_members"],
|
||||
Value::Array(vec![Value::String("StartProject".to_string())])
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user