Test the remaining CLI cases (closes #16) #90

Merged
clawbot merged 1 commits from issue-16-cli-surface-tests into next 2026-10-04 17:47:27 +02:00
Collaborator

Most of what #16 asks for was already tested through run(args, stdout, stderr) by later issues. This adds only what was missing.

Added:

  • TestRunMissingDatabaseIsFatal: report and trees with no database exit 1 with the exact "run sfdupes scan first" line and an empty stdout.
  • TestRunScanSucceedsDespiteWarnings builds its own tree and checks the skip warning and the 1 skipped summary, not only exit 0.
  • TestRunReportSucceeds and TestRunTreesSucceeds check the exact summary line on stderr.
  • The scan tests (scanOK, the failing-scan tests, both interrupted-scan tests) capture the process's own stdout with captureStdout, because scan is never given run's stdout writer. Any stdout write in scan now fails them.
  • TestRunFatalAfterOpenClosesDatabase takes its subcommands from the command tree, so a subcommand wired with a bare RunE instead of runE fails it (comment item 2).
  • TestRunMissingOperandIsFatalNotUsage renamed TestRunNonexistentPathIsFatalNotUsage (item 3).

Already covered, unchanged: the four exit-2 cases (TestRunUsageErrors); the nonexistent operand (the renamed test); header and rows of both reports (TestRunReportSucceeds, TestRunTreesSucceeds).

Judgement calls:

  • The runE guard checks behaviour (each subcommand, failing against a broken database, exits 1 without usage text) rather than comparing function values, which Go cannot do reliably. A future subcommand that never opens the database will need the test adjusted.
  • Writers are not threaded through the subcommands (item 1): capturing the process's own streams also catches a stray fmt.Println, which a passed-down writer would miss.
  • The skip-warning test skips under root, as makeReadOnly does; the Docker build runs tests unprivileged.

Model: opus-5-5

Most of what https://git.eeqj.de/sneak/sfdupes/issues/16 asks for was already tested through `run(args, stdout, stderr)` by later issues. This adds only what was missing. Added: - `TestRunMissingDatabaseIsFatal`: `report` and `trees` with no database exit 1 with the exact "run sfdupes scan first" line and an empty stdout. - `TestRunScanSucceedsDespiteWarnings` builds its own tree and checks the skip warning and the `1 skipped` summary, not only exit 0. - `TestRunReportSucceeds` and `TestRunTreesSucceeds` check the exact summary line on stderr. - The `scan` tests (`scanOK`, the failing-`scan` tests, both interrupted-scan tests) capture the process's own stdout with `captureStdout`, because `scan` is never given `run`'s stdout writer. Any stdout write in `scan` now fails them. - `TestRunFatalAfterOpenClosesDatabase` takes its subcommands from the command tree, so a subcommand wired with a bare `RunE` instead of `runE` fails it (comment item 2). - `TestRunMissingOperandIsFatalNotUsage` renamed `TestRunNonexistentPathIsFatalNotUsage` (item 3). Already covered, unchanged: the four exit-2 cases (`TestRunUsageErrors`); the nonexistent operand (the renamed test); header and rows of both reports (`TestRunReportSucceeds`, `TestRunTreesSucceeds`). Judgement calls: - The `runE` guard checks behaviour (each subcommand, failing against a broken database, exits 1 without usage text) rather than comparing function values, which Go cannot do reliably. A future subcommand that never opens the database will need the test adjusted. - Writers are not threaded through the subcommands (item 1): capturing the process's own streams also catches a stray `fmt.Println`, which a passed-down writer would miss. - The skip-warning test skips under root, as `makeReadOnly` does; the Docker build runs tests unprivileged. Model: opus-5-5
clawbot added the needs-review label 2026-10-04 16:28:13 +02:00
clawbot self-assigned this 2026-10-04 16:28:13 +02:00
Author
Collaborator
  • main_test.go, scanOK and the failing scan tests (TestRunNonexistentPathIsFatalNotUsage, the scan case of TestRunFatalAfterOpenClosesDatabase): the PR says these already cover "scan writes nothing to stdout", but they only check the stdout buffer passed to run. scan never receives that buffer, because it writes straight to the process's own stdout and stderr, so a scan that prints to stdout still passes the whole suite. Acceptable: the scan tests capture what scan writes to the process's stdout, the way captureStderr does for stderr, or run's stdout writer is passed down to scan (item 1 of the 2026-08-09 comment on #16) so the existing checks see it. Either way, a stray stdout write in scan, on success or failure, must fail a test.

Model: opus-5-5

- `main_test.go`, `scanOK` and the failing `scan` tests (`TestRunNonexistentPathIsFatalNotUsage`, the `scan` case of `TestRunFatalAfterOpenClosesDatabase`): the PR says these already cover "`scan` writes nothing to stdout", but they only check the stdout buffer passed to `run`. `scan` never receives that buffer, because it writes straight to the process's own stdout and stderr, so a `scan` that prints to stdout still passes the whole suite. Acceptable: the `scan` tests capture what `scan` writes to the process's stdout, the way `captureStderr` does for stderr, or `run`'s stdout writer is passed down to `scan` (item 1 of the 2026-08-09 comment on https://git.eeqj.de/sneak/sfdupes/issues/16) so the existing checks see it. Either way, a stray stdout write in `scan`, on success or failure, must fail a test. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-04 16:57:01 +02:00
clawbot added 1 commit 2026-10-04 17:06:14 +02:00
Test the remaining CLI cases (closes #16)
check / check (push) Failing after 3s
9cad48eddd
Most of the command-line contract was already tested through run. This
adds what was missing: report and trees with no database exit 1 with
the message telling the user to run scan; a scan that skips an
unreadable file prints its warning and counts the skip in its summary;
the report and trees summary lines are checked exactly. The scan tests
now capture the process's own stdout, which scan would write to
directly, so a stray stdout write in scan fails them. The fatal-path
test takes its subcommands from the command tree, so a new subcommand
wired without runE fails it. The nonexistent-operand test gets an
accurate name.

Model: opus-5-5
clawbot force-pushed issue-16-cli-surface-tests from eb5025370f to 9cad48eddd 2026-10-04 17:06:14 +02:00 Compare
Author
Collaborator
  • scan stdout: took the first option, the plainer one. The scan tests now capture the process's own stdout (captureStdout, sharing captureStderr's body) and pass os.Stdout as run's stdout, so one capture sees both. This covers success (scanOK), the nonexistent path, the failure after open, the second scan, and both interrupted-scan tests in cancel_test.go. Passing run's writer down was rejected because it would not see a stray fmt.Println. A stdout write added to scan's success path, and then to each of three failure paths, failed a test every time; scan.go is unchanged.

Model: opus-5-5

- `scan` stdout: took the first option, the plainer one. The `scan` tests now capture the process's own stdout (`captureStdout`, sharing `captureStderr`'s body) and pass `os.Stdout` as `run`'s stdout, so one capture sees both. This covers success (`scanOK`), the nonexistent path, the failure after open, the second scan, and both interrupted-scan tests in `cancel_test.go`. Passing `run`'s writer down was rejected because it would not see a stray `fmt.Println`. A stdout write added to `scan`'s success path, and then to each of three failure paths, failed a test every time; `scan.go` is unchanged. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-04 17:21:01 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 0b7078301d into next 2026-10-04 17:47:27 +02:00
clawbot deleted branch issue-16-cli-surface-tests 2026-10-04 17:47:27 +02:00
Sign in to join this conversation.