testfile

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 10 Imported by: 0

README

yze-go-testfile

A yze analyzer (category testing) enforcing the gomatic Go testing standard that unit-test files are 1:1 with their source: <name>_test.go tests <name>.go. It exists because the 100%-coverage gate makes scattered <name><extra>_test.go files easy to introduce.

A _test.go file without a matching source file is flagged unless it is not a unit test:

  • it carries a build constraint (//go:build ... or the legacy // +build ...) — i.e. an integration test; or
  • it declares no Test functions — i.e. only examples, benchmarks, or fuzz targets.

Build constraints and Test declarations are recognized by parsing the file, not by substring matching, so a //go:build or func Test appearing inside a comment or string literal never changes the verdict.

The package directory is read from the filesystem, so the rule holds in production (where the driver does not load test files into the analysis pass).

  • Rule: yze/testfile
  • Binary: cmd/yze-go-testfile runs it standalone.

Built on the go-yze framework.

Documentation

Overview

Package testfile provides a go/analysis analyzer enforcing the gomatic Go testing standard that unit-test files are 1:1 with their source files: <name>_test.go tests <name>.go. A _test.go file without a matching source file is allowed only when it is not a unit test — it carries a build constraint (integration tests) or declares no Test functions (examples, benchmarks, fuzz targets).

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "testfile",
	Doc:  "reports _test.go unit-test files without a matching source file",
	Run:  run,
}

Analyzer reports unit-test files that are not 1:1 with a source file.

View Source
var Registration = goyze.Registration{
	Name:       "testfile",
	Categories: []goyze.Category{"testing"},
	URL:        "https://docs.gomatic.dev/yze/testfile",
	Analyzer:   Analyzer,
}

Registration declares this analyzer to the yze framework.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
yze-go-testfile command
Command yze-go-testfile runs the testfile analyzer as a standalone go/analysis checker (text and -json output, and as a `go vet -vettool`).
Command yze-go-testfile runs the testfile analyzer as a standalone go/analysis checker (text and -json output, and as a `go vet -vettool`).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL