@@ -297,6 +297,133 @@ func TestChecker_Check(t *testing.T) {
297297 Name : "myFunction" ,
298298 },
299299 },
300+ }, {
301+ "variadic options with bad type" ,
302+ `
303+ fs default() {
304+ myfunc option::run {} option::copy {}
305+ }
306+ fs myfunc(variadic option::run opts) {
307+ image "busybox"
308+ run "echo hi" with opts
309+ }
310+ ` ,
311+ ErrWrongArgType {},
312+ }, {
313+ "variadic options with bad method type" ,
314+ `
315+ fs default() {
316+ myfunc option::run {
317+ copyOpt
318+ }
319+ }
320+ fs myfunc(variadic option::run opts) {
321+ image "busybox"
322+ run "echo hi" with opts
323+ }
324+ option::copy copyOpt() {}
325+ ` ,
326+ ErrWrongArgType {},
327+ }, {
328+ "variadic options with mixed types" ,
329+ `
330+ fs default() {
331+ myfunc option::run {} option::copy {}
332+ }
333+ fs myfunc(variadic option::run opts) {
334+ image "busybox"
335+ run "echo hi" with opts
336+ }
337+ ` ,
338+ ErrWrongArgType {},
339+ }, {
340+ "func call with bad arg count" ,
341+ `
342+ fs default() {
343+ myfunc "a" "b"
344+ }
345+ fs myfunc(string cmd) {
346+ image "busybox"
347+ run cmd
348+ }
349+ ` ,
350+ ErrNumArgs {},
351+ }, {
352+ "func call with bad arg type: basic literal" ,
353+ `
354+ fs default() {
355+ myfunc 1
356+ }
357+ fs myfunc(string cmd) {
358+ image "busybox"
359+ run cmd
360+ }
361+ ` ,
362+ ErrWrongArgType {},
363+ }, {
364+ "func call with bad arg type: basic ident" ,
365+ `
366+ fs default() {
367+ myfunc one
368+ }
369+ int one() { 1; }
370+ fs myfunc(string cmd) {
371+ image "busybox"
372+ run cmd
373+ }
374+ ` ,
375+ ErrWrongArgType {},
376+ }, {
377+ "func call with bad arg type: func ident" ,
378+ `
379+ fs default() {
380+ myfunc foo
381+ }
382+ fs foo() {}
383+ fs myfunc(string cmd) {
384+ image "busybox"
385+ run cmd
386+ }
387+ ` ,
388+ ErrWrongArgType {},
389+ }, {
390+ "func call with bad arg type: func literal" ,
391+ `
392+ fs default() {
393+ myfunc fs {}
394+ }
395+ fs myfunc(string cmd) {
396+ image "busybox"
397+ run cmd
398+ }
399+ ` ,
400+ ErrWrongArgType {},
401+ }, {
402+ "func call with bad subtype" ,
403+ `
404+ fs default() {
405+ runOpt
406+ }
407+ option::run runOpt() {}
408+ fs myfunc(string cmd) {
409+ image "busybox"
410+ run cmd
411+ }
412+ ` ,
413+ ErrWrongArgType {},
414+ }, {
415+ "func call with bad option type" ,
416+ `
417+ fs default() {
418+ myfunc "foo" with runOpt
419+ }
420+ option::run runOpt() {}
421+ fs myfunc(string cmd) {
422+ image "busybox"
423+ run cmd
424+ }
425+ ` ,
426+ ErrWrongArgType {},
300427 }} {
301428 tc := tc
302429 t .Run (tc .name , func (t * testing.T ) {
@@ -305,12 +432,20 @@ func TestChecker_Check(t *testing.T) {
305432 mod , err := parser .Parse (in )
306433 require .NoError (t , err )
307434
308- err = Check (mod )
435+ var r interface {}
436+ func () {
437+ defer func () {
438+ r = recover ()
439+ }()
440+ err = Check (mod )
441+ }()
442+ require .Nil (t , r , "panic: %+v" , r )
309443 validateError (t , tc .errType , err )
310444 })
311445 }
312446}
313447
448+
314449func TestChecker_CheckSelectors (t * testing.T ) {
315450 t .Parallel ()
316451
@@ -384,9 +519,9 @@ func validateError(t *testing.T, expectedError error, actualError error) {
384519 // to validate the underlying error
385520 if semErr , ok := actualError .(ErrSemantic ); ok {
386521 require .IsType (t , expectedError , semErr .Errs [0 ])
387- require .Equal (t , expectedError .Error (), semErr .Errs [0 ].Error ())
522+ require .Equal (t , expectedError .Error (), semErr .Errs [0 ].Error (), "error: %v" , actualError )
388523 } else {
389- require .IsType (t , expectedError , actualError )
524+ require .IsType (t , expectedError , actualError , "error: %v" , actualError )
390525 }
391526 }
392527}
0 commit comments