Help us shape the future of Go! Take the 2026 Go Developer Survey

tenv

package module
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 6 Imported by: 11

README

tenv

tenv Gopher

test_and_lint

tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17

Instruction

go install github.com/sivchari/tenv/cmd/tenv@latest

Usage

package main

import (
	"fmt"
	"os"
	"testing"
)

func TestMain(t *testing.T) {
	fmt.Println(os.Getenv("GO"))
	os.Setenv("GO", "HACKING GOPHER")
}

func TestMain2(t *testing.T) {
	fmt.Println(os.Getenv("GO"))
}

func helper() {
	os.Setenv("GO", "HACKING GOPHER")
}
go vet -vettool=$(which tenv) ./...

# a
./main_test.go:11:2: os.Setenv() can be replaced by `t.Setenv()` in TestMain
option

The option all will run against whole test files (_test.go) regardless of method/function signatures.

By default, only methods that take *testing.T, *testing.B, and testing.TB as arguments are checked.

package main

import (
	"fmt"
	"os"
	"testing"
)

func TestMain(t *testing.T) {
	fmt.Println(os.Getenv("GO"))
	os.Setenv("GO", "HACKING GOPHER")
}

func TestMain2(t *testing.T) {
	fmt.Println(os.Getenv("GO"))
}

func helper() {
	os.Setenv("GO", "HACKING GOPHER")
}
go vet -vettool=$(which tenv) -tenv.all ./...

# a
./main_test.go:11:2: os.Setenv() can be replaced by `t.Setenv()` in TestMain
./main_test.go:19:2: os.Setenv() can be replaced by `testing.Setenv()` in helper

CI

CircleCI
- run:
    name: install tenv
    command: go install github.com/sivchari/tenv@latest

- run:
    name: run tenv
    command: go vet -vettool=`which tenv` ./...
GitHub Actions
- name: install tenv
  run: go install github.com/sivchari/tenv@latest

- name: run tenv
  run: go vet -vettool=`which tenv` ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	A = "all"
)
View Source
var Analyzer = &analysis.Analyzer{
	Name: "tenv",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Analyzer is tenv analyzer

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
tenv command

Jump to

Keyboard shortcuts

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