Skip to content

Commit f121264

Browse files
committed
fix readme
1 parent d8ea6ba commit f121264

File tree

3 files changed

+51
-55
lines changed

3 files changed

+51
-55
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
1313

14+
.idea
15+
1416
# Dependency directories (remove the comment below to include it)
1517
# vendor/

README.md

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# tenv
2+
3+
![tenv Gopher](./tenv.png "Gopher")
4+
25
tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
36

47
[![test_and_lint](https://github.com/sivchari/tenv/actions/workflows/workflows.yml/badge.svg?branch=main)](https://github.com/sivchari/tenv/actions/workflows/workflows.yml)
@@ -12,79 +15,70 @@ go install github.com/sivchari/tenv/cmd/tenv
1215
## Usage
1316

1417
```go
15-
package sandbox_test
18+
package main
1619

1720
import (
18-
"os"
19-
"testing"
21+
"fmt"
22+
"os"
23+
"testing"
2024
)
2125

22-
var (
23-
e = os.Setenv("a", "b")
24-
_ = e
25-
)
26+
func TestMain(t *testing.T) {
27+
fmt.Println(os.Getenv("GO"))
28+
os.Setenv("GO", "HACKING GOPHER")
29+
}
2630

27-
func setup() {
28-
os.Setenv("a", "b")
29-
err := os.Setenv("a", "b")
30-
if err != nil {
31-
_ = err
32-
}
31+
func TestMain2(t *testing.T) {
32+
fmt.Println(os.Getenv("GO"))
3333
}
3434

35-
func TestF(t *testing.T) {
36-
setup()
37-
os.Setenv("a", "b")
38-
if err := os.Setenv("a", "b"); err != nil {
39-
_ = err
40-
}
35+
func helper() {
36+
os.Setenv("GO", "HACKING GOPHER")
4137
}
4238
```
4339

44-
### fish
45-
4640
```console
47-
go vet -vettool=(which tenv) sandbox_test.go
48-
49-
# command-line-arguments
50-
./sandbox_test.go:9:2: variable e is not using t.Setenv
51-
./sandbox_test.go:14:2: func setup is not using t.Setenv
52-
./sandbox_test.go:15:2: func setup is not using t.Setenv
53-
./sandbox_test.go:23:2: func TestF is not using t.Setenv
54-
./sandbox_test.go:24:2: func TestF is not using t.Setenv
55-
```
56-
57-
### bash
41+
go vet -vettool=(which tenv) ./...
5842

59-
```console
60-
$ go vet -vettool=`which tenv` main.go
61-
62-
# command-line-arguments
63-
./sandbox_test.go:9:2: variable e is not using t.Setenv
64-
./sandbox_test.go:14:2: func setup is not using t.Setenv
65-
./sandbox_test.go:15:2: func setup is not using t.Setenv
66-
./sandbox_test.go:23:2: func TestF is not using t.Setenv
67-
./sandbox_test.go:24:2: func TestF is not using t.Setenv
43+
# a
44+
./main_test.go:11:2: os.Setenv() can be replaced by `t.Setenv()` in TestMain
6845
```
6946

7047
### option
7148

72-
t.Setenv can use since Go1.17.
73-
This linter diagnostics, if Go version is since 1.17.
74-
But, if you wanna exec this linter in prior Go1.17, you can use it that you set `-tenv.f` flag.
49+
The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
7550

76-
e.g.
51+
By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
7752

78-
### fish
53+
```go
54+
package main
7955

80-
```console
81-
go vet -vettool=(which tenv) -tenv.f sandbox_test.go
82-
```
56+
import (
57+
"fmt"
58+
"os"
59+
"testing"
60+
)
61+
62+
func TestMain(t *testing.T) {
63+
fmt.Println(os.Getenv("GO"))
64+
os.Setenv("GO", "HACKING GOPHER")
65+
}
8366

84-
### bash
67+
func TestMain2(t *testing.T) {
68+
fmt.Println(os.Getenv("GO"))
69+
}
70+
71+
func helper() {
72+
os.Setenv("GO", "HACKING GOPHER")
73+
}
74+
```
8575

8676
```console
87-
go vet -vettool=`which tenv` -tenv.f main.go
77+
go vet -vettool=(which tenv) -tenv.all ./...
78+
79+
# a
80+
./main_test.go:11:2: os.Setenv() can be replaced by `t.Setenv()` in TestMain
81+
./main_test.go:19:2: os.Setenv() can be replaced by `testing.Setenv()` in helper
8882
```
8983

9084
## CI
@@ -93,20 +87,20 @@ go vet -vettool=`which tenv` -tenv.f main.go
9387

9488
```yaml
9589
- run:
96-
name: Install tenv
90+
name: install tenv
9791
command: go install github.com/sivchari/tenv
9892

9993
- run:
100-
name: Run tenv
94+
name: run tenv
10195
command: go vet -vettool=`which tenv` ./...
10296
```
10397
10498
### GitHub Actions
10599
106100
```yaml
107-
- name: Install tenv
101+
- name: install tenv
108102
run: go install github.com/sivchari/tenv
109103

110-
- name: Run tenv
104+
- name: run tenv
111105
run: go vet -vettool=`which tenv` ./...
112106
```

tenv.png

241 KB
Loading

0 commit comments

Comments
 (0)