Skip to content

Start each cobra run in the cli tests with the usage block on, and put the pipeline flags back when a test ends (#43) - #44

Merged
thebenignhacker merged 1 commit into
mainfrom
integrate/2026-10-20-r2
Oct 20, 2026
Merged

thebenignhacker merged 1 commit into
mainfrom
integrate/2026-10-20-r2

Conversation

@thebenignhacker

Copy link
Copy Markdown
Member

This pull request lands 1 commit in internal/cli.

Included

Verified on this exact tree

  • go build -v ./...: exit 0
  • go vet ./...: exit 0
  • gofmt -l ./internal ./pkg ./cmd: no files listed
  • golangci-lint run --concurrency 4 ./... (golangci-lint 2.12.2): exit 1, 21 issues (errcheck: 15, staticcheck: 6); pre-existing: the same command in a worktree of origin/main (0fb15c5) prints the same 21 issues by file and message
  • go test -race -count=1 -p 4 -json ./...: exit 0; 9 packages: 8 ok, 1 with no test files; top-level tests: 311 passed, 0 failed, 0 skipped; subtests: 740 passed, 0 failed, 0 skipped
  • Changelog check, TestChangelogEntries and TestChangelogSaysWhereSARIFAndCSVCarryTheCryptoJSText in pkg/reporter (in the run above): passed
  • go test -count=1 -shuffle=1792442745693168000 ./internal/cli: ok
  • internal/cli test binary from go test -c, run with -test.count=1 -test.shuffle=N for N from 1 to 40: 40 runs, 0 failed

Not included

None

Closes

Fixes #43

How to merge

Rebase and merge, so that each change stays its own commit on main.

…t the pipeline flags back when a test ends (#43)

scanPipeline turns the usage block off on the command it runs, and in the
test binary scanCmd kept that setting after executeScan, runScanWith and
the tests that call scanTarget(scanCmd, ...) directly. When one of them ran
before TestUsageErrorsStillPrintUsage with no executeRoot test in between,
cobra printed only "Error: accepts 1 arg(s), received 0" and the test
failed. executeRoot and executeScan now turn the usage block back on before
they run the command, and executeScan also turns it back on when its test
ends, as executeRoot already did.

resetPipelineFlags put only outputFormat and outputFile back when a test
ended. The two skipped-file tests set failOn to "low" after calling it, and
TestRunScanExcludesFromFlagConfigAndDefaults, run directly after either of
them, ended the test binary with exit code 1 inside runScan.
resetPipelineFlags now puts back every variable it sets when the test ends,
as well as when it starts.

Two tests cover this: a usage error through executeRoot or executeScan
prints the usage block after a scan through executeScan or runScanWith,
and resetPipelineFlags puts failOn and four other variables back when a
test ends. Both failed before this change.

go test -count=1 -shuffle=1792442745693168000 ./internal/cli, which failed
before, passes. Shuffle seeds 1 to 40 failed 27 times on the previous
commit; seeds 1 to 300 pass, and each of the 102 top-level tests passes
when it runs directly after any other one.

Fixes #43
@thebenignhacker
thebenignhacker merged commit 881bc8f into main Oct 20, 2026
4 checks passed
@thebenignhacker
thebenignhacker deleted the integrate/2026-10-20-r2 branch October 20, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestUsageErrorsStillPrintUsage fails when it runs after a test that uses executeScan

1 participant