-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmocker_comp_test.go
58 lines (51 loc) · 1.43 KB
/
mocker_comp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Package mocker_test 对 mocker 包的测试
// 当前文件实现了对 mocker_test.go,iface_test.go,debug_test.go 的单测对于不同 go 版本的兼容性测试
package mocker_test
import (
"fmt"
"os"
"strings"
"testing"
"github.com/tencent/goom/test"
)
var versions = []string{
"go1.16",
"go1.17",
"go1.18",
"go1.19",
"go1.20",
"go1.21.1",
"go1.22.1",
"go1.23.1",
}
const testEnv = "MOCKER_COMPATIBILITY_TEST"
// TestCompatibility 测试针对不同 go 版本的兼容情况
func TestCompatibility(t *testing.T) {
if os.Getenv(testEnv) == "true" {
return
}
os.Setenv(testEnv, "true")
for _, v := range versions {
fmt.Printf("> [%s] start testing..\n", v)
if err := test.Run(v, nil, "version"); err != nil {
t.Errorf("[%s] env prepare fail: %v", v, err)
}
logHandler := func(log string) {
if strings.Contains(log, "--- FAIL:") {
t.Errorf("[%s] run fail: see details in the log above.", v)
}
fmt.Println(log)
}
vn := strings.Join(strings.Split(strings.Split(v, "go")[1], ".")[0:2], ".")
if err := test.Run(v, logHandler, "mod", "edit", "-go="+vn); err != nil {
t.Errorf("[%s] mod edit error: %v, see details in the log above.", v, err)
}
if err := test.Run(v, logHandler, "test", "-v", "-gcflags=all=-l", "-ldflags=-s=false", "."); err != nil {
t.Errorf("[%s] run error: %v, see details in the log above.", v, err)
}
if t.Failed() {
break
}
t.Logf("[%s] testing success.", v)
}
}