diff --git a/CHANGELOG.md b/CHANGELOG.md index af12feb..e437d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 2.0.2 + - Update dependencies + - Update `very_good_analysis` to `9.0.0` + - Added topics: [test, testing, parameterized] to pubspec.yaml + - Added small explanation to README.md about Future.error usage in tests. + - Updated dart formatting. + ## 2.0.1 - Updated dependencies - sdk to `>=3.4.0 <4.0.0` diff --git a/README.md b/README.md index 9326a76..5aa4fa2 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,10 @@ parameterizedTest('Example of CSV data', }); ``` +### Testing with `Future.error` values +When using `Future.error` directly in your parameterized test values, this might leads to not executing tests at all. In order to handle this correctly your can provide the `Future` as a callback function. +But also need to make sure that the when the future is awaited its also catch. `Future.error` will throw the provided object. See [23](https://github.com/DutchCodingCompany/parameterized_test/issues/23) for more information. + ## Additional information 💡 It's just a simple wrapper to easily execute tests multiple times with different values. Feel free to diff --git a/analysis_options.yaml b/analysis_options.yaml index fd66045..e61f064 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,5 +1,8 @@ include: package:very_good_analysis/analysis_options.yaml +formatter: + trailing_commas: automate + analyzer: errors: unawaited_futures: warning diff --git a/example/parameterized_test_example.dart b/example/parameterized_test_example.dart index ebcb2e0..b1821d3 100644 --- a/example/parameterized_test_example.dart +++ b/example/parameterized_test_example.dart @@ -1,3 +1,4 @@ +// ignore this lint for example reasons. // ignore_for_file: avoid_print import 'package:csv/csv.dart'; @@ -6,46 +7,44 @@ import 'package:test/test.dart'; void main() { // Simple test containing a list of single values + parameterizedTest('Example of list of single values', [1, 2, 3], (int value) { + final result = value < 4; + expect(result, true); + }); + + // Simple test containing a list of multiple values parameterizedTest( - 'Example of list of single values', + 'Example of list of multiple values', [ - 1, - 2, - 3, + [0, 1, 1], + [1, 1, 2], + [1, 2, 3], + [2, 2, 4], ], - (int value) { - final result = value < 4; - expect(result, true); + (int value1, int value2, int sum) { + expect(value1 + value2, sum); }, ); - // Simple test containing a list of multiple values - parameterizedTest('Example of list of multiple values', [ - [0, 1, 1], - [1, 1, 2], - [1, 2, 3], - [2, 2, 4], - ], (int value1, int value2, int sum) { - expect(value1 + value2, sum); - }); - // Test containing a list with complex objects - parameterizedTest('Example of a list with complex object', [ - [DateTime(2024, 4, 12), 5], - [DateTime(1969, 07, 20), 7], - ], (DateTime dateTime, int expectedWeekday) { - expect(dateTime.weekday, expectedWeekday); - }); - - // Test containing a list of enums parameterizedTest( - 'Example using enum as value', - FruitEnum.values, - (FruitEnum testEnum) { - expect(testEnum.name.length, testEnum.wordLength); + 'Example of a list with complex object', + [ + [DateTime(2024, 4, 12), 5], + [DateTime(1969, 07, 20), 7], + ], + (DateTime dateTime, int expectedWeekday) { + expect(dateTime.weekday, expectedWeekday); }, ); + // Test containing a list of enums + parameterizedTest('Example using enum as value', FruitEnum.values, ( + FruitEnum testEnum, + ) { + expect(testEnum.name.length, testEnum.wordLength); + }); + // Test retreiving the list of values from a function List provideData() { return [ @@ -56,13 +55,13 @@ void main() { ]; } - parameterizedTest( - 'Example of list of values from function', - provideData(), - (int value1, int value2, int sum) { - expect(value1 + value2, sum); - }, - ); + parameterizedTest('Example of list of values from function', provideData(), ( + int value1, + int value2, + int sum, + ) { + expect(value1 + value2, sum); + }); // Simple test with setup and teardown parameterizedTest( @@ -88,28 +87,24 @@ void main() { // But this is not a good practice to use a delay like // this in a test. Running this test will take longer. This could be // fixed by using a package like fake_async. - parameterizedTest( - 'Example using a async test', - [ - 100, - 200, - 300, - ], - (int value) async { - final millis = DateTime.now().millisecondsSinceEpoch; - await Future.delayed(Duration(milliseconds: value)); - final passed = DateTime.now().millisecondsSinceEpoch - millis; + parameterizedTest('Example using a async test', [100, 200, 300], ( + int value, + ) async { + final millis = DateTime.now().millisecondsSinceEpoch; + await Future.delayed(Duration(milliseconds: value)); + final passed = DateTime.now().millisecondsSinceEpoch - millis; - expect(passed >= value, true); - }, - ); + expect(passed >= value, true); + }); // Test with CSV data - parameterizedTest('Example of CSV data', - const CsvToListConverter().convert('kiwi,4\r\napple,5\r\nbanana,6'), - (String fruit, int length) { - expect(fruit.length, length); - }); + parameterizedTest( + 'Example of CSV data', + const CsvToListConverter().convert('kiwi,4\r\napple,5\r\nbanana,6'), + (String fruit, int length) { + expect(fruit.length, length); + }, + ); } enum FruitEnum { diff --git a/lib/parameterized_test.dart b/lib/parameterized_test.dart index 4ea0d77..0bfeebf 100644 --- a/lib/parameterized_test.dart +++ b/lib/parameterized_test.dart @@ -1,5 +1,5 @@ /// A library that simplifies writing parameterized tests in Dart. -library parameterized_test; +library; export '/src/parameterized_test.dart' show parameterizedGroup, parameterizedTest; diff --git a/lib/src/errors/parameterized_error.dart b/lib/src/errors/parameterized_error.dart index 3f7fe90..99ec4a2 100644 --- a/lib/src/errors/parameterized_error.dart +++ b/lib/src/errors/parameterized_error.dart @@ -8,18 +8,16 @@ class ParameterizedError extends Error { /// Creates a [ParameterizedError] from a [TypeError]. /// When arguments types don't match the function arguments types. - factory ParameterizedError.forTypeError( - List value, - Function body, - ) { + factory ParameterizedError.forTypeError(List value, Function body) { final bodyClosure = extractFunctionArgumentsSignature(body.toString()); return ParameterizedError( - "Provided value(s) didn't match the function arguments types.\n" - 'Test values: $value\n' - 'Provided types: ' - '(${value.map((e) => e.runtimeType).join(', ')})\n' - 'Expected types: ($bodyClosure)'); + "Provided value(s) didn't match the function arguments types.\n" + 'Test values: $value\n' + 'Provided types: ' + '(${value.map((e) => e.runtimeType).join(', ')})\n' + 'Expected types: ($bodyClosure)', + ); } /// Creates a [ParameterizedError] from a [TypeError]. @@ -32,13 +30,14 @@ class ParameterizedError extends Error { final positionalArgumentsCount = ','.allMatches(bodyClosure).length + 1; return ParameterizedError( - "Provided value(s) didn't match the function arguments count.\n" - 'Amount of provided values: ${value.length}\n' - 'Expected function arguments: $positionalArgumentsCount\n' - 'Test values: $value\n' - 'Provided types: ' - '(${value.map((e) => e.runtimeType).join(', ')})\n' - 'Expected types: ($bodyClosure)'); + "Provided value(s) didn't match the function arguments count.\n" + 'Amount of provided values: ${value.length}\n' + 'Expected function arguments: $positionalArgumentsCount\n' + 'Test values: $value\n' + 'Provided types: ' + '(${value.map((e) => e.runtimeType).join(', ')})\n' + 'Expected types: ($bodyClosure)', + ); } /// Error message. @@ -51,10 +50,7 @@ class ParameterizedError extends Error { final closureIndex = body.indexOf(closure); final endIndex = body.indexOf(')', closureIndex); - final bodyClosure = body.substring( - closureIndex + closure.length, - endIndex, - ); + final bodyClosure = body.substring(closureIndex + closure.length, endIndex); return bodyClosure.replaceAll(RegExp('<(.*)>'), ''); } diff --git a/lib/src/errors/stack_trace_extension.dart b/lib/src/errors/stack_trace_extension.dart index 11819de..c7d9b03 100644 --- a/lib/src/errors/stack_trace_extension.dart +++ b/lib/src/errors/stack_trace_extension.dart @@ -27,8 +27,6 @@ extension StackTraceExtension on StackTrace { final frames = trace.frames.take(index).toList(); - return !frames.every( - (f) => f.package == 'parameterized_test' || f.isCore, - ); + return !frames.every((f) => f.package == 'parameterized_test' || f.isCore); } } diff --git a/lib/src/parameterized_test.dart b/lib/src/parameterized_test.dart index 1b88a8d..a0698b6 100644 --- a/lib/src/parameterized_test.dart +++ b/lib/src/parameterized_test.dart @@ -5,16 +5,17 @@ import 'package:parameterized_test/src/test_options/value_with_test_options.dart import 'package:test/test.dart'; /// Callback signature for test and group functions. -typedef TestFunc = void Function( - Object? description, - dynamic Function() body, { - String? testOn, - Timeout? timeout, - Object? skip, - Object? tags, - Map? onPlatform, - int? retry, -}); +typedef TestFunc = + void Function( + Object? description, + dynamic Function() body, { + String? testOn, + Timeout? timeout, + Object? skip, + Object? tags, + Map? onPlatform, + int? retry, + }); /// Callback signature for setUp and tearDown functions. typedef SetupFunc = void Function(dynamic Function()); @@ -42,12 +43,8 @@ typedef SetupFunc = void Function(dynamic Function()); /// ``` /// {@endtemplate} @isTestGroup -ParameterizedTest get parameterizedTest => const ParameterizedTestImpl( - group, - test, - setUp, - tearDown, - ); +ParameterizedTest get parameterizedTest => + const ParameterizedTestImpl(group, test, setUp, tearDown); /// {@template parameterizedGroup} // ignore: comment_references @@ -76,12 +73,8 @@ ParameterizedTest get parameterizedTest => const ParameterizedTestImpl( /// ``` /// {@endtemplate} @isTestGroup -ParameterizedTest get parameterizedGroup => const ParameterizedTestImpl( - group, - group, - setUp, - tearDown, - ); +ParameterizedTest get parameterizedGroup => + const ParameterizedTestImpl(group, group, setUp, tearDown); /// {@template ParameterizedTest} /// Implementation of parameterized test. @@ -159,17 +152,16 @@ class ParameterizedTestImpl implements ParameterizedTest { testDescription, () { try { - return Function.apply( - body, - value, - ); + return Function.apply(body, value); } + // We want to catch these errors to provide better error messages //ignore: avoid_catching_errors on NoSuchMethodError catch (e, s) { if (s.isInsideTestBody) rethrow; throw ParameterizedError.fromNoSuchMethodError(e, value); } + // We want to catch these errors to provide better error messages //ignore: avoid_catching_errors on TypeError catch (e, s) { if (s.isInsideTestBody) rethrow; @@ -206,9 +198,7 @@ class ParameterizedTestImpl implements ParameterizedTest { List value, CustomDescriptionBuilder? customDescriptionBuilder, ) { - final mappedValues = value.map( - (e) => e is String ? "'$e'" : e.toString(), - ); + final mappedValues = value.map((e) => e is String ? "'$e'" : e.toString()); return customDescriptionBuilder?.call(description, index, value) ?? '[ ${mappedValues.join(', ')} ]'; @@ -217,9 +207,9 @@ class ParameterizedTestImpl implements ParameterizedTest { /// Unpack wrapped values and test options. /// Handle different types of values. ValueWithTestOptions parseValues(dynamic value) => switch (value) { - ValueWithTestOptions() => value, - List() => (values: value, testOptions: null), - Iterable() => (values: value.toList(), testOptions: null), - _ => (values: [value], testOptions: null), - }; + ValueWithTestOptions() => value, + List() => (values: value, testOptions: null), + Iterable() => (values: value.toList(), testOptions: null), + _ => (values: [value], testOptions: null), + }; } diff --git a/lib/src/test_options/test_options_ext.dart b/lib/src/test_options/test_options_ext.dart index fe750af..ca8c844 100644 --- a/lib/src/test_options/test_options_ext.dart +++ b/lib/src/test_options/test_options_ext.dart @@ -20,19 +20,18 @@ extension ListTestParametersEx> on T { dynamic tags, Map? onPlatform, int? retry, - }) => - ( - values: this, - testOptions: TestOptions( - customDescriptionBuilder: customDescriptionBuilder, - testOn: testOn, - timeout: timeout, - skip: skip, - tags: tags, - onPlatform: onPlatform, - retry: retry, - ), - ); + }) => ( + values: this, + testOptions: TestOptions( + customDescriptionBuilder: customDescriptionBuilder, + testOn: testOn, + timeout: timeout, + skip: skip, + tags: tags, + onPlatform: onPlatform, + retry: retry, + ), + ); } /// Extension on [Object] to apply extra test options for a specified @@ -54,17 +53,16 @@ extension TestParametersEx on Object { dynamic tags, Map? onPlatform, int? retry, - }) => - ( - values: [this], - testOptions: TestOptions( - customDescriptionBuilder: customDescriptionBuilder, - testOn: testOn, - timeout: timeout, - skip: skip, - tags: tags, - onPlatform: onPlatform, - retry: retry, - ), - ); + }) => ( + values: [this], + testOptions: TestOptions( + customDescriptionBuilder: customDescriptionBuilder, + testOn: testOn, + timeout: timeout, + skip: skip, + tags: tags, + onPlatform: onPlatform, + retry: retry, + ), + ); } diff --git a/lib/src/test_options/value_with_test_options.dart b/lib/src/test_options/value_with_test_options.dart index 0d968ed..9656e8a 100644 --- a/lib/src/test_options/value_with_test_options.dart +++ b/lib/src/test_options/value_with_test_options.dart @@ -10,11 +10,8 @@ import 'package:parameterized_test/src/test_options/test_options.dart'; /// '🚀[$index] $groupDescription: <<${values.join('|')}>>', /// ``` /// {@endtemplate} -typedef CustomDescriptionBuilder = Object? Function( - Object? groupDescription, - int index, - List values, -); +typedef CustomDescriptionBuilder = + Object? Function(Object? groupDescription, int index, List values); /// {@template ValueWithTestOptions} /// Wrapper for test values and associated test options. diff --git a/pubspec.yaml b/pubspec.yaml index bc5659d..68d7c77 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,11 @@ name: parameterized_test description: Run a test multiple times based on provided parameter list. Inspired by JUnit ParameterizedTest. -version: 2.0.1 +version: 2.0.2 homepage: https://www.github.com/DutchCodingCompany/parameterized_test +topics: [test, testing, parameterized] environment: - sdk: '>=3.4.0 <4.0.0' + sdk: '>=3.8.0 <4.0.0' dependencies: meta: ^1.15.0 @@ -13,4 +14,4 @@ dependencies: dev_dependencies: csv: ^6.0.0 - very_good_analysis: ^6.0.0 + very_good_analysis: ^9.0.0 diff --git a/test/parameterized_error_test.dart b/test/parameterized_error_test.dart index 9265ab3..5afd054 100644 --- a/test/parameterized_error_test.dart +++ b/test/parameterized_error_test.dart @@ -1,3 +1,6 @@ +// We want to catch these errors to test if we can provide better error messages +// ignore_for_file: document_ignores + import 'package:parameterized_test/src/errors/parameterized_error.dart'; import 'package:test/test.dart'; @@ -39,10 +42,9 @@ void main() { }); test('ParameterizedError for TypeError', () { - final result = ParameterizedError.forTypeError( - [1], - (String value) => value, - ); + final result = ParameterizedError.forTypeError([ + 1, + ], (String value) => value); expect( result.message, "Provided value(s) didn't match the function arguments types.\n" @@ -62,11 +64,11 @@ void main() { ((Map value, String string) => Null, 'Map, String'), ( (Map value, String string) => Map, - 'Map, String' + 'Map, String', ), ( (Map> value, String string) => Null, - 'Map, String' + 'Map, String', ), ((int value, String string) async => Future, 'int, String'), ]; diff --git a/test/parameterized_test_example_test.dart b/test/parameterized_test_example_test.dart index ebcb2e0..564cd73 100644 --- a/test/parameterized_test_example_test.dart +++ b/test/parameterized_test_example_test.dart @@ -1,3 +1,5 @@ +// Example of a parameterized test using the parameterized_test package +// using print to indicate setup and teardown // ignore_for_file: avoid_print import 'package:csv/csv.dart'; @@ -6,46 +8,44 @@ import 'package:test/test.dart'; void main() { // Simple test containing a list of single values + parameterizedTest('Example of list of single values', [1, 2, 3], (int value) { + final result = value < 4; + expect(result, true); + }); + + // Simple test containing a list of multiple values parameterizedTest( - 'Example of list of single values', + 'Example of list of multiple values', [ - 1, - 2, - 3, + [0, 1, 1], + [1, 1, 2], + [1, 2, 3], + [2, 2, 4], ], - (int value) { - final result = value < 4; - expect(result, true); + (int value1, int value2, int sum) { + expect(value1 + value2, sum); }, ); - // Simple test containing a list of multiple values - parameterizedTest('Example of list of multiple values', [ - [0, 1, 1], - [1, 1, 2], - [1, 2, 3], - [2, 2, 4], - ], (int value1, int value2, int sum) { - expect(value1 + value2, sum); - }); - // Test containing a list with complex objects - parameterizedTest('Example of a list with complex object', [ - [DateTime(2024, 4, 12), 5], - [DateTime(1969, 07, 20), 7], - ], (DateTime dateTime, int expectedWeekday) { - expect(dateTime.weekday, expectedWeekday); - }); - - // Test containing a list of enums parameterizedTest( - 'Example using enum as value', - FruitEnum.values, - (FruitEnum testEnum) { - expect(testEnum.name.length, testEnum.wordLength); + 'Example of a list with complex object', + [ + [DateTime(2024, 4, 12), 5], + [DateTime(1969, 07, 20), 7], + ], + (DateTime dateTime, int expectedWeekday) { + expect(dateTime.weekday, expectedWeekday); }, ); + // Test containing a list of enums + parameterizedTest('Example using enum as value', FruitEnum.values, ( + FruitEnum testEnum, + ) { + expect(testEnum.name.length, testEnum.wordLength); + }); + // Test retreiving the list of values from a function List provideData() { return [ @@ -56,13 +56,13 @@ void main() { ]; } - parameterizedTest( - 'Example of list of values from function', - provideData(), - (int value1, int value2, int sum) { - expect(value1 + value2, sum); - }, - ); + parameterizedTest('Example of list of values from function', provideData(), ( + int value1, + int value2, + int sum, + ) { + expect(value1 + value2, sum); + }); // Simple test with setup and teardown parameterizedTest( @@ -88,28 +88,24 @@ void main() { // But this is not a good practice to use a delay like // this in a test. Running this test will take longer. This could be // fixed by using a package like fake_async. - parameterizedTest( - 'Example using a async test', - [ - 100, - 200, - 300, - ], - (int value) async { - final millis = DateTime.now().millisecondsSinceEpoch; - await Future.delayed(Duration(milliseconds: value)); - final passed = DateTime.now().millisecondsSinceEpoch - millis; + parameterizedTest('Example using a async test', [100, 200, 300], ( + int value, + ) async { + final millis = DateTime.now().millisecondsSinceEpoch; + await Future.delayed(Duration(milliseconds: value)); + final passed = DateTime.now().millisecondsSinceEpoch - millis; - expect(passed >= value, true); - }, - ); + expect(passed >= value, true); + }); // Test with CSV data - parameterizedTest('Example of CSV data', - const CsvToListConverter().convert('kiwi,4\r\napple,5\r\nbanana,6'), - (String fruit, int length) { - expect(fruit.length, length); - }); + parameterizedTest( + 'Example of CSV data', + const CsvToListConverter().convert('kiwi,4\r\napple,5\r\nbanana,6'), + (String fruit, int length) { + expect(fruit.length, length); + }, + ); } enum FruitEnum { diff --git a/test/parameterized_test_test.dart b/test/parameterized_test_test.dart index 1dcc0f1..e202022 100644 --- a/test/parameterized_test_test.dart +++ b/test/parameterized_test_test.dart @@ -1,3 +1,4 @@ +// Used print as value to test setup and teardown calls // ignore_for_file: avoid_print import 'package:parameterized_test/parameterized_test.dart'; @@ -31,8 +32,7 @@ void main() { group('makeDescription tests', () { const baseDescription = 'Group description'; - test( - 'makeDescription return a String with ' + test('makeDescription return a String with ' 'comma separated values', () { final values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; @@ -41,8 +41,7 @@ void main() { expect(result, '[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]'); }); - test( - 'makeDescription return a String with ' + test('makeDescription return a String with ' 'single qouted strings', () { final values = ['one', 'two', 'three']; @@ -51,8 +50,7 @@ void main() { expect(result, "[ 'one', 'two', 'three' ]"); }); - test( - 'makeDescription return a String with ' + test('makeDescription return a String with ' 'single qouted strings and unqouted other object', () { final values = [ 'one', @@ -77,8 +75,7 @@ void main() { ); }); - test( - 'makeDescription return a String with ' + test('makeDescription return a String with ' 'formatted output by customDescriptionBuilder ', () { final values = [1, 2, 3]; @@ -95,8 +92,7 @@ void main() { expect(result, '[ Group description | 1 | 3 ]'); }); - test( - 'makeDescription return a String with ' + test('makeDescription return a String with ' 'formatted output by customDescriptionBuilder ' 'and complex object as group description', () { final values = [1, 2, 3]; @@ -128,25 +124,13 @@ void main() { ); const dynamic singleValue = 1; - expect( - pTest.parseValues(valuesWithOption), - valuesWithOption, - ); - expect( - pTest.parseValues(values), - (values: values, testOptions: null), - ); + expect(pTest.parseValues(valuesWithOption), valuesWithOption); + expect(pTest.parseValues(values), (values: values, testOptions: null)); expect( pTest.parseValues(singleValue), - isA().having( - (value) => value.values, - 'values', - [singleValue], - ).having( - (value) => value.testOptions, - 'testOptions', - null, - ), + isA() + .having((value) => value.values, 'values', [singleValue]) + .having((value) => value.testOptions, 'testOptions', null), ); }); @@ -157,11 +141,9 @@ void main() { expect(tearDownMock.setupCaptures, isEmpty); }); - test('setUp/tearDown is called if when provided', () { - // ignore: prefer_function_declarations_over_variables - final setUpCall = () => print('setUp'); - // ignore: prefer_function_declarations_over_variables - final tearDownCall = () => print('tearDown'); + test('setUp/tearDown is called when provided', () { + void setUpCall() => print('setUp'); + void tearDownCall() => print('tearDown'); pTest( 'test', @@ -183,8 +165,7 @@ void main() { expect(groupMock.testCaptures, hasLength(1)); }); - test( - 'group is called with right parameters ' + test('group is called with right parameters ' '[ description, testOn, timeout, skip, tags, onPlatform, retry ]', () { const description = 'description'; const testOn = 'testOn'; @@ -217,8 +198,7 @@ void main() { expect(result.retry, retry); }); - test( - 'group is called with right parameters ' + test('group is called with right parameters ' 'options on value are not passed to group ' '[ description, testOn, timeout, skip, tags, onPlatform, retry ]', () { const description = 'description'; @@ -372,8 +352,7 @@ void main() { }); group('parameterized test exception handling tests', () { - test( - 'test throws ParameterizedError when length values and length ' + test('test throws ParameterizedError when length values and length ' 'function arguments dont match', () { expect( () => @@ -382,31 +361,26 @@ void main() { ); expect( - () => pTest( - 'test', - [ - [1, 2], - [3, 4], - [5, 6], - ], - (int value) => value, - ), + () => pTest('test', [ + [1, 2], + [3, 4], + [5, 6], + ], (int value) => value), throwsA(isA()), ); }); - test( - 'nested test throws ParameterizedError when length values and length ' + test('nested test throws ParameterizedError when length values and length ' 'function arguments dont match', () { expect( () => pTest( 'test', [1, 2, 3], - (int value) => pTest( - 'test', - [1, 2, 3], - (int value, int value2) => value + value2, - ), + (int value) => pTest('test', [ + 1, + 2, + 3, + ], (int value, int value2) => value + value2), ), throwsA(isA()), ); @@ -415,22 +389,17 @@ void main() { () => pTest( 'test', [1], - (int value) => pTest( - 'test', - [ - [1, 2], - [3, 4], - [5, 6], - ], - (int value) => value, - ), + (int value) => pTest('test', [ + [1, 2], + [3, 4], + [5, 6], + ], (int value) => value), ), throwsA(isA()), ); }); - test( - 'test throws ParameterizedError when values types and ' + test('test throws ParameterizedError when values types and ' 'function arguments types dont match', () { expect( () => pTest('test', [1, 2, 3], (String value) => value), @@ -438,28 +407,23 @@ void main() { ); expect( - () => pTest( - 'test', - [ - [1, 2], - [3, 4], - [5, 6], - ], - (int value, String value2) => value + value2.length, - ), + () => pTest('test', [ + [1, 2], + [3, 4], + [5, 6], + ], (int value, String value2) => value + value2.length), throwsA(isA()), ); }); - test( - 'nested test throws ParameterizedError when values types and ' + test('nested test throws ParameterizedError when values types and ' 'function arguments types dont match', () { expect( - () => pTest( - 'test', - [1, 2, 3], - (int value) => pTest('test', [1, 2, 3], (String value) => value), - ), + () => pTest('test', [ + 1, + 2, + 3, + ], (int value) => pTest('test', [1, 2, 3], (String value) => value)), throwsA(isA()), ); @@ -467,34 +431,31 @@ void main() { () => pTest( 'test', [1], - (int value) => pTest( - 'test', - [ - [1, 2], - [3, 4], - [5, 6], - ], - (int value, String value2) => value + value2.length, - ), + (int value) => pTest('test', [ + [1, 2], + [3, 4], + [5, 6], + ], (int value, String value2) => value + value2.length), ), throwsA(isA()), ); }); - test('test doesnt catch TypeError when the test body throws the exception', - () { - expect( - () => pTest('test', [1, 2, 3], (int value) { - // Causes a TypeError for test - // ignore: unused_local_variable - final error = value as String; - }), - throwsA(isA()), - ); - }); - test( - 'nested test doesnt catch TypeError when the test body ' + 'test doesnt catch TypeError when the test body throws the exception', + () { + expect( + () => pTest('test', [1, 2, 3], (int value) { + // Causes a TypeError for test + // ignore: unused_local_variable + final error = value as String; + }), + throwsA(isA()), + ); + }, + ); + + test('nested test doesnt catch TypeError when the test body ' 'throws the exception', () { expect( () => pTest( @@ -510,8 +471,7 @@ void main() { ); }); - test( - 'test doesnt catch NoSuchMethodError when the test body ' + test('test doesnt catch NoSuchMethodError when the test body ' 'throws the exception', () { expect( () => pTest('test', [1, 2, 3], (int value) { @@ -525,8 +485,7 @@ void main() { ); }); - test( - 'nested test doesnt catch NoSuchMethodError when the test body ' + test('nested test doesnt catch NoSuchMethodError when the test body ' 'throws the exception from a object', () { expect( () => pTest( @@ -544,8 +503,7 @@ void main() { ); }); - test( - 'nested test doesnt catch NoSuchMethodError when the test body ' + test('nested test doesnt catch NoSuchMethodError when the test body ' 'throws the exception from a Function.apply', () { expect( () => pTest( @@ -559,30 +517,25 @@ void main() { ); }); - test('test doesnt catch exceptions other than NoSuchMethodError, TypeError', - () { - expect( - () => pTest( - 'test', - [1, 2, 3], - (int value) => throw Exception('test'), - ), - throwsA(isA()), - ); - }); - test( - 'nested test doesnt catch exceptions other than ' + 'test doesnt catch exceptions other than NoSuchMethodError, TypeError', + () { + expect( + () => + pTest('test', [1, 2, 3], (int value) => throw Exception('test')), + throwsA(isA()), + ); + }, + ); + + test('nested test doesnt catch exceptions other than ' 'NoSuchMethodError, TypeError', () { expect( () => pTest( 'test', [1, 2, 3], - (int value) => pTest( - 'test', - [1, 2, 3], - (int value) => throw Exception('test'), - ), + (int value) => + pTest('test', [1, 2, 3], (int value) => throw Exception('test')), ), throwsA(isA()), ); diff --git a/test/stack_trace_extension_test.dart b/test/stack_trace_extension_test.dart index 5e32c89..14ae02a 100644 --- a/test/stack_trace_extension_test.dart +++ b/test/stack_trace_extension_test.dart @@ -54,10 +54,8 @@ void main() { }, ); - test( - 'StackTrace with no function.apply call', - () { - final stackTrace = Trace.parse(''' + test('StackTrace with no function.apply call', () { + final stackTrace = Trace.parse(''' #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 _objectNoSuchMethod (dart:core-patch/object_patch.dart:85:9) #2 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) @@ -66,31 +64,25 @@ void main() { #5 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) '''); - final result = stackTrace.isInsideTestBody; + final result = stackTrace.isInsideTestBody; - expect(result, isFalse); - }, - ); + expect(result, isFalse); + }); - test( - 'StackTrace with no parameterized_test call', - () { - final stackTrace = Trace.parse(''' + test('StackTrace with no parameterized_test call', () { + final stackTrace = Trace.parse(''' #0 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) #1 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) '''); - final result = stackTrace.isInsideTestBody; + final result = stackTrace.isInsideTestBody; - expect(result, isFalse); - }, - ); + expect(result, isFalse); + }); - test( - 'StackTrace with other call then core or parameterized_test ' - 'before function.apply', - () { - final stackTrace = Trace.parse(''' + test('StackTrace with other call then core or parameterized_test ' + 'before function.apply', () { + final stackTrace = Trace.parse(''' #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 _objectNoSuchMethod (dart:core-patch/object_patch.dart:85:9) #2 main.... (file:///parameterized_test/test/parameterized_test_test.dart:490:31) @@ -99,17 +91,14 @@ void main() { #5 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) '''); - final result = stackTrace.isInsideTestBody; + final result = stackTrace.isInsideTestBody; - expect(result, isTrue); - }, - ); + expect(result, isTrue); + }); - test( - 'StackTrace with multiple other call then core or parameterized_test ' - 'before function.apply', - () { - final stackTrace = Trace.parse(''' + test('StackTrace with multiple other call then core or parameterized_test ' + 'before function.apply', () { + final stackTrace = Trace.parse(''' #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 main.... (file:///parameterized_test/test/parameterized_test_test.dart:490:31) #2 _objectNoSuchMethod (dart:core-patch/object_patch.dart:85:9) @@ -119,17 +108,14 @@ void main() { #6 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) '''); - final result = stackTrace.isInsideTestBody; + final result = stackTrace.isInsideTestBody; - expect(result, isTrue); - }, - ); + expect(result, isTrue); + }); - test( - 'StackTrace with multiple other call then core or parameterized_test ' - 'before function.apply', - () { - final stackTrace = Trace.parse(''' + test('StackTrace with multiple other call then core or parameterized_test ' + 'before function.apply', () { + final stackTrace = Trace.parse(''' #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 main.... (file:///parameterized_test/test/parameterized_test_test.dart:490:31) #2 Function._apply (dart:core-patch/function_patch.dart:11:71) @@ -141,17 +127,14 @@ void main() { #8 ParameterizedTestImpl.call.. (package:parameterized_test/src/parameterized_test.dart:162:33) '''); - final result = stackTrace.isInsideTestBody; + final result = stackTrace.isInsideTestBody; - expect(result, isTrue); - }, - ); + expect(result, isTrue); + }); - test( - 'StackTrace with multiple other call then core or parameterized_test ' - 'after function.apply', - () { - final stackTrace = Trace.parse(''' + test('StackTrace with multiple other call then core or parameterized_test ' + 'after function.apply', () { + final stackTrace = Trace.parse(''' #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 _objectNoSuchMethod (dart:core-patch/object_patch.dart:85:9) #2 Function._apply (dart:core-patch/function_patch.dart:11:71) @@ -161,11 +144,10 @@ void main() { #6 main.... (file:///parameterized_test/test/parameterized_test_test.dart:490:31) '''); - final result = stackTrace.isInsideTestBody; + final result = stackTrace.isInsideTestBody; - expect(result, isFalse); - }, - ); + expect(result, isFalse); + }); test('empty stack trace', () { const stackTrace = StackTrace.empty; diff --git a/test/test_options_ext_test.dart b/test/test_options_ext_test.dart index 7633c69..1440150 100644 --- a/test/test_options_ext_test.dart +++ b/test/test_options_ext_test.dart @@ -5,19 +5,13 @@ import 'package:test/test.dart'; void main() { test('Object test options extensions test', () { // act - final result = [ - 1, - 3.options(skip: 'not now'), - ]; + final result = [1, 3.options(skip: 'not now')]; expect( result[1], const TypeMatcher() - .having((value) => value.values, 'value', [3]).having( - (value) => value.testOptions?.skip, - 'skip', - 'not now', - ), + .having((value) => value.values, 'value', [3]) + .having((value) => value.testOptions?.skip, 'skip', 'not now'), ); }); @@ -31,11 +25,8 @@ void main() { expect( result[1], const TypeMatcher() - .having((value) => value.values, 'value', [3, 4]).having( - (value) => value.testOptions?.skip, - 'skip', - 'not now', - ), + .having((value) => value.values, 'value', [3, 4]) + .having((value) => value.testOptions?.skip, 'skip', 'not now'), ); }); }