-
-
Notifications
You must be signed in to change notification settings - Fork 398
/
errorformat_test.go
78 lines (72 loc) 路 1.68 KB
/
errorformat_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
package parser
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"testing"
"google.golang.org/protobuf/encoding/protojson"
)
func TestNewErrorformatParserString(t *testing.T) {
in := []string{`%f:%l:%c:%m`, `%-G%.%#`}
got, err := NewErrorformatParserString(in)
if err != nil {
t.Fatal(err)
}
if len(got.efm.Efms) != len(in) {
t.Errorf("NewErrorformatParserString: len: got %v, want %v", len(got.efm.Efms), len(in))
}
}
func ExampleErrorformatParser() {
const sample = `/path/to/file1.txt:1:14: [E][RULE:14] message 1
/path/to/file2.txt:2:14: [N][RULE:7] message 2`
p, err := NewErrorformatParserString([]string{`%f:%l:%c: [%t][RULE:%n] %m`})
if err != nil {
panic(err)
}
diagnostics, err := p.Parse(strings.NewReader(sample))
if err != nil {
panic(err)
}
for _, d := range diagnostics {
rdjson, _ := protojson.MarshalOptions{Indent: " "}.Marshal(d)
var out bytes.Buffer
json.Indent(&out, rdjson, "", " ")
fmt.Println(out.String())
}
// Output:
// {
// "message": "message 1",
// "location": {
// "path": "/path/to/file1.txt",
// "range": {
// "start": {
// "line": 1,
// "column": 14
// }
// }
// },
// "severity": "ERROR",
// "code": {
// "value": "14"
// },
// "originalOutput": "/path/to/file1.txt:1:14: [E][RULE:14] message 1"
// }
// {
// "message": "message 2",
// "location": {
// "path": "/path/to/file2.txt",
// "range": {
// "start": {
// "line": 2,
// "column": 14
// }
// }
// },
// "severity": "INFO",
// "code": {
// "value": "7"
// },
// "originalOutput": "/path/to/file2.txt:2:14: [N][RULE:7] message 2"
// }
}