//! Integration tests for the `defsnip` command. use assert_cmd::Command; use predicates::prelude::*; use std::path::PathBuf; fn cargo_command() -> Command { Command::cargo_bin("defsnip").expect("binary") } fn fixture_path(relative: &str) -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("..") .join("..") .join("fixtures") .join("polyglot") .join("repo") .join(relative) } fn pwsh_command(script: impl AsRef) -> Command { let mut command = Command::new("pwsh"); command .arg("-NoProfile") .arg("-Command") .arg(script.as_ref()); command } #[test] fn extracts_exact_symbol_matches_as_json() { let mut command = cargo_command(); command .arg("--json") .arg("helper") .arg(fixture_path("")) .assert() .success() .stdout(predicate::str::contains("\"qualified_name\":\"helper\"")) .stdout(predicate::str::contains( "\"qualified_name\":\"nested::Widget::helper\"", )) .stdout(predicate::str::contains("\"qualified_name\":\"Worker::build\"").not()); } #[test] fn filters_method_matches_and_renders_text() { let mut command = cargo_command(); command .args(["--kind", "method", "--parents", "Build"]) .arg(fixture_path("")) .assert() .success() .stdout(predicate::str::contains("RocketBuilder::Build")) .stdout(predicate::str::contains("NestedThing::Build")) .stdout(predicate::str::contains("public void Build(string name)")); } #[test] fn supports_powershell_pipeline_paths() { let binary = assert_cmd::cargo::cargo_bin("defsnip"); let path = fixture_path("web/app.ts"); let script = format!( "'{}' | & '{}' helper --json | ConvertFrom-Json | Select-Object -ExpandProperty qualified_name", path.display(), binary.display() ); let mut command = pwsh_command(script); command .assert() .success() .stdout(predicate::str::contains("helper")); } #[test] fn help_includes_examples_and_pipeline_usage() { let mut command = cargo_command(); command .arg("--help") .assert() .success() .stdout(predicate::str::contains("--kind")) .stdout(predicate::str::contains("ConvertFrom-Json")) .stdout(predicate::str::contains("defsnip helper")); }