@@ -216,6 +216,7 @@ var parsePlusBuildExprTests = []struct {
216
216
{"!!x" , tag ("ignore" )},
217
217
{"!x" , not (tag ("x" ))},
218
218
{"!" , tag ("ignore" )},
219
+ {"" , tag ("ignore" )},
219
220
}
220
221
221
222
func TestParsePlusBuildExpr (t * testing.T ) {
@@ -232,34 +233,37 @@ func TestParsePlusBuildExpr(t *testing.T) {
232
233
var constraintTests = []struct {
233
234
in string
234
235
x Expr
235
- err error
236
+ err string
236
237
}{
237
- {"//+build x y" , or (tag ("x" ), tag ("y" )), nil },
238
- {"// +build x y \n " , or (tag ("x" ), tag ("y" )), nil },
239
- {"// +build x y \n " , nil , errNotConstraint },
240
- {"// +build x y \n more" , nil , errNotConstraint },
241
- {" //+build x y" , nil , errNotConstraint },
238
+ {"//+build !" , tag ("ignore" ), "" },
239
+ {"//+build" , tag ("ignore" ), "" },
240
+ {"//+build x y" , or (tag ("x" ), tag ("y" )), "" },
241
+ {"// +build x y \n " , or (tag ("x" ), tag ("y" )), "" },
242
+ {"// +build x y \n " , nil , "not a build constraint" },
243
+ {"// +build x y \n more" , nil , "not a build constraint" },
244
+ {" //+build x y" , nil , "not a build constraint" },
242
245
243
- {"//go:build x && y" , and (tag ("x" ), tag ("y" )), nil },
244
- {"//go:build x && y\n " , and (tag ("x" ), tag ("y" )), nil },
245
- {"//go:build x && y\n " , nil , errNotConstraint },
246
- {"//go:build x && y\n more" , nil , errNotConstraint },
247
- {" //go:build x && y" , nil , errNotConstraint },
246
+ {"//go:build x && y" , and (tag ("x" ), tag ("y" )), "" },
247
+ {"//go:build x && y\n " , and (tag ("x" ), tag ("y" )), "" },
248
+ {"//go:build x && y\n " , nil , "not a build constraint" },
249
+ {"//go:build x && y\n more" , nil , "not a build constraint" },
250
+ {" //go:build x && y" , nil , "not a build constraint" },
251
+ {"//go:build\n " , nil , "unexpected end of expression" },
248
252
}
249
253
250
254
func TestParse (t * testing.T ) {
251
255
for i , tt := range constraintTests {
252
256
t .Run (fmt .Sprint (i ), func (t * testing.T ) {
253
257
x , err := Parse (tt .in )
254
258
if err != nil {
255
- if tt .err == nil {
259
+ if tt .err == "" {
256
260
t .Errorf ("Constraint(%q): unexpected error: %v" , tt .in , err )
257
- } else if tt . err != err {
261
+ } else if ! strings . Contains ( err . Error (), tt . err ) {
258
262
t .Errorf ("Constraint(%q): error %v, want %v" , tt .in , err , tt .err )
259
263
}
260
264
return
261
265
}
262
- if tt .err != nil {
266
+ if tt .err != "" {
263
267
t .Errorf ("Constraint(%q) = %v, want error %v" , tt .in , x , tt .err )
264
268
return
265
269
}
0 commit comments