Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic when empty test function without t name #27

Merged
merged 2 commits into from
May 30, 2023
Merged

fix panic when empty test function without t name #27

merged 2 commits into from
May 30, 2023

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Mar 29, 2023

The PR fixes panic when running paralleltest on an empty test function without t.

This bug was discovered when running golangci-lint run --disable-all --no-config --enable=paralleltest runtime/logging/source_test.go in ServiceWeaver/weaver on the following lines:

func TestDontShowWholeFile(*testing.T) {}

Without the change test TestIgnoreMissing panics:

Running tool: /usr/local/bin/go test -timeout 30s -run ^TestIgnoreMissing$ github.com/kunwardeep/paralleltest/pkg/paralleltest -count=1 -v -race

=== RUN   TestIgnoreMissing
=== PAUSE TestIgnoreMissing
=== CONT  TestIgnoreMissing
panic: runtime error: index out of range [0] with length 0

goroutine 1124 [running]:
github.com/kunwardeep/paralleltest/pkg/paralleltest.isTestFunction(0xc00abf7ce0)
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go:252 +0x393
github.com/kunwardeep/paralleltest/pkg/paralleltest.run.func1({0x14ed048?, 0xc00abf7ce0?})
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go:58 +0x1b8
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc007bcb890, {0xc007bcb880?, 0x1, 0x1?}, 0xc007bcb8a8)
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/vendor/golang.org/x/tools/go/ast/inspector/inspector.go:77 +0x103
github.com/kunwardeep/paralleltest/pkg/paralleltest.run(0xc00b962410)
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go:47 +0x1c6
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc00b8e70e0)
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:728 +0x1a25
sync.(*Once).doSlow(0xc00b8e70e0, 0xc000611f68)
	/usr/local/Cellar/go/1.20.1/libexec/src/sync/once.go:74 +0x102
sync.(*Once).Do(0xc00b8e70e0, 0x10bfbd9?)
	/usr/local/Cellar/go/1.20.1/libexec/src/sync/once.go:65 +0x47
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc00b8e70e0)
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:616 +0x4d
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0x0?)
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:604 +0x36
created by golang.org/x/tools/go/analysis/internal/checker.execAll
	/Users/redko.o/src/github.com/kunwardeep/paralleltest/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:610 +0x22f
FAIL	github.com/kunwardeep/paralleltest/pkg/paralleltest	2.325s

@kunwardeep
Copy link
Owner

I am unsure why the tests have not been kicked off for this branch.. I'll need to investigate

@kunwardeep kunwardeep merged commit 1ab3f5c into kunwardeep:main May 30, 2023
@alexandear alexandear deleted the fix-panic-when-missing-t branch May 30, 2023 07:58
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.

2 participants