Skip to content

Use testify in the internal tests - #169

Merged
crhntr merged 23 commits into
mainfrom
test/testify-readability
Sep 30, 2026
Merged

crhntr merged 23 commits into
mainfrom
test/testify-readability

Conversation

@crhntr

@crhntr crhntr commented Sep 30, 2026

Copy link
Copy Markdown
Member

Converts the tests under internal/ from hand-rolled if got != want { t.Errorf(...) } checks to testify, package by package, and makes the ones that were hard to follow easier to read. Only _test.go files change: no non-test file, nothing under cmd/, and no testdata or snapshot archive.

Conversion

  • t.Errorf became assert, and t.Fatal became require, so a check that used to continue still continues and one that stopped still stops.
  • No assertion was removed or loosened. Exact error-string checks stay exact, expected values come first, and failure messages still name the input.
  • Loops and sequential blocks that checked several unrelated things became named subtests; repeated setup moved into small helpers.
  • The snapshot harnesses keep their -update behavior and file layout.
  • configurations_test.go, header_test.go and other files that already used testify consistently were left alone.

TestTypeFormatter is now eight one-behavior subtests, each with its own formatter, covering the nil and output package, the numeric suffix, the memoized name, skipping declared names, same-named packages, the sorted import declaration, and the JSON key order.

Coverage and mutation testing

For every internal package I compared per-function go tool cover -func output before and after. It is identical for all eleven, so no function lost coverage. Gremlins gives the same killed, lived and not-covered counts as before the change:

Package Killed Lived Not covered
muxt 352 0 17
generate 135 0 3
cli 157 4 0
analysis 103 0 4
astgen 46 0 0
load 59 8 1
header 12 0 0
fakeserver 9 0 0
mutation 148 13 6

mutation was run on its main source files only, because each mutant costs a full test suite. The full suite passes with -race -shuffle=on.

Tests that checked less than they looked like

Fixed as part of the conversion:

  • The check that a TypeFormatter keeps the name it assigned could not tell memoization from recomputation; it now also runs after the declared names change.
  • TestReportTrims asserted nothing; it now asserts that it does not panic.
  • TestWalkActionsOrder and TestWalkActionsNarrowsDot joined slices into strings before comparing; they now compare the slices.
  • TestNearestString skipped its suggestion check when nothing matched.
  • TestDecisionRefusesWhatItCannotModel made an unchecked type assertion that would panic.
  • TestImports passed got and want the wrong way round.

Left as they were, because removing a case would change what is tested:

  • TestVersionCommand never checks its error when the CLI version is known.
  • TestTemplateName_ByPathThenMethod repeats one case verbatim, and one case in that file has a no-op assertion.
  • Two subtests in TestNewTemplateName share a name.

🤖 Generated with Claude Code

Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Each subtest builds its own formatter, since Qualifier memoizes the name it
assigned per import path. The memoization sequence stays in one subtest.

Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
TestImports compared got and want the wrong way round; the expected value
now comes first.

Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
The snapshot mismatch message had a %s with no argument; it now names the
want/ file.

Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
Assisted-by: Claude:claude-sonnet-5-5 gofumpt goimports staticcheck gremlins
@crhntr
crhntr merged commit 41f1108 into main Sep 30, 2026
2 checks passed
@crhntr
crhntr deleted the test/testify-readability branch September 30, 2026 01:21
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.

1 participant