use assert_cmd::Command;
use predicates::prelude::*;
fn skim_cmd() -> Command {
Command::cargo_bin("skim").unwrap()
}
#[test]
fn test_alignment_cargo_test_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "cargo", "test"])
.assert()
.success()
.stdout(predicate::str::contains("skim test cargo"));
let fixture = include_str!("fixtures/cmd/test/cargo_pass.json");
skim_cmd()
.args(["test", "cargo"])
.write_stdin(fixture)
.assert()
.success()
.stdout(predicate::str::contains("PASS"));
}
#[test]
fn test_alignment_cargo_test_true_roundtrip() {
let rewrite_out = skim_cmd()
.args(["rewrite", "cargo", "test"])
.output()
.unwrap();
assert!(
rewrite_out.status.success(),
"skim rewrite cargo test must succeed; got: {:?}",
rewrite_out.status
);
let rewritten = String::from_utf8(rewrite_out.stdout).unwrap();
let rewritten = rewritten.trim();
assert!(
!rewritten.is_empty(),
"skim rewrite cargo test must emit a non-empty command string"
);
let tokens: Vec<&str> = rewritten.split_whitespace().collect();
assert!(
tokens.first() == Some(&"skim"),
"rewrite output must start with 'skim'; got: {rewritten}"
);
let handler_args = &tokens[1..];
let fixture = include_str!("fixtures/cmd/test/cargo_pass.json");
skim_cmd()
.args(handler_args)
.write_stdin(fixture)
.assert()
.success()
.stdout(predicate::str::contains("PASS"));
}
#[test]
fn test_alignment_pytest_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "pytest"])
.assert()
.success()
.stdout(predicate::str::contains("skim test pytest"));
let fixture = include_str!("fixtures/cmd/test/pytest_pass.txt");
skim_cmd()
.args(["test", "pytest"])
.write_stdin(fixture)
.assert()
.success()
.stdout(predicate::str::contains("PASS"));
}
#[test]
fn test_alignment_npx_vitest_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "npx", "vitest"])
.assert()
.success()
.stdout(predicate::str::contains("skim test vitest"));
let fixture = include_str!("fixtures/cmd/test/vitest_regex_fail.txt");
skim_cmd()
.args(["test", "vitest"])
.write_stdin(fixture)
.assert()
.code(1)
.stdout(predicate::str::contains("FAIL: 1"));
}
#[test]
fn test_alignment_eslint_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "eslint", "."])
.assert()
.success()
.stdout(predicate::str::contains("skim lint eslint"));
let fixture = include_str!("fixtures/cmd/lint/eslint_fail.json");
skim_cmd()
.args(["lint", "eslint"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("LINT"));
}
#[test]
fn test_alignment_ruff_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "ruff", "check", "."])
.assert()
.success()
.stdout(predicate::str::contains("skim lint ruff"));
let fixture = include_str!("fixtures/cmd/lint/ruff_fail.json");
skim_cmd()
.args(["lint", "ruff"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("LINT"));
}
#[test]
fn test_alignment_mypy_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "mypy", "."])
.assert()
.success()
.stdout(predicate::str::contains("skim lint mypy"));
let fixture = include_str!("fixtures/cmd/lint/mypy_fail.json");
skim_cmd()
.args(["lint", "mypy"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("LINT"));
}
#[test]
fn test_alignment_golangci_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "golangci-lint", "run", "./..."])
.assert()
.success()
.stdout(predicate::str::contains("skim lint golangci"));
let fixture = include_str!("fixtures/cmd/lint/golangci_fail.json");
skim_cmd()
.args(["lint", "golangci"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("LINT"));
}
#[test]
fn test_alignment_npm_audit_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "npm", "audit"])
.assert()
.success()
.stdout(predicate::str::contains("skim pkg npm audit"));
let fixture = include_str!("fixtures/cmd/pkg/npm_audit.json");
skim_cmd()
.args(["pkg", "npm", "audit"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("AUDIT"));
}
#[test]
fn test_alignment_npm_install_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "npm", "install", "express"])
.assert()
.success()
.stdout(predicate::str::contains("skim pkg npm install express"));
let fixture = include_str!("fixtures/cmd/pkg/npm_install.json");
skim_cmd()
.args(["pkg", "npm", "install"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("INSTALL").or(predicate::str::contains("install")));
}
#[test]
fn test_alignment_cargo_audit_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "cargo", "audit"])
.assert()
.success()
.stdout(predicate::str::contains("skim pkg cargo audit"));
let fixture = include_str!("fixtures/cmd/pkg/cargo_audit.json");
skim_cmd()
.args(["pkg", "cargo", "audit"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("AUDIT"));
}
#[test]
fn test_alignment_pip_install_rewrite_and_handler() {
skim_cmd()
.args(["rewrite", "pip", "install", "flask"])
.assert()
.success()
.stdout(predicate::str::contains("skim pkg pip install flask"));
let fixture = include_str!("fixtures/cmd/pkg/pip_install.txt");
skim_cmd()
.args(["pkg", "pip", "install"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("INSTALL").or(predicate::str::contains("install")));
}
#[test]
fn test_alignment_prettier_check_acked_not_rewritten_to_handler() {
let output = skim_cmd()
.args(["rewrite", "prettier", "--check", "."])
.output()
.unwrap();
assert!(
output.status.success(),
"ACKed command must exit 0, got: {:?}",
output.status
);
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains("prettier --check"),
"ACK must echo original command: {stdout}"
);
assert!(
!stdout.contains("skim lint prettier"),
"ACK must NOT produce a handler rewrite: {stdout}"
);
}
#[test]
fn test_alignment_rustfmt_check_acked_not_rewritten_to_handler() {
let output = skim_cmd()
.args(["rewrite", "rustfmt", "--check", "src/main.rs"])
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains("rustfmt --check"),
"ACK must echo original command: {stdout}"
);
assert!(
!stdout.contains("skim lint rustfmt"),
"ACK must NOT produce a handler rewrite: {stdout}"
);
}
#[test]
fn test_alignment_cargo_fmt_check_acked() {
let output = skim_cmd()
.args(["rewrite", "cargo", "fmt", "--check"])
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains("cargo fmt --check"),
"ACK must echo original command: {stdout}"
);
assert!(
!stdout.contains("skim lint rustfmt"),
"ACK must NOT rewrite to a handler: {stdout}"
);
}
#[test]
fn test_alignment_cargo_fmt_dashdash_check_acked() {
let output = skim_cmd()
.args(["rewrite", "cargo", "fmt", "--", "--check"])
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains("cargo fmt -- --check"),
"ACK must echo original command: {stdout}"
);
}
#[test]
fn test_alignment_rewrite_single_quoted_string_tokenizes_correctly() {
let output = skim_cmd()
.args(["rewrite", "prettier --check src/"])
.output()
.unwrap();
assert!(
output.status.success(),
"single quoted arg must succeed, got: {:?}",
output.status
);
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains("prettier --check"),
"single quoted arg must ACK-echo the command: {stdout}"
);
}
#[test]
fn test_alignment_rewrite_single_quoted_cargo_fmt() {
let output = skim_cmd()
.args(["rewrite", "cargo fmt --check"])
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains("cargo fmt --check"),
"single quoted cargo fmt --check must ACK-echo: {stdout}"
);
}
#[test]
fn test_alignment_cargo_test_separator_preserved() {
skim_cmd()
.args(["rewrite", "cargo", "test", "--", "--nocapture"])
.assert()
.success()
.stdout(predicate::str::contains("skim test cargo -- --nocapture"));
}
#[test]
fn test_alignment_npm_ci_alias_and_handler() {
skim_cmd()
.args(["rewrite", "npm", "ci"])
.assert()
.success()
.stdout(predicate::str::contains("skim pkg npm install"));
let fixture = include_str!("fixtures/cmd/pkg/npm_install.json");
skim_cmd()
.args(["pkg", "npm", "install"])
.write_stdin(fixture)
.assert()
.stdout(predicate::str::contains("INSTALL").or(predicate::str::contains("install")));
}
#[test]
fn test_alignment_python3_m_pytest_same_handler_as_bare_pytest() {
let bare = skim_cmd()
.args(["rewrite", "pytest", "-v"])
.output()
.unwrap();
let python3 = skim_cmd()
.args(["rewrite", "python3", "-m", "pytest", "-v"])
.output()
.unwrap();
assert!(bare.status.success());
assert!(python3.status.success());
let bare_stdout = String::from_utf8(bare.stdout).unwrap();
let python3_stdout = String::from_utf8(python3.stdout).unwrap();
assert!(
bare_stdout.contains("skim test pytest"),
"bare pytest must rewrite to skim test pytest: {bare_stdout}"
);
assert!(
python3_stdout.contains("skim test pytest"),
"python3 -m pytest must rewrite to skim test pytest: {python3_stdout}"
);
}