sivchari / tenv

tenv detects environment variable not using t.Setenv
MIT License
23 stars 7 forks source link

panic in table-driven tests #21

Closed jacobbogdanov closed 2 years ago

jacobbogdanov commented 2 years ago
package tenv_test

import (
    "testing"
)

func TestTenv(t *testing.T) {
    t.Run("test", func(*testing.T) { })
}

running version 1.47.0 of golangci-lint

$ golangci-lint run --disable-all --enable tenv tenv_test.go

ERRO [runner] Panic: tenv: package "tenv_test" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0: goroutine 268 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x155
panic({0x1bd22a0, 0xc0005a4000})
        runtime/panic.go:838 +0x207
github.com/sivchari/tenv.targetRunner({0xc00021a060, 0x1, 0x1?}, {0xc001495e60, 0x25})
        github.com/sivchari/tenv@v1.6.0/tenv.go:166 +0x3e5
github.com/sivchari/tenv.checkFuncLit(0xc00020ccc0?, 0xc0002060b0, {0xc001495e60?, 0x0?})
        github.com/sivchari/tenv@v1.6.0/tenv.go:62 +0x4e
github.com/sivchari/tenv.run.func1({0x1e86290?, 0xc0002060b0?})
        github.com/sivchari/tenv@v1.6.0/tenv.go:46 +0x105
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc000eee258, {0xc00094ad18?, 0x2?, 0xc00094ad28?}, 0xc0017c9d08)
        golang.org/x/tools@v0.1.11/go/ast/inspector/inspector.go:77 +0x9a
github.com/sivchari/tenv.run(0xc0007fc680)
        github.com/sivchari/tenv@v1.6.0/tenv.go:41 +0xa5
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc000120000)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x1d
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00011e190, {0x1c2e909, 0x4}, 0xc00094af48)
        github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc001c5f860?)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x85
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc000120000)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1eb 
WARN [runner] Can't run linter tenv: tenv: tenv: package "tenv_test" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0 
ERRO Running error: 1 error occurred:
        * can't run linter tenv: tenv: tenv: package "tenv_test" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0
sivchari commented 2 years ago

I fixed it, thanks.