diff --git a/.github/workflows/very_good_test_runner.yaml b/.github/workflows/very_good_test_runner.yaml index 3c8e4ae..b50da91 100644 --- a/.github/workflows/very_good_test_runner.yaml +++ b/.github/workflows/very_good_test_runner.yaml @@ -13,12 +13,6 @@ on: jobs: build: - strategy: - matrix: - flutter_version: - - "3.24.0" # The Flutter version with a Dart SDK that matches the minimum Dart SDK version supported by the package. - - "3.x" # The Flutter version with a Dart SDK that matches the maximum Dart SDK version supported by the package. - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 with: - flutter_version: ${{ matrix.flutter_version }} + flutter_version: "3.35.x" diff --git a/analysis_options.yaml b/analysis_options.yaml index c2f4cbb..9df80aa 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1 @@ -include: package:very_good_analysis/analysis_options.7.0.0.yaml +include: package:very_good_analysis/analysis_options.yaml diff --git a/build.yaml b/build.yaml index 650337e..f3b8985 100644 --- a/build.yaml +++ b/build.yaml @@ -9,6 +9,7 @@ targets: - cast_nullable_to_non_nullable - require_trailing_commas - lines_longer_than_80_chars + - specify_nonobvious_property_types json_serializable: options: create_to_json: false diff --git a/example/main.dart b/example/main.dart index 5345e8f..b18c41c 100644 --- a/example/main.dart +++ b/example/main.dart @@ -1,3 +1,4 @@ +// This is not production code. // ignore_for_file: avoid_print import 'package:very_good_test_runner/very_good_test_runner.dart'; diff --git a/lib/src/models/test_event.dart b/lib/src/models/test_event.dart index ba4f844..07d6f62 100644 --- a/lib/src/models/test_event.dart +++ b/lib/src/models/test_event.dart @@ -15,32 +15,20 @@ abstract class TestEvent { /// Converts [json] into a [TestEvent]. static TestEvent fromJson(Map json) { final type = json['type'] as String?; - switch (type) { - case 'start': - return StartTestEvent.fromJson(json); - case 'allSuites': - return AllSuitesTestEvent.fromJson(json); - case 'suite': - return SuiteTestEvent.fromJson(json); - case 'debug': - return DebugTestEvent.fromJson(json); - case 'group': - return GroupTestEvent.fromJson(json); - case 'testStart': - return TestStartEvent.fromJson(json); - case 'print': - return MessageTestEvent.fromJson(json); - case 'error': - return ErrorTestEvent.fromJson(json); - case 'testDone': - return TestDoneEvent.fromJson(json); - case 'done': - return DoneTestEvent.fromJson(json); - case 'exit': - return ExitTestEvent.fromJson(json); - default: - throw UnsupportedError('Unsupported type: $type'); - } + return switch (type) { + 'start' => StartTestEvent.fromJson(json), + 'allSuites' => AllSuitesTestEvent.fromJson(json), + 'suite' => SuiteTestEvent.fromJson(json), + 'debug' => DebugTestEvent.fromJson(json), + 'group' => GroupTestEvent.fromJson(json), + 'testStart' => TestStartEvent.fromJson(json), + 'print' => MessageTestEvent.fromJson(json), + 'error' => ErrorTestEvent.fromJson(json), + 'testDone' => TestDoneEvent.fromJson(json), + 'done' => DoneTestEvent.fromJson(json), + 'exit' => ExitTestEvent.fromJson(json), + _ => throw UnsupportedError('Unsupported type: $type'), + }; } /// The type of the event. @@ -275,7 +263,7 @@ enum TestResult { failure, /// the test had an error other than `TestFailure` - error + error, } /// {@template test_done_event} @@ -341,7 +329,7 @@ class DoneTestEvent extends TestEvent { class ExitTestEvent extends TestEvent { /// {@macro test_exit_event} const ExitTestEvent({required super.time, required this.exitCode}) - : super(type: 'exit'); + : super(type: 'exit'); /// {@macro test_exit_event} factory ExitTestEvent.fromJson(Map json) => diff --git a/lib/src/models/test_event.g.dart b/lib/src/models/test_event.g.dart index bca7a9c..84e8b58 100644 --- a/lib/src/models/test_event.g.dart +++ b/lib/src/models/test_event.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: document_ignores, implicit_dynamic_parameter, cast_nullable_to_non_nullable, require_trailing_commas, lines_longer_than_80_chars +// ignore_for_file: document_ignores, implicit_dynamic_parameter, cast_nullable_to_non_nullable, require_trailing_commas, lines_longer_than_80_chars, specify_nonobvious_property_types part of 'test_event.dart'; @@ -9,139 +9,109 @@ part of 'test_event.dart'; // ************************************************************************** StartTestEvent _$StartTestEventFromJson(Map json) => - $checkedCreate( - 'StartTestEvent', - json, - ($checkedConvert) { - final val = StartTestEvent( - protocolVersion: - $checkedConvert('protocolVersion', (v) => v as String), - runnerVersion: $checkedConvert('runnerVersion', (v) => v as String?), - pid: $checkedConvert('pid', (v) => (v as num).toInt()), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('StartTestEvent', json, ($checkedConvert) { + final val = StartTestEvent( + protocolVersion: $checkedConvert('protocolVersion', (v) => v as String), + runnerVersion: $checkedConvert('runnerVersion', (v) => v as String?), + pid: $checkedConvert('pid', (v) => (v as num).toInt()), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); AllSuitesTestEvent _$AllSuitesTestEventFromJson(Map json) => - $checkedCreate( - 'AllSuitesTestEvent', - json, - ($checkedConvert) { - final val = AllSuitesTestEvent( - count: $checkedConvert('count', (v) => (v as num).toInt()), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('AllSuitesTestEvent', json, ($checkedConvert) { + final val = AllSuitesTestEvent( + count: $checkedConvert('count', (v) => (v as num).toInt()), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); SuiteTestEvent _$SuiteTestEventFromJson(Map json) => - $checkedCreate( - 'SuiteTestEvent', - json, - ($checkedConvert) { - final val = SuiteTestEvent( - suite: $checkedConvert( - 'suite', (v) => TestSuite.fromJson(v as Map)), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('SuiteTestEvent', json, ($checkedConvert) { + final val = SuiteTestEvent( + suite: $checkedConvert( + 'suite', + (v) => TestSuite.fromJson(v as Map), + ), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); DebugTestEvent _$DebugTestEventFromJson(Map json) => - $checkedCreate( - 'DebugTestEvent', - json, - ($checkedConvert) { - final val = DebugTestEvent( - suiteID: $checkedConvert('suiteID', (v) => (v as num).toInt()), - observatory: $checkedConvert('observatory', (v) => v as String?), - remoteDebugger: - $checkedConvert('remoteDebugger', (v) => v as String?), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('DebugTestEvent', json, ($checkedConvert) { + final val = DebugTestEvent( + suiteID: $checkedConvert('suiteID', (v) => (v as num).toInt()), + observatory: $checkedConvert('observatory', (v) => v as String?), + remoteDebugger: $checkedConvert('remoteDebugger', (v) => v as String?), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); GroupTestEvent _$GroupTestEventFromJson(Map json) => - $checkedCreate( - 'GroupTestEvent', - json, - ($checkedConvert) { - final val = GroupTestEvent( - group: $checkedConvert( - 'group', (v) => TestGroup.fromJson(v as Map)), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('GroupTestEvent', json, ($checkedConvert) { + final val = GroupTestEvent( + group: $checkedConvert( + 'group', + (v) => TestGroup.fromJson(v as Map), + ), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); TestStartEvent _$TestStartEventFromJson(Map json) => - $checkedCreate( - 'TestStartEvent', - json, - ($checkedConvert) { - final val = TestStartEvent( - test: $checkedConvert( - 'test', (v) => Test.fromJson(v as Map)), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('TestStartEvent', json, ($checkedConvert) { + final val = TestStartEvent( + test: $checkedConvert( + 'test', + (v) => Test.fromJson(v as Map), + ), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); MessageTestEvent _$MessageTestEventFromJson(Map json) => - $checkedCreate( - 'MessageTestEvent', - json, - ($checkedConvert) { - final val = MessageTestEvent( - testID: $checkedConvert('testID', (v) => (v as num).toInt()), - messageType: $checkedConvert('messageType', (v) => v as String), - message: $checkedConvert('message', (v) => v as String), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('MessageTestEvent', json, ($checkedConvert) { + final val = MessageTestEvent( + testID: $checkedConvert('testID', (v) => (v as num).toInt()), + messageType: $checkedConvert('messageType', (v) => v as String), + message: $checkedConvert('message', (v) => v as String), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); ErrorTestEvent _$ErrorTestEventFromJson(Map json) => - $checkedCreate( - 'ErrorTestEvent', - json, - ($checkedConvert) { - final val = ErrorTestEvent( - testID: $checkedConvert('testID', (v) => (v as num).toInt()), - error: $checkedConvert('error', (v) => v as String), - stackTrace: $checkedConvert('stackTrace', (v) => v as String), - isFailure: $checkedConvert('isFailure', (v) => v as bool), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('ErrorTestEvent', json, ($checkedConvert) { + final val = ErrorTestEvent( + testID: $checkedConvert('testID', (v) => (v as num).toInt()), + error: $checkedConvert('error', (v) => v as String), + stackTrace: $checkedConvert('stackTrace', (v) => v as String), + isFailure: $checkedConvert('isFailure', (v) => v as bool), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); TestDoneEvent _$TestDoneEventFromJson(Map json) => - $checkedCreate( - 'TestDoneEvent', - json, - ($checkedConvert) { - final val = TestDoneEvent( - testID: $checkedConvert('testID', (v) => (v as num).toInt()), - result: $checkedConvert( - 'result', (v) => $enumDecode(_$TestResultEnumMap, v)), - hidden: $checkedConvert('hidden', (v) => v as bool), - skipped: $checkedConvert('skipped', (v) => v as bool), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('TestDoneEvent', json, ($checkedConvert) { + final val = TestDoneEvent( + testID: $checkedConvert('testID', (v) => (v as num).toInt()), + result: $checkedConvert( + 'result', + (v) => $enumDecode(_$TestResultEnumMap, v), + ), + hidden: $checkedConvert('hidden', (v) => v as bool), + skipped: $checkedConvert('skipped', (v) => v as bool), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); const _$TestResultEnumMap = { TestResult.success: 'success', @@ -150,99 +120,81 @@ const _$TestResultEnumMap = { }; DoneTestEvent _$DoneTestEventFromJson(Map json) => - $checkedCreate( - 'DoneTestEvent', - json, - ($checkedConvert) { - final val = DoneTestEvent( - success: $checkedConvert('success', (v) => v as bool?), - time: $checkedConvert('time', (v) => (v as num).toInt()), - ); - return val; - }, - ); + $checkedCreate('DoneTestEvent', json, ($checkedConvert) { + final val = DoneTestEvent( + success: $checkedConvert('success', (v) => v as bool?), + time: $checkedConvert('time', (v) => (v as num).toInt()), + ); + return val; + }); ExitTestEvent _$ExitTestEventFromJson(Map json) => - $checkedCreate( - 'ExitTestEvent', - json, - ($checkedConvert) { - final val = ExitTestEvent( - time: $checkedConvert('time', (v) => (v as num).toInt()), - exitCode: $checkedConvert('exitCode', (v) => (v as num).toInt()), - ); - return val; - }, - ); - -TestSuite _$TestSuiteFromJson(Map json) => $checkedCreate( - 'TestSuite', - json, - ($checkedConvert) { - final val = TestSuite( - id: $checkedConvert('id', (v) => (v as num).toInt()), - platform: $checkedConvert('platform', (v) => v as String), - path: $checkedConvert('path', (v) => v as String?), - ); - return val; - }, - ); - -TestGroup _$TestGroupFromJson(Map json) => $checkedCreate( - 'TestGroup', - json, - ($checkedConvert) { - final val = TestGroup( - id: $checkedConvert('id', (v) => (v as num).toInt()), - name: $checkedConvert('name', (v) => v as String), - suiteID: $checkedConvert('suiteID', (v) => (v as num).toInt()), - testCount: $checkedConvert('testCount', (v) => (v as num).toInt()), - metadata: $checkedConvert('metadata', - (v) => TestMetadata.fromJson(v as Map)), - parentID: $checkedConvert('parentID', (v) => (v as num?)?.toInt()), - line: $checkedConvert('line', (v) => (v as num?)?.toInt()), - column: $checkedConvert('column', (v) => (v as num?)?.toInt()), - url: $checkedConvert('url', (v) => v as String?), - ); - return val; - }, - ); + $checkedCreate('ExitTestEvent', json, ($checkedConvert) { + final val = ExitTestEvent( + time: $checkedConvert('time', (v) => (v as num).toInt()), + exitCode: $checkedConvert('exitCode', (v) => (v as num).toInt()), + ); + return val; + }); + +TestSuite _$TestSuiteFromJson(Map json) => + $checkedCreate('TestSuite', json, ($checkedConvert) { + final val = TestSuite( + id: $checkedConvert('id', (v) => (v as num).toInt()), + platform: $checkedConvert('platform', (v) => v as String), + path: $checkedConvert('path', (v) => v as String?), + ); + return val; + }); + +TestGroup _$TestGroupFromJson(Map json) => + $checkedCreate('TestGroup', json, ($checkedConvert) { + final val = TestGroup( + id: $checkedConvert('id', (v) => (v as num).toInt()), + name: $checkedConvert('name', (v) => v as String), + suiteID: $checkedConvert('suiteID', (v) => (v as num).toInt()), + testCount: $checkedConvert('testCount', (v) => (v as num).toInt()), + metadata: $checkedConvert( + 'metadata', + (v) => TestMetadata.fromJson(v as Map), + ), + parentID: $checkedConvert('parentID', (v) => (v as num?)?.toInt()), + line: $checkedConvert('line', (v) => (v as num?)?.toInt()), + column: $checkedConvert('column', (v) => (v as num?)?.toInt()), + url: $checkedConvert('url', (v) => v as String?), + ); + return val; + }); TestMetadata _$TestMetadataFromJson(Map json) => - $checkedCreate( - 'TestMetadata', - json, - ($checkedConvert) { - final val = TestMetadata( - skip: $checkedConvert('skip', (v) => v as bool), - skipReason: $checkedConvert('skipReason', (v) => v as String?), - ); - return val; - }, - ); - -Test _$TestFromJson(Map json) => $checkedCreate( - 'Test', - json, - ($checkedConvert) { - final val = Test( - id: $checkedConvert('id', (v) => (v as num).toInt()), - name: $checkedConvert('name', (v) => v as String), - suiteID: $checkedConvert('suiteID', (v) => (v as num).toInt()), - groupIDs: $checkedConvert( - 'groupIDs', - (v) => - (v as List).map((e) => (e as num).toInt()).toList()), - metadata: $checkedConvert('metadata', - (v) => TestMetadata.fromJson(v as Map)), - line: $checkedConvert('line', (v) => (v as num?)?.toInt()), - column: $checkedConvert('column', (v) => (v as num?)?.toInt()), - url: $checkedConvert('url', (v) => v as String?), - rootLine: $checkedConvert('rootLine', (v) => (v as num?)?.toInt()), - rootColumn: - $checkedConvert('rootColumn', (v) => (v as num?)?.toInt()), - rootUrl: $checkedConvert('rootUrl', (v) => v as String?), - ); - return val; - }, - ); + $checkedCreate('TestMetadata', json, ($checkedConvert) { + final val = TestMetadata( + skip: $checkedConvert('skip', (v) => v as bool), + skipReason: $checkedConvert('skipReason', (v) => v as String?), + ); + return val; + }); + +Test _$TestFromJson(Map json) => + $checkedCreate('Test', json, ($checkedConvert) { + final val = Test( + id: $checkedConvert('id', (v) => (v as num).toInt()), + name: $checkedConvert('name', (v) => v as String), + suiteID: $checkedConvert('suiteID', (v) => (v as num).toInt()), + groupIDs: $checkedConvert( + 'groupIDs', + (v) => (v as List).map((e) => (e as num).toInt()).toList(), + ), + metadata: $checkedConvert( + 'metadata', + (v) => TestMetadata.fromJson(v as Map), + ), + line: $checkedConvert('line', (v) => (v as num?)?.toInt()), + column: $checkedConvert('column', (v) => (v as num?)?.toInt()), + url: $checkedConvert('url', (v) => v as String?), + rootLine: $checkedConvert('rootLine', (v) => (v as num?)?.toInt()), + rootColumn: $checkedConvert('rootColumn', (v) => (v as num?)?.toInt()), + rootUrl: $checkedConvert('rootUrl', (v) => v as String?), + ); + return val; + }); diff --git a/lib/src/very_good_test_runner.dart b/lib/src/very_good_test_runner.dart index 32db4f6..8f93bf6 100644 --- a/lib/src/very_good_test_runner.dart +++ b/lib/src/very_good_test_runner.dart @@ -5,15 +5,16 @@ import 'package:universal_io/io.dart'; import 'package:very_good_test_runner/very_good_test_runner.dart'; /// Signature for `Process.start`. -typedef StartProcess = Future Function( - String executable, - List arguments, { - String? workingDirectory, - Map? environment, - bool includeParentEnvironment, - bool runInShell, - ProcessStartMode mode, -}); +typedef StartProcess = + Future Function( + String executable, + List arguments, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment, + bool runInShell, + ProcessStartMode mode, + }); /// Runs `dart test` and returns a stream of [TestEvent] /// reported by the process. diff --git a/pubspec.yaml b/pubspec.yaml index 84f3a85..328f410 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,16 +4,16 @@ homepage: https://github.com/VeryGoodOpenSource/very_good_test_runner version: 0.3.0 environment: - sdk: ^3.5.0 + sdk: ^3.8.0 dependencies: json_annotation: ^4.9.0 universal_io: ^2.2.2 dev_dependencies: - build_runner: ^2.4.12 - build_verify: ^3.1.0 - json_serializable: ^6.8.0 + build_runner: ^2.8.0 + build_verify: ^3.1.1 + json_serializable: ^6.11.1 mocktail: ^1.0.4 test: ^1.25.8 - very_good_analysis: ^7.0.0 + very_good_analysis: ^10.0.0 diff --git a/test/src/models/test_event_test.dart b/test/src/models/test_event_test.dart index 80b300e..93a08ad 100644 --- a/test/src/models/test_event_test.dart +++ b/test/src/models/test_event_test.dart @@ -4,8 +4,7 @@ import 'package:very_good_test_runner/very_good_test_runner.dart'; void main() { group('TestEvent', () { group('fromJson', () { - test( - 'throws UnsupportedError ' + test('throws UnsupportedError ' 'when object is not a supported test event', () { expect( () => TestEvent.fromJson({}), diff --git a/test/src/very_good_test_runner_test.dart b/test/src/very_good_test_runner_test.dart index a8f3138..de99b68 100644 --- a/test/src/very_good_test_runner_test.dart +++ b/test/src/very_good_test_runner_test.dart @@ -129,9 +129,9 @@ void main() { ''', ); expect( - dartTest(workingDirectory: tempDirectory.path) - .where((e) => e is DoneTestEvent) - .first, + dartTest( + workingDirectory: tempDirectory.path, + ).where((e) => e is DoneTestEvent).first, completes, ); }); @@ -241,9 +241,9 @@ void main() { ''', ); expect( - flutterTest(workingDirectory: tempDirectory.path) - .where((e) => e is DoneTestEvent) - .first, + flutterTest( + workingDirectory: tempDirectory.path, + ).where((e) => e is DoneTestEvent).first, completes, ); });