@@ -48,6 +48,19 @@ func Run(testMaps map[string][]string, filter func(name string) bool) {
48
48
os .Exit (1 )
49
49
}
50
50
51
+ unusedPatterns := false
52
+ for _ , label := range generator .allLabels {
53
+ for _ , match := range generator .matches [label ] {
54
+ if ! match .matched {
55
+ unusedPatterns = true
56
+ fmt .Fprintf (os .Stderr , "Unused pattern: %s => %s\n " , label , match .pattern )
57
+ }
58
+ }
59
+ }
60
+ if unusedPatterns {
61
+ os .Exit (1 )
62
+ }
63
+
51
64
// All tests must be associated with a sig (either upstream), or downstream
52
65
// If you get this error, you should add the [sig-X] tag to your test (if its
53
66
// in origin) or if it is upstream add a new rule to rules.go that assigns
@@ -110,25 +123,29 @@ func init() {
110
123
}
111
124
}
112
125
126
+ type matchable struct {
127
+ pattern string
128
+ literal string
129
+ re * regexp.Regexp
130
+ matched bool
131
+ }
132
+
113
133
func newGenerator (testMaps map [string ][]string ) * ginkgoTestRenamer {
114
134
var allLabels []string
115
- matches := make (map [string ]* regexp.Regexp )
116
- stringMatches := make (map [string ][]string )
135
+ matches := make (map [string ][]* matchable )
117
136
118
137
for label , items := range testMaps {
119
138
sort .Strings (items )
120
139
allLabels = append (allLabels , label )
121
- var remain []string
122
140
for _ , item := range items {
141
+ match := & matchable {pattern : item }
123
142
re := regexp .MustCompile (item )
124
143
if p , ok := re .LiteralPrefix (); ok {
125
- stringMatches [ label ] = append ( stringMatches [ label ], p )
144
+ match . literal = p
126
145
} else {
127
- remain = append ( remain , item )
146
+ match . re = re
128
147
}
129
- }
130
- if len (remain ) > 0 {
131
- matches [label ] = regexp .MustCompile (strings .Join (remain , `|` ))
148
+ matches [label ] = append (matches [label ], match )
132
149
}
133
150
}
134
151
sort .Strings (allLabels )
@@ -137,7 +154,6 @@ func newGenerator(testMaps map[string][]string) *ginkgoTestRenamer {
137
154
138
155
return & ginkgoTestRenamer {
139
156
allLabels : allLabels ,
140
- stringMatches : stringMatches ,
141
157
matches : matches ,
142
158
excludedTestsFilter : excludedTestsFilter ,
143
159
output : make (map [string ]string ),
@@ -154,10 +170,8 @@ func newRenamerFromGenerated(names map[string]string) *ginkgoTestRenamer {
154
170
type ginkgoTestRenamer struct {
155
171
// keys defined in TestMaps in openshift-hack/e2e/annotate/rules.go
156
172
allLabels []string
157
- // exact substrings to match to apply a particular label
158
- stringMatches map [string ][]string
159
- // regular expressions to match to apply a particular label
160
- matches map [string ]* regexp.Regexp
173
+ // matches to apply a particular label
174
+ matches map [string ][]* matchable
161
175
// regular expression excluding permanently a set of tests
162
176
// see ExcludedTests in openshift-hack/e2e/annotate/rules.go
163
177
excludedTestsFilter * regexp.Regexp
@@ -193,17 +207,17 @@ func (r *ginkgoTestRenamer) generateRename(name string, node types.TestSpec) {
193
207
}
194
208
195
209
var hasLabel bool
196
- for _ , segment := range r .stringMatches [label ] {
197
- hasLabel = strings .Contains (newName , segment )
210
+ for _ , match := range r .matches [label ] {
211
+ if match .re != nil {
212
+ hasLabel = match .re .MatchString (newName )
213
+ } else {
214
+ hasLabel = strings .Contains (newName , match .literal )
215
+ }
198
216
if hasLabel {
217
+ match .matched = true
199
218
break
200
219
}
201
220
}
202
- if ! hasLabel {
203
- if re := r .matches [label ]; re != nil {
204
- hasLabel = r .matches [label ].MatchString (newName )
205
- }
206
- }
207
221
208
222
if hasLabel {
209
223
count ++
0 commit comments