agentleFS
mejbaurbaharmejbaurbahar/software-tester-skills/skills/cli-testing/SKILL.md

cli-testing

Skill1 starsChanged 52 days agoMITView on GitHub

Use when testing command-line tools and scripts — exit codes, stdout/stderr contracts, flags and argument parsing, help/version output, stdin/pipes, env/config precedence, cross-platform paths, signals, idempotency, and Bats/pytest/expect-based automation.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

CLI Testing

A CLI's API is: args + env + stdin → stdout + stderr + exit code + side effects. Test that contract.

Contract checklist

AspectVerify
Exit codes0 success; non-zero on failure (documented: 1 general, 2 usage, 64–78 sysexits); consistent
StreamsData → stdout; diagnostics/progress → stderr; nothing extra on stdout (pipe-safe)
Help/version-h/--help exit 0, lists all flags, examples; --version machine-readable
ArgsUnknown flag → usage error (exit 2); missing required arg; -- separator; flag=value & flag value; short-flag bundling -abc; repeated flags; negative numbers
Inputstdin -; empty stdin; huge stdin; binary; CRLF; TTY vs pipe detection
Output modes--json valid & stable schema; --quiet/--verbose; color disabled when not TTY or NO_COLOR set
Config precedenceflag > env > project config > user config > defaults (test each layer)
FilesNonexistent, directory instead of file, no permission, symlink, spaces/unicode paths, ~ expansion, overwrite prompts/--force, atomic writes
IdempotencyRunning twice is safe; --dry-run changes nothing
SignalsSIGINT/SIGTERM → cleanup, partial files removed, exit 130/143; SIGPIPE handled (`head`)
InteractivityPrompts have non-interactive override (--yes); no hang in CI
Cross-platformWindows paths/CRLF/quoting, macOS BSD vs GNU coreutils, locale LANG=C
SecurityNo secrets in argv (visible in ps); shell-injection via args/filenames; tmp files 0600; safe deserialization
PerformanceStartup time; large input streaming (constant memory)

Tooling

# Bats (bash)
#!/usr/bin/env bats
@test "prints version" { run mycli --version; [ "$status" -eq 0 ]; [[ "$output" =~ ^mycli\ [0-9]+\.[0-9]+ ]]; }
@test "rejects unknown flag" { run mycli --nope; [ "$status" -eq 2 ]; [[ "$output" == *"Usage"* ]]; }
# pytest + subprocess
import subprocess, json
def run(*a, inp=None): return subprocess.run(["mycli",*a], input=inp, capture_output=True, text=True)
def test_json_mode():
    r = run("list","--json"); assert r.returncode == 0 and r.stderr == ""
    assert isinstance(json.loads(r.stdout), list)

Other: cram/prysk (transcript tests), expect/pexpect/node-pty for interactive TTY flows, snapshot-golden-testing for help text and reports, shellcheck + shfmt for shell scripts, Go testscript, Rust assert_cmd + predicates, Node execa.

Test the installed artifact

Package (npm/pip/brew/cargo/binary), install into a clean container, run smoke commands, verify shebang/permissions/completions (bash, zsh, fish), man page, --version matches tag.

Related

unit-testing, integration-testing, snapshot-golden-testing, installation-upgrade-testing, fuzz-testing

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.