@@ -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,34 @@ 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
+ if _ , exists := matches [item ]; exists {
142
+ fmt .Fprintf (os .Stderr , "multiple entries for pattern %q\n " , item )
143
+ os .Exit (1 )
144
+ }
145
+
146
+ match := & matchable {pattern : item }
123
147
re := regexp .MustCompile (item )
124
148
if p , ok := re .LiteralPrefix (); ok {
125
- stringMatches [ label ] = append ( stringMatches [ label ], p )
149
+ match . literal = p
126
150
} else {
127
- remain = append ( remain , item )
151
+ match . re = re
128
152
}
129
- }
130
- if len (remain ) > 0 {
131
- matches [label ] = regexp .MustCompile (strings .Join (remain , `|` ))
153
+ matches [label ] = append (matches [label ], match )
132
154
}
133
155
}
134
156
sort .Strings (allLabels )
@@ -137,7 +159,6 @@ func newGenerator(testMaps map[string][]string) *ginkgoTestRenamer {
137
159
138
160
return & ginkgoTestRenamer {
139
161
allLabels : allLabels ,
140
- stringMatches : stringMatches ,
141
162
matches : matches ,
142
163
excludedTestsFilter : excludedTestsFilter ,
143
164
output : make (map [string ]string ),
@@ -154,10 +175,8 @@ func newRenamerFromGenerated(names map[string]string) *ginkgoTestRenamer {
154
175
type ginkgoTestRenamer struct {
155
176
// keys defined in TestMaps in openshift-hack/e2e/annotate/rules.go
156
177
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
178
+ // matches to apply a particular label
179
+ matches map [string ][]* matchable
161
180
// regular expression excluding permanently a set of tests
162
181
// see ExcludedTests in openshift-hack/e2e/annotate/rules.go
163
182
excludedTestsFilter * regexp.Regexp
@@ -193,17 +212,17 @@ func (r *ginkgoTestRenamer) generateRename(name string, node types.TestSpec) {
193
212
}
194
213
195
214
var hasLabel bool
196
- for _ , segment := range r .stringMatches [label ] {
197
- hasLabel = strings .Contains (newName , segment )
215
+ for _ , match := range r .matches [label ] {
216
+ if match .re != nil {
217
+ hasLabel = match .re .MatchString (newName )
218
+ } else {
219
+ hasLabel = strings .Contains (newName , match .literal )
220
+ }
198
221
if hasLabel {
222
+ match .matched = true
199
223
break
200
224
}
201
225
}
202
- if ! hasLabel {
203
- if re := r .matches [label ]; re != nil {
204
- hasLabel = r .matches [label ].MatchString (newName )
205
- }
206
- }
207
226
208
227
if hasLabel {
209
228
count ++
0 commit comments