Migrate to nullsafety
diff --git a/pkgs/test_reflective_loader/CHANGELOG.md b/pkgs/test_reflective_loader/CHANGELOG.md index 616d021..7efa79c 100644 --- a/pkgs/test_reflective_loader/CHANGELOG.md +++ b/pkgs/test_reflective_loader/CHANGELOG.md
@@ -1,3 +1,7 @@ +## 0.2.0-nullsafety.0 + +- Migrate to the null safety language feature. + ## 0.1.9 - Add `@SkippedTest` annotation and `skip_test` prefix.
diff --git a/pkgs/test_reflective_loader/lib/test_reflective_loader.dart b/pkgs/test_reflective_loader/lib/test_reflective_loader.dart index 6430c66..04caa51 100644 --- a/pkgs/test_reflective_loader/lib/test_reflective_loader.dart +++ b/pkgs/test_reflective_loader/lib/test_reflective_loader.dart
@@ -38,7 +38,7 @@ final List<_Group> _currentGroups = <_Group>[]; int _currentSuiteLevel = 0; -String _currentSuiteName = null; +String? _currentSuiteName = null; /** * Is `true` the application is running in the checked mode. @@ -58,8 +58,8 @@ * create embedded suites. If the current suite is the top-level one, perform * check for "solo" groups and tests, and run all or only "solo" items. */ -void defineReflectiveSuite(void define(), {String name}) { - String groupName = _currentSuiteName; +void defineReflectiveSuite(void define(), {String? name}) { + String? groupName = _currentSuiteName; _currentSuiteLevel++; try { _currentSuiteName = _combineNames(_currentSuiteName, name); @@ -167,13 +167,13 @@ */ void _addTestsIfTopLevelSuite() { if (_currentSuiteLevel == 0) { - void runTests({bool allGroups, bool allTests}) { + void runTests({/*required*/ required bool allGroups, /*required*/ required bool allTests}) { for (_Group group in _currentGroups) { if (allGroups || group.isSolo) { for (_Test test in group.tests) { if (allTests || test.isSolo) { - test_package.test(test.name, test.function, - timeout: test.timeout, skip: test.isSkipped); + test_package.test(test.name, test.function!, + timeout: test.timeout!, skip: test.isSkipped); } } } @@ -195,7 +195,7 @@ * Return the combination of the [base] and [addition] names. * If any other two is `null`, then the other one is returned. */ -String _combineNames(String base, String addition) { +String? _combineNames(String? base, String? addition) { if (base == null) { return addition; } else if (addition == null) { @@ -205,7 +205,7 @@ } } -Object _getAnnotationInstance(DeclarationMirror declaration, Type type) { +Object? _getAnnotationInstance(DeclarationMirror declaration, Type type) { for (InstanceMirror annotation in declaration.metadata) { if (annotation.reflectee.runtimeType == type) { return annotation.reflectee; @@ -227,9 +227,9 @@ bool _hasSkippedTestAnnotation(MethodMirror method) => _hasAnnotationInstance(method, skippedTest); -Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { - var invocationResult = null; - InstanceMirror closure; +Future<Object?> _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { + Object? invocationResult = null; + InstanceMirror? closure; try { closure = instanceMirror.getField(symbol); } on NoSuchMethodError {} @@ -248,7 +248,7 @@ * - The test returns a future which completes with an error. * - An exception is thrown to the zone handler from a timer task. */ -Future _runFailingTest(ClassMirror classMirror, Symbol symbol) { +Future<void> _runFailingTest(ClassMirror classMirror, Symbol symbol) { bool passed = false; return runZoned(() { return new Future.sync(() => _runTest(classMirror, symbol)).then((_) { @@ -270,7 +270,7 @@ }); } -Future _runTest(ClassMirror classMirror, Symbol symbol) { +Future<void> _runTest(ClassMirror classMirror, Symbol symbol) { InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); return _invokeSymbolIfExists(instanceMirror, #setUp) .then((_) => instanceMirror.invoke(symbol, []).reflectee) @@ -289,7 +289,7 @@ * [issue] is a full URI describing the failure and used for tracking. * [reason] is a free form textual description. */ - const FailingTest({String issue, String reason}); + const FailingTest({String? issue, String? reason}); } /** @@ -302,7 +302,7 @@ * [issue] is a full URI describing the failure and used for tracking. * [reason] is a free form textual description. */ - const SkippedTest({String issue, String reason}); + const SkippedTest({String? issue, String? reason}); } /** @@ -331,7 +331,7 @@ */ class _Group { final bool isSolo; - final String name; + final String? name; final List<_Test> tests = <_Test>[]; _Group(this.isSolo, this.name); @@ -339,14 +339,14 @@ bool get hasSoloTest => tests.any((test) => test.isSolo); void addSkippedTest(String name) { - String fullName = _combineNames(this.name, name); + String? fullName = _combineNames(this.name, name); tests.add(new _Test.skipped(isSolo, fullName)); } void addTest(bool isSolo, String name, MethodMirror memberMirror, _TestFunction function) { - String fullName = _combineNames(this.name, name); - TestTimeout timeout = _getAnnotationInstance(memberMirror, TestTimeout); + String? fullName = _combineNames(this.name, name); + var timeout = _getAnnotationInstance(memberMirror, TestTimeout) as TestTimeout?; tests.add(new _Test(isSolo, fullName, function, timeout?._timeout)); } } @@ -371,9 +371,9 @@ */ class _Test { final bool isSolo; - final String name; - final _TestFunction function; - final test_package.Timeout timeout; + final String? name; + final _TestFunction? function; + final test_package.Timeout? timeout; final bool isSkipped;
diff --git a/pkgs/test_reflective_loader/pubspec.yaml b/pkgs/test_reflective_loader/pubspec.yaml index 8cfc3fa..75df05f 100644 --- a/pkgs/test_reflective_loader/pubspec.yaml +++ b/pkgs/test_reflective_loader/pubspec.yaml
@@ -1,12 +1,12 @@ name: test_reflective_loader -version: 0.1.9 +version: 0.2.0-nullsafety.0 description: Support for discovering tests and test suites using reflection. author: Dart Team <misc@dartlang.org> homepage: https://github.com/dart-lang/test_reflective_loader environment: - sdk: '>=1.8.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: test: '>=0.12.0 <2.0.0'
diff --git a/pkgs/test_reflective_loader/test/test_reflective_loader_test.dart b/pkgs/test_reflective_loader/test/test_reflective_loader_test.dart index a657b04..2c69cce 100644 --- a/pkgs/test_reflective_loader/test/test_reflective_loader_test.dart +++ b/pkgs/test_reflective_loader/test/test_reflective_loader_test.dart
@@ -15,8 +15,6 @@ @reflectiveTest class TestReflectiveLoaderTest { - String pathname; - void test_passes() { expect(true, true); }