Skip to content

Commit 463e125

Browse files
committed
add more integration tests
1 parent 152c26e commit 463e125

9 files changed

+574
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//golangcitest:args -Ettempdir
2+
package testdata
3+
4+
import (
5+
"io/ioutil"
6+
"testing"
7+
)
8+
9+
var (
10+
_, ee = ioutil.TempDir("a", "b") // never seen
11+
)
12+
13+
func setup() {
14+
ioutil.TempDir("a", "b") // never seen
15+
_, err := ioutil.TempDir("a", "b") // never seen
16+
if err != nil {
17+
_ = err
18+
}
19+
ioutil.TempDir("a", "b") // never seen
20+
}
21+
22+
func F(t *testing.T) {
23+
setup()
24+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
25+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
26+
_ = err
27+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
28+
_ = err
29+
}
30+
}
31+
32+
func BF(b *testing.B) {
33+
TBF(b)
34+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
35+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
36+
_ = err
37+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
38+
_ = err
39+
}
40+
}
41+
42+
func TBF(tb testing.TB) {
43+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
44+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
45+
_ = err
46+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
47+
_ = err
48+
}
49+
}
50+
51+
func FF(f *testing.F) {
52+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
53+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
54+
_ = err
55+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
56+
_ = err
57+
}
58+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//golangcitest:args -Ettempdir
2+
package testdata
3+
4+
import (
5+
"io/ioutil"
6+
"testing"
7+
)
8+
9+
var (
10+
_, e = ioutil.TempDir("a", "b") // never seen
11+
)
12+
13+
func testsetup() {
14+
ioutil.TempDir("a", "b") // if -all = true, want "ioutil\\.TempDir\\(\\) should be replaced by `testing\\.TempDir\\(\\)` in testsetup"
15+
_, err := ioutil.TempDir("a", "b") // if -all = true, want "ioutil\\.TempDir\\(\\) should be replaced by `testing\\.TempDir\\(\\)` in testsetup"
16+
if err != nil {
17+
_ = err
18+
}
19+
ioutil.TempDir("a", "b") // if -all = true, "func setup is not using testing.TempDir"
20+
}
21+
22+
func TestF(t *testing.T) {
23+
testsetup()
24+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF"
25+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF"
26+
_ = err
27+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF"
28+
_ = err
29+
}
30+
}
31+
32+
func BenchmarkF(b *testing.B) {
33+
TB(b)
34+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF"
35+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF"
36+
_ = err
37+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF"
38+
_ = err
39+
}
40+
}
41+
42+
func TB(tb testing.TB) {
43+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB"
44+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB"
45+
_ = err
46+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB"
47+
_ = err
48+
}
49+
}
50+
51+
func FuzzF(f *testing.F) {
52+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF"
53+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF"
54+
_ = err
55+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF"
56+
_ = err
57+
}
58+
}
59+
60+
func TestFunctionLiteral(t *testing.T) {
61+
testsetup()
62+
t.Run("test", func(t *testing.T) {
63+
ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
64+
_, err := ioutil.TempDir("a", "b") // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
65+
_ = err
66+
if _, err := ioutil.TempDir("a", "b"); err != nil { // want "ioutil\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
67+
_ = err
68+
}
69+
})
70+
}
71+
72+
func TestEmpty(t *testing.T) {
73+
t.Run("test", func(*testing.T) {})
74+
}
75+
76+
func TestEmptyTB(t *testing.T) {
77+
func(testing.TB) {}(t)
78+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//golangcitest:args -Ettempdir
2+
package testdata
3+
4+
import (
5+
"os"
6+
"testing"
7+
)
8+
9+
var (
10+
_, ee = os.MkdirTemp("a", "b") // never seen
11+
)
12+
13+
func setup() {
14+
os.MkdirTemp("a", "b") // never seen
15+
_, err := os.MkdirTemp("a", "b") // never seen
16+
if err != nil {
17+
_ = err
18+
}
19+
os.MkdirTemp("a", "b") // never seen
20+
}
21+
22+
func F(t *testing.T) {
23+
setup()
24+
os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
25+
_, err := os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
26+
_ = err
27+
if _, err := os.MkdirTemp("a", "b"); err != nil { // want "os\\.MkdirTemp\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
28+
_ = err
29+
}
30+
31+
_ = func(t *testing.T) {
32+
_ = t
33+
_, _ = os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
34+
}
35+
36+
t.Cleanup(func() {
37+
_, _ = os.MkdirTemp("a", "b")
38+
})
39+
}
40+
41+
func BF(b *testing.B) {
42+
TBF(b)
43+
os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
44+
_, err := os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
45+
_ = err
46+
if _, err := os.MkdirTemp("a", "b"); err != nil { // want "os\\.MkdirTemp\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
47+
_ = err
48+
}
49+
50+
func(b *testing.B) {
51+
_ = b
52+
_, _ = os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `b\\.TempDir\\(\\)` in anonymous function"
53+
}(b)
54+
}
55+
56+
func TBF(tb testing.TB) {
57+
os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
58+
_, err := os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
59+
_ = err
60+
if _, err := os.MkdirTemp("a", "b"); err != nil { // want "os\\.MkdirTemp\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
61+
_ = err
62+
}
63+
64+
defer func(tb testing.TB) {
65+
_ = tb
66+
_, _ = os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in anonymous function"
67+
}(tb)
68+
}
69+
70+
func FF(f *testing.F) {
71+
os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
72+
_, err := os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
73+
_ = err
74+
if _, err := os.MkdirTemp("a", "b"); err != nil { // want "os\\.MkdirTemp\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
75+
_ = err
76+
}
77+
78+
defer os.MkdirTemp("a", "b") // want "os\\.MkdirTemp\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
79+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//golangcitest:args -Ettempdir
2+
package testdata
3+
4+
import (
5+
"os"
6+
"testing"
7+
)
8+
9+
var (
10+
dir = os.TempDir() // never seen
11+
)
12+
13+
func setup() {
14+
os.TempDir() // never seen
15+
dir := os.TempDir() // never seen
16+
_ = dir
17+
_ = os.TempDir() // never seen
18+
}
19+
20+
func F(t *testing.T) {
21+
setup()
22+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
23+
t.Log(os.TempDir()) // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
24+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
25+
if dir := os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in F"
26+
_ = dir
27+
}
28+
}
29+
30+
func BF(b *testing.B) {
31+
TBF(b)
32+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
33+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
34+
if dir := os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BF"
35+
_ = dir
36+
}
37+
}
38+
39+
func TBF(tb testing.TB) {
40+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
41+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
42+
if dir := os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TBF"
43+
_ = dir
44+
}
45+
}
46+
47+
func FF(f *testing.F) {
48+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
49+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
50+
if dir := os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FF"
51+
_ = dir
52+
}
53+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//golangcitest:args -Ettempdir
2+
package testdata
3+
4+
import (
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
"testing"
9+
)
10+
11+
var (
12+
tdir = os.TempDir() // never seen
13+
)
14+
15+
func testsetup() {
16+
os.TempDir() // if -all = true, want "os\\.TempDir\\(\\) should be replaced by `testing\\.TempDir\\(\\)` in testsetup"
17+
dir := os.TempDir() // if -all = true, want "os\\.TempDir\\(\\) should be replaced by `testing\\.TempDir\\(\\)` in testsetup"
18+
_ = dir
19+
_ = os.TempDir() // if -all = true, "func setup is not using testing.TempDir"
20+
}
21+
22+
func TestF(t *testing.T) {
23+
testsetup()
24+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF"
25+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF"
26+
if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF"
27+
_ = dir
28+
}
29+
}
30+
31+
func BenchmarkF(b *testing.B) {
32+
TB(b)
33+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF"
34+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF"
35+
if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF"
36+
_ = dir
37+
}
38+
}
39+
40+
func TB(tb testing.TB) {
41+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB"
42+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB"
43+
if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB"
44+
_ = dir
45+
}
46+
}
47+
48+
func FuzzF(f *testing.F) {
49+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF"
50+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF"
51+
if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF"
52+
_ = dir
53+
}
54+
}
55+
56+
func TestFunctionLiteral(t *testing.T) {
57+
testsetup()
58+
t.Run("test", func(t *testing.T) {
59+
os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
60+
_ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
61+
if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function"
62+
_ = dir
63+
}
64+
})
65+
}
66+
67+
func TestEmpty(t *testing.T) {
68+
t.Run("test", func(*testing.T) {})
69+
}
70+
71+
func TestEmptyTB(t *testing.T) {
72+
func(testing.TB) {}(t)
73+
}
74+
75+
func TestRecursive(t *testing.T) {
76+
t.Log( // recursion level 1
77+
os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive"
78+
)
79+
t.Log( // recursion level 1
80+
fmt.Sprintf("%s", // recursion level 2
81+
os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive"
82+
),
83+
)
84+
t.Log( // recursion level 1
85+
filepath.Clean( // recursion level 2
86+
fmt.Sprintf("%s", // recursion level 3
87+
os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive"
88+
),
89+
),
90+
)
91+
t.Log( // recursion level 1
92+
filepath.Join( // recursion level 2
93+
filepath.Clean( // recursion level 3
94+
fmt.Sprintf("%s", // recursion level 4
95+
os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive"
96+
),
97+
),
98+
"test",
99+
),
100+
)
101+
t.Log( // recursion level 1
102+
fmt.Sprintf("%s/foo-%d", // recursion level 2
103+
filepath.Join( // recursion level 3
104+
filepath.Clean( // recursion level 4
105+
fmt.Sprintf("%s", // recursion level 5
106+
os.TempDir(), // max recursion level reached.
107+
),
108+
),
109+
"test",
110+
),
111+
1024,
112+
),
113+
)
114+
}

0 commit comments

Comments
 (0)