@@ -97,19 +97,24 @@ void main() {
9797
9898 test (
9999 'makeDescription return a String with '
100- 'formatted output by customDescriptionBuilder '
101- 'and complex object as group description' , () {
100+ 'formatted output by customDescriptionBuilder '
101+ 'and complex object as group description' , () {
102102 final values = [1 , 2 , 3 ];
103103
104104 Object ? builder (
105- Object ? groupDescription,
106- int index,
107- List <dynamic > values,
108- ) {
105+ Object ? groupDescription,
106+ int index,
107+ List <dynamic > values,
108+ ) {
109109 return '[ $groupDescription | $index | ${values .length } ]' ;
110110 }
111111
112- final result = pTest.makeDescription (DateTime (2024 ,04 ,17 ), 1 , values, builder);
112+ final result = pTest.makeDescription (
113+ DateTime (2024 , 04 , 17 ),
114+ 1 ,
115+ values,
116+ builder,
117+ );
113118
114119 expect (result, '[ 2024-04-17 00:00:00.000 | 1 | 3 ]' );
115120 });
@@ -364,7 +369,9 @@ void main() {
364369 expect (testMock.testCaptures[1 ].description, 3 );
365370 expect (testMock.testCaptures[2 ].description, 4 );
366371 });
372+ });
367373
374+ group ('parameterized test exception handling tests' , () {
368375 test (
369376 'test throws ParameterizedError when length values and length '
370377 'function arguments dont match' , () {
@@ -373,6 +380,7 @@ void main() {
373380 pTest ('test' , [1 , 2 , 3 ], (int value, int value2) => value + value2),
374381 throwsA (isA <ParameterizedError >()),
375382 );
383+
376384 expect (
377385 () => pTest (
378386 'test' ,
@@ -387,13 +395,48 @@ void main() {
387395 );
388396 });
389397
398+ test (
399+ 'nested test throws ParameterizedError when length values and length '
400+ 'function arguments dont match' , () {
401+ expect (
402+ () => pTest (
403+ 'test' ,
404+ [1 , 2 , 3 ],
405+ (int value) => pTest (
406+ 'test' ,
407+ [1 , 2 , 3 ],
408+ (int value, int value2) => value + value2,
409+ ),
410+ ),
411+ throwsA (isA <ParameterizedError >()),
412+ );
413+
414+ expect (
415+ () => pTest (
416+ 'test' ,
417+ [1 ],
418+ (int value) => pTest (
419+ 'test' ,
420+ [
421+ [1 , 2 ],
422+ [3 , 4 ],
423+ [5 , 6 ],
424+ ],
425+ (int value) => value,
426+ ),
427+ ),
428+ throwsA (isA <ParameterizedError >()),
429+ );
430+ });
431+
390432 test (
391433 'test throws ParameterizedError when values types and '
392434 'function arguments types dont match' , () {
393435 expect (
394436 () => pTest ('test' , [1 , 2 , 3 ], (String value) => value),
395437 throwsA (isA <ParameterizedError >()),
396438 );
439+
397440 expect (
398441 () => pTest (
399442 'test' ,
@@ -408,10 +451,124 @@ void main() {
408451 );
409452 });
410453
454+ test (
455+ 'nested test throws ParameterizedError when values types and '
456+ 'function arguments types dont match' , () {
457+ expect (
458+ () => pTest (
459+ 'test' ,
460+ [1 , 2 , 3 ],
461+ (int value) => pTest ('test' , [1 , 2 , 3 ], (String value) => value),
462+ ),
463+ throwsA (isA <ParameterizedError >()),
464+ );
465+
466+ expect (
467+ () => pTest (
468+ 'test' ,
469+ [1 ],
470+ (int value) => pTest (
471+ 'test' ,
472+ [
473+ [1 , 2 ],
474+ [3 , 4 ],
475+ [5 , 6 ],
476+ ],
477+ (int value, String value2) => value + value2.length,
478+ ),
479+ ),
480+ throwsA (isA <ParameterizedError >()),
481+ );
482+ });
483+
484+ test ('test doesnt catch TypeError when the test body throws the exception' ,
485+ () {
486+ expect (
487+ () => pTest ('test' , [1 , 2 , 3 ], (int value) {
488+ // Causes a TypeError for test
489+ // ignore: unused_local_variable
490+ final error = value as String ;
491+ }),
492+ throwsA (isA <TypeError >()),
493+ );
494+ });
495+
496+ test (
497+ 'nested test doesnt catch TypeError when the test body '
498+ 'throws the exception' , () {
499+ expect (
500+ () => pTest (
501+ 'test' ,
502+ [1 , 2 , 3 ],
503+ (int value) => pTest ('test' , [1 , 2 , 3 ], (int value) {
504+ // Causes a TypeError for test
505+ // ignore: unused_local_variable
506+ final error = value as String ;
507+ }),
508+ ),
509+ throwsA (isA <TypeError >()),
510+ );
511+ });
512+
513+ test (
514+ 'test doesnt catch NoSuchMethodError when the test body '
515+ 'throws the exception' , () {
516+ expect (
517+ () => pTest ('test' , [1 , 2 , 3 ], (int value) {
518+ const dynamic errorCauser = '' ;
519+
520+ // This is a dynamic call, so it will throw a NoSuchMethodError
521+ // ignore: avoid_dynamic_calls
522+ errorCauser.whoop (1 , 2 );
523+ }),
524+ throwsA (isA <NoSuchMethodError >()),
525+ );
526+ });
527+
528+ test (
529+ 'nested test doesnt catch NoSuchMethodError when the test body '
530+ 'throws the exception' , () {
531+ expect (
532+ () => pTest (
533+ 'test' ,
534+ [1 , 2 , 3 ],
535+ (int value) => pTest ('test' , [1 , 2 , 3 ], (int value) {
536+ const dynamic errorCauser = '' ;
537+
538+ // This is a dynamic call, so it will throw a NoSuchMethodError
539+ // ignore: avoid_dynamic_calls
540+ errorCauser.whoop (1 , 2 );
541+ }),
542+ ),
543+ throwsA (isA <NoSuchMethodError >()),
544+ );
545+ });
546+
411547 test ('test doesnt catch exceptions other than NoSuchMethodError, TypeError' ,
412548 () {
413549 expect (
414- () => pTest ('test' , [1 , 2 , 3 ], (int value) => throw Exception ('test' )),
550+ () => pTest (
551+ 'test' ,
552+ [1 , 2 , 3 ],
553+ (int value) => throw Exception ('test' ),
554+ ),
555+ throwsA (isA <Exception >()),
556+ );
557+ });
558+
559+ test (
560+ 'nested test doesnt catch exceptions other than '
561+ 'NoSuchMethodError, TypeError' , () {
562+ expect (
563+ () => pTest (
564+ 'test' ,
565+ [1 , 2 , 3 ],
566+ (int value) => pTest (
567+ 'test' ,
568+ [1 , 2 , 3 ],
569+ (int value) => throw Exception ('test' ),
570+ ),
571+ ),
415572 throwsA (isA <Exception >()),
416573 );
417574 });
0 commit comments