Skip to content

chore: fix panicking benchmarks#1648

Merged
alexandear merged 7 commits intomgechev:masterfrom
alexandear:chore/fix-benchmarks
Feb 21, 2026
Merged

chore: fix panicking benchmarks#1648
alexandear merged 7 commits intomgechev:masterfrom
alexandear:chore/fix-benchmarks

Conversation

@alexandear
Copy link
Copy Markdown
Collaborator

@alexandear alexandear commented Feb 21, 2026

Logs before

go test -run=^$ -bench . -benchmem -count=1 ./...
?       github.com/mgechev/revive       [no test files]
PASS
ok      github.com/mgechev/revive/cli   0.219s
PASS
ok      github.com/mgechev/revive/config        0.173s
PASS
ok      github.com/mgechev/revive/formatter     0.177s
?       github.com/mgechev/revive/internal/astutils     [no test files]
PASS
ok      github.com/mgechev/revive/internal/ifelse       0.152s
PASS
ok      github.com/mgechev/revive/internal/rule 0.152s
?       github.com/mgechev/revive/internal/typeparams   [no test files]
PASS
ok      github.com/mgechev/revive/lint  0.155s
PASS
ok      github.com/mgechev/revive/logging       0.152s
PASS
ok      github.com/mgechev/revive/revivelib     0.349s
PASS
ok      github.com/mgechev/revive/rule  0.334s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100df53dc]

goroutine 33 [running]:
github.com/mgechev/revive/test_test.testRule(0x0, {0x100e101af, 0x16}, {0x1011568c0, 0x20cdd39a64e0}, {0x20cdd3aa6ef0, 0x1, 0x30000007d?})
        /Users/alexandear/src/github.com/mgechev/revive/test/utils_test.go:37 +0x3c
github.com/mgechev/revive/test_test.BenchmarkArgumentsLimit(0x20cdd3b46308)
        /Users/alexandear/src/github.com/mgechev/revive/test/argument_limit_test.go:23 +0x84
testing.(*B).runN(0x20cdd3b46308, 0x1)
        /opt/homebrew/Cellar/go/1.26.0/libexec/src/testing/benchmark.go:219 +0x180
testing.(*B).run1.func1()
        /opt/homebrew/Cellar/go/1.26.0/libexec/src/testing/benchmark.go:245 +0x48
created by testing.(*B).run1 in goroutine 1
        /opt/homebrew/Cellar/go/1.26.0/libexec/src/testing/benchmark.go:238 +0x88
exit status 2
FAIL    github.com/mgechev/revive/test  0.323s
FAIL

Logs after

go test -run=^$ -bench . -benchmem -count=1 ./...
?       github.com/mgechev/revive       [no test files]
PASS
ok      github.com/mgechev/revive/cli   0.228s
PASS
ok      github.com/mgechev/revive/config        0.174s
PASS
ok      github.com/mgechev/revive/formatter     0.176s
?       github.com/mgechev/revive/internal/astutils     [no test files]
PASS
ok      github.com/mgechev/revive/internal/ifelse       0.158s
PASS
ok      github.com/mgechev/revive/internal/rule 0.156s
?       github.com/mgechev/revive/internal/typeparams   [no test files]
PASS
ok      github.com/mgechev/revive/lint  0.318s
PASS
ok      github.com/mgechev/revive/logging       0.246s
PASS
ok      github.com/mgechev/revive/revivelib     0.188s
PASS
ok      github.com/mgechev/revive/rule  0.172s
goos: darwin
goarch: arm64
pkg: github.com/mgechev/revive/test
cpu: Apple M4 Pro
BenchmarkArgumentsLimit-12                 21960             53291 ns/op           27340 B/op        322 allocs/op
BenchmarkLintFileHeader-12                 28952             42611 ns/op           16669 B/op        156 allocs/op
BenchmarkImportsBlocklist-12               14158             84881 ns/op           69823 B/op        572 allocs/op
BenchmarkUnusedParam-12                     4429            246618 ns/op          256929 B/op       6294 allocs/op
BenchmarkUnusedReceiver-12                 13582             88475 ns/op           56706 B/op       1104 allocs/op
BenchmarkUpperCaseConstTrue-12                 5         235795333 ns/op         2382774 B/op      17573 allocs/op
PASS
ok      github.com/mgechev/revive/test  7.403s

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses panics in the test package benchmarks and stabilizes formatter output in tests, while also adding convenient benchmark entry points via make bench and CI.

Changes:

  • Fix benchmark helpers to use testing.TB and update benchmarks to call testRule with *testing.B (avoids nil *testing.T panics).
  • Make formatter tests deterministic by disabling ANSI color output and adjust the Friendly formatter to honor color.NoColor at call time.
  • Add benchmark execution to the Makefile and GitHub Actions workflow.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/utils_test.go Generalize helper APIs from *testing.T to testing.TB to support both tests and benchmarks safely.
test/argument_limit_test.go Update benchmark to use b.Loop() and pass b into testRule.
test/file_header_test.go Update benchmark loop and pass b into testRule.
test/imports_blocklist_test.go Update benchmark loop and pass b into testRule.
test/unused_param_test.go Update benchmark loop and pass b into testRule.
test/unused_receiver_test.go Update benchmark loop and pass b into testRule.
test/var_naming_test.go Update benchmark loop and pass b into testRule.
formatter/friendly.go Compute colored markers/headers at use-time so color.NoColor changes are respected.
formatter/formatter_test.go Disable color output during formatter golden-output assertions.
Makefile Add bench target for running benchmarks.
.github/workflows/test.yaml Add a CI step to run benchmarks.

Comment thread formatter/formatter_test.go Outdated
Comment thread .github/workflows/test.yaml Outdated
Comment thread Makefile Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/test.yaml Outdated
@alexandear alexandear merged commit 6a72f8d into mgechev:master Feb 21, 2026
9 checks passed
@alexandear alexandear deleted the chore/fix-benchmarks branch February 21, 2026 17:23
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.

4 participants