@@ -58,6 +58,8 @@ func AssertIssues(t *testing.T, want Issues, got Issues) {
58
58
opts := []cmp.Option {
59
59
// Byte field will be ignored because it's not important in tests such as positions
60
60
cmpopts .IgnoreFields (hcl.Pos {}, "Byte" ),
61
+ // Issues will be sorted and output in the end, so ignore the order.
62
+ ignoreIssuesOrder (),
61
63
ruleComparer (),
62
64
}
63
65
if diff := cmp .Diff (want , got , opts ... ); diff != "" {
@@ -71,6 +73,7 @@ func AssertIssuesWithoutRange(t *testing.T, want Issues, got Issues) {
71
73
72
74
opts := []cmp.Option {
73
75
cmpopts .IgnoreFields (Issue {}, "Range" ),
76
+ ignoreIssuesOrder (),
74
77
ruleComparer (),
75
78
}
76
79
if diff := cmp .Diff (want , got , opts ... ); diff != "" {
@@ -98,3 +101,24 @@ func ruleComparer() cmp.Option {
98
101
return reflect .TypeOf (x ) == reflect .TypeOf (y )
99
102
})
100
103
}
104
+
105
+ func ignoreIssuesOrder () cmp.Option {
106
+ return cmpopts .SortSlices (func (i , j * Issue ) bool {
107
+ if i .Range .Filename != j .Range .Filename {
108
+ return i .Range .Filename < j .Range .Filename
109
+ }
110
+ if i .Range .Start .Line != j .Range .Start .Line {
111
+ return i .Range .Start .Line < j .Range .Start .Line
112
+ }
113
+ if i .Range .Start .Column != j .Range .Start .Column {
114
+ return i .Range .Start .Column < j .Range .Start .Column
115
+ }
116
+ if i .Range .End .Line != j .Range .End .Line {
117
+ return i .Range .End .Line > j .Range .End .Line
118
+ }
119
+ if i .Range .End .Column != j .Range .End .Column {
120
+ return i .Range .End .Column > j .Range .End .Column
121
+ }
122
+ return i .Message < j .Message
123
+ })
124
+ }
0 commit comments