tenv detects environment variable not using t.Setenv
MIT License
Bot releases are hidden (Show)
Full Changelog: https://github.com/sivchari/tenv/compare/v1.9.1...v1.10.0
Published by sivchari 4 months ago
Full Changelog: https://github.com/sivchari/tenv/compare/v1.9.0...v1.9.1
Published by sivchari 5 months ago
Full Changelog: https://github.com/sivchari/tenv/compare/v1.8.1...v1.9.0
Published by sivchari over 2 years ago
Published by sivchari over 2 years ago
This release handles to diagnose testing.F in Go1.18.
Published by sivchari about 3 years ago
package main
import (
"os"
"testing"
)
var (
ee = os.Setenv("a", "b") // never seen
)
func setup() {
os.Setenv("a", "b") // never seen
err := os.Setenv("a", "b") // never seen
if err != nil {
_ = err
}
os.Setenv("a", "b") // never seen
}
func F(t *testing.T) {
setup()
os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in F"
err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in F"
_ = err
if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in F"
_ = err
}
}
func BF(b *testing.B) {
TBF(b)
os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BF"
err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BF"
_ = err
if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BF"
_ = err
}
}
func TBF(tb testing.TB) {
os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in TBF"
err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in TBF"
_ = err
if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in TBF"
_ = err
}
}
package main_test
import (
"os"
"testing"
)
var (
e = os.Setenv("a", "b") // never seen
)
func testsetup() {
os.Setenv("a", "b") // if -all = true, want "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in testsetup"
err := os.Setenv("a", "b") // if -all = true, want "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in testsetup"
if err != nil {
_ = err
}
os.Setenv("a", "b") // if -all = true, "func setup is not using testing.Setenv"
}
func TestF(t *testing.T) {
testsetup()
os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
_ = err
if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF"
_ = err
}
}
func BenchmarkF(b *testing.B) {
TB(b)
os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
_ = err
if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF"
_ = err
}
}
func TB(tb testing.TB) {
os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in TB"
err := os.Setenv("a", "b") // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in TB"
_ = err
if err := os.Setenv("a", "b"); err != nil { // want "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in TB"
_ = err
}
}
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
You can use all to check all methods.
By default, only methods that take *testing.T, *testing.B, and testing.TB as arguments are checked.
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago
Published by sivchari about 3 years ago