chore(release): prepare public source release
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
//! Integration tests for the `fileprobe` command.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use assert_cmd::Command;
|
||||
use predicates::prelude::*;
|
||||
|
||||
fn cargo_command() -> Command {
|
||||
Command::cargo_bin("fileprobe").expect("binary")
|
||||
}
|
||||
|
||||
fn fixture(path: &str) -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("..")
|
||||
.join("..")
|
||||
.join("fixtures")
|
||||
.join(path)
|
||||
}
|
||||
|
||||
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 probes_source_files_in_text_mode() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg(fixture("reading/sample.rs"))
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("family=source"))
|
||||
.stdout(predicate::str::contains("language=rust"))
|
||||
.stdout(predicate::str::contains("binary=false"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probes_binary_files_as_json() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--json")
|
||||
.arg(fixture("reading/binary.bin"))
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("\"is_binary\":true"))
|
||||
.stdout(predicate::str::contains("\"family\":\"binary\""))
|
||||
.stdout(predicate::str::contains("\"container_hint\":\"pe\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flags_generated_minified_and_locklike_files() {
|
||||
let mut minified = cargo_command();
|
||||
minified
|
||||
.arg("--json")
|
||||
.arg(fixture("reading/minified.js"))
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("\"likely_minified\":true"))
|
||||
.stdout(predicate::str::contains("\"language_hint\":\"javascript\""));
|
||||
|
||||
let mut generated = cargo_command();
|
||||
generated
|
||||
.arg("--json")
|
||||
.arg(fixture("reading/generated.lock"))
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("\"likely_generated\":true"))
|
||||
.stdout(predicate::str::contains("\"likely_lockfile\":true"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recognizes_jsonl_as_data_for_pipeline_handoffs() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--json")
|
||||
.arg(fixture("jsonl/events.jsonl"))
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("\"family\":\"data\""))
|
||||
.stdout(predicate::str::contains("\"language_hint\":\"jsonl\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supports_powershell_path_pipeline() {
|
||||
let binary = assert_cmd::cargo::cargo_bin("fileprobe");
|
||||
let input = fixture("reading/sample.cs");
|
||||
let script = format!("'{}' | & '{}' --json", input.display(), binary.display());
|
||||
|
||||
let mut command = pwsh_command(script);
|
||||
command
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("\"language_hint\":\"csharp\""))
|
||||
.stdout(predicate::str::contains("\"family\":\"source\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expands_literal_globs_passed_by_powershell() {
|
||||
let temp = tempfile::tempdir().expect("tempdir");
|
||||
std::fs::write(temp.path().join("one.json"), "{}\n").expect("one");
|
||||
std::fs::write(temp.path().join("two.json"), "{}\n").expect("two");
|
||||
std::fs::write(temp.path().join("skip.txt"), "notes\n").expect("skip");
|
||||
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--json")
|
||||
.arg(temp.path().join("*.json"))
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("one.json"))
|
||||
.stdout(predicate::str::contains("two.json"))
|
||||
.stdout(predicate::str::contains("skip.txt").not());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unmatched_glob_suggests_fd_pipeline_for_powershell() {
|
||||
let temp = tempfile::tempdir().expect("tempdir");
|
||||
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--json")
|
||||
.arg(temp.path().join("*.missing"))
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains("glob pattern"))
|
||||
.stderr(predicate::str::contains("PowerShell"))
|
||||
.stderr(predicate::str::contains("fd -t f ."))
|
||||
.stderr(predicate::str::contains("fileprobe --input-format lines"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reports_directories_as_directories_instead_of_raw_access_errors() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--json")
|
||||
.arg(
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("..")
|
||||
.join("..")
|
||||
.join("crates"),
|
||||
)
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("\"family\":\"directory\""))
|
||||
.stdout(predicate::str::contains("\"is_directory\":true"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_includes_probe_examples() {
|
||||
let mut command = cargo_command();
|
||||
command
|
||||
.arg("--help")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("fileprobe .\\src\\main.rs"))
|
||||
.stdout(predicate::str::contains("ConvertFrom-Json"))
|
||||
.stdout(predicate::str::contains("--toon"))
|
||||
.stdout(predicate::str::contains("--format <FORMAT>"));
|
||||
}
|
||||
Reference in New Issue
Block a user