forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_transpile_test.go
86 lines (81 loc) · 1.7 KB
/
tool_transpile_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"go/scanner"
"go/token"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parseGoBuildErrors(t *testing.T) {
t.Parallel()
tests := []struct {
name string
output string
expectedError error
expectedErrorIs error
}{
{
name: "empty output",
output: "",
expectedError: nil,
},
{
name: "random output",
output: "xxx",
expectedError: scanner.ErrorList{
&scanner.Error{
Msg: "Additional go build errors:\nxxx",
},
},
},
{
name: "some errors",
output: `xxx
main.gno:6:2: nasty error
pkg/file.gno:60:20: ugly error`,
expectedError: scanner.ErrorList{
&scanner.Error{
Pos: token.Position{
Filename: "main.gno",
Line: 6,
Column: 2,
},
Msg: "nasty error",
},
&scanner.Error{
Pos: token.Position{
Filename: "pkg/file.gno",
Line: 60,
Column: 20,
},
Msg: "ugly error",
},
&scanner.Error{
Msg: "Additional go build errors:\nxxx",
},
},
},
{
name: "line parse error",
output: `main.gno:9000000000000000000000000000000000000000000000000000:11: error`,
expectedErrorIs: strconv.ErrRange,
},
{
name: "column parse error",
output: `main.gno:1:9000000000000000000000000000000000000000000000000000: error`,
expectedErrorIs: strconv.ErrRange,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := parseGoBuildErrors(tt.output)
if eis := tt.expectedErrorIs; eis != nil {
assert.ErrorIs(t, err, eis)
} else {
assert.Equal(t, tt.expectedError, err)
}
})
}
}