Skip to content

Revive doesn't analyze tests in separate _test packages #1357

Closed
@alexandear

Description

@alexandear

Describe the bug

revive ignores tests located in _test packages and doesn't analyze them.

To Reproduce

Steps to reproduce the behavior:

  1. Consider the following project with any tests in a _test package:
Details

❯ tree .
.
├── bugtestpkg_test.go
├── bugtestpkg.go
└── go.mod

1 directory, 3 files
-- go.mod --
module bugtestpkg

go 1.23

-- bugtestpkg.go --
// Package bugtestpkg is a package.
package bugtestpkg

// Add returns a + b.
func Add(a, b int) int {
        return a + b
}

-- bugtestpkg_test.go --
package bugtestpkg_test

import (
        "bugtestpkg"
        "testing"
)

func Id() {}

func TestAdd(t *testing.T) {
        if bugtestpkg.Add(1, 2) != 3 {
                t.FailNow()
        }
}

  1. Run the latest revive without any configuration:
revive ./...

Expected behavior

There should be one warning:

bugtestpkg_test.go:7:6: func Id should be ID

Actual behavior

No warnings are reported.

Desktop

Details

❯ go env
AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/alexandear/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/alexandear/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/q0/5_z6pvw574z1c0zcrr2xvk0r0000gn/T/go-build1859025823=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/alexandear/src/github.com/mgechev/revive/bugtestpkg/go.mod'
GOMODCACHE='/Users/alexandear/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/alexandear/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.3/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/alexandear/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

Additional context

First noticed in #1353.

Golangci-lint correctly detects the issue:

❯ golangci-lint run --enable-only revive
bugtestpkg/bugtestpkg_test.go:8:6: var-naming: func Id should be ID (revive)
func Id() {}
     ^
1 issues:
* revive: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions