93 lines
2.6 KiB
Rust
93 lines
2.6 KiB
Rust
//! Integration tests for the `codeshape` command.
|
|
|
|
use assert_cmd::Command;
|
|
use predicates::prelude::*;
|
|
use std::path::PathBuf;
|
|
|
|
fn cargo_command() -> Command {
|
|
Command::cargo_bin("codeshape").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<str>) -> Command {
|
|
let mut command = Command::new("pwsh");
|
|
command
|
|
.arg("-NoProfile")
|
|
.arg("-Command")
|
|
.arg(script.as_ref());
|
|
command
|
|
}
|
|
|
|
#[test]
|
|
fn summarizes_polyglot_repo_as_json() {
|
|
let mut command = cargo_command();
|
|
command
|
|
.arg("--json")
|
|
.arg(fixture_path(""))
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("\"roots\""))
|
|
.stdout(predicate::str::contains("\"language\":\"rust\""))
|
|
.stdout(predicate::str::contains("\"language\":\"go\""))
|
|
.stdout(predicate::str::contains("\"language\":\"java\""))
|
|
.stdout(predicate::str::contains(
|
|
"\"qualified_name\":\"Service::execute\"",
|
|
))
|
|
.stdout(predicate::str::contains(
|
|
"\"signature\":\"pub fn helper(name: &str) -> String\"",
|
|
))
|
|
.stdout(predicate::str::contains(
|
|
"\"signature\":\"function Invoke-Helper\"",
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn renders_compact_tree_text() {
|
|
let mut command = cargo_command();
|
|
command
|
|
.args(["--limit-per-file", "4"])
|
|
.arg(fixture_path(""))
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("src\\lib.rs"))
|
|
.stdout(predicate::str::contains("function helper"))
|
|
.stdout(predicate::str::contains("namespace Mercury.Game"));
|
|
}
|
|
|
|
#[test]
|
|
fn supports_powershell_pipeline_roots() {
|
|
let binary = assert_cmd::cargo::cargo_bin("codeshape");
|
|
let root = fixture_path("");
|
|
let script = format!(
|
|
"'{}' | & '{}' --json | ConvertFrom-Json | Select-Object -ExpandProperty totals | Select-Object -ExpandProperty files_indexed",
|
|
root.display(),
|
|
binary.display()
|
|
);
|
|
let mut command = pwsh_command(script);
|
|
command
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("10"));
|
|
}
|
|
|
|
#[test]
|
|
fn help_includes_repo_map_examples() {
|
|
let mut command = cargo_command();
|
|
command
|
|
.arg("--help")
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("--max-files"))
|
|
.stdout(predicate::str::contains("ConvertFrom-Json"))
|
|
.stdout(predicate::str::contains("codeshape"));
|
|
}
|