Skip to content

false deadcode positive for main_test.go files #131

Closed
@cloudlena

Description

@cloudlena

deadcode produces false positives if there is a main_test.go file which is part of the main package. To reproduce, create the following files:

main.go:

package main

import "fmt"

func main() {
	fmt.Println("derp")
}

main_test.go:

package main

import (
	"fmt"
	"testing"
)

func TestMain(t *testing.T) {
	fmt.Println("herp")
}

This produces the following error message when running golangci-lint run:

main_test.go:8:6: `TestMain` is unused (deadcode)
func TestMain(t *testing.T) {
     ^

The false positive doesn't occur, if the package of the testing file is changed to main_test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    false positiveAn error is reported when one does not exist

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions