Skip to content

Commit e2fe6a3

Browse files
committed
Fix go1.13
1 parent 9c596af commit e2fe6a3

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

test/fix_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ func TestFix(t *testing.T) {
2626

2727
if os.Getenv("GL_KEEP_TEMP_FILES") == "1" {
2828
t.Logf("Temp dir for fix test: %s", tmpDir)
29-
} else {
30-
t.Cleanup(func() {
29+
} else if tCleanupExists {
30+
registerCleanup(t, func() {
3131
os.RemoveAll(tmpDir)
3232
})
33+
} else {
34+
os.RemoveAll(tmpDir)
3335
}
3436

3537
fixDir := filepath.Join(testdataDir, "fix")
@@ -40,7 +42,10 @@ func TestFix(t *testing.T) {
4042
for _, input := range inputs {
4143
input := input
4244
t.Run(filepath.Base(input), func(t *testing.T) {
43-
t.Parallel()
45+
// if t.Cleanup does not exist, don't run these tests concurrently because we need to use defer for clean up
46+
if tCleanupExists {
47+
t.Parallel()
48+
}
4449
args := []string{
4550
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number",
4651
"--allow-parallel-runners", "--fix",

test/fix_test_go1_13.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// +build !go1.14
2+
3+
package test
4+
5+
import "testing"
6+
7+
const tCleanupExists = false
8+
9+
// do nothing for go.1.13
10+
func registerCleanup(t *testing.T, f func()) {}

test/register_cleanup.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// +build go1.14
2+
3+
package test
4+
5+
import "testing"
6+
7+
const tCleanupExists = true
8+
9+
// registerCleanup exists because t.Cleanup doesn't exist prior to go1.14
10+
func registerCleanup(t *testing.T, f func()) {
11+
t.Cleanup(f)
12+
}

0 commit comments

Comments
 (0)