From f18fbbc50fa470babfeb2eceb04758ef1352b067 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 30 Dec 2021 18:25:08 -0700 Subject: [PATCH 1/3] Migrate several test files to null safety --- test/io_utils_test.dart | 2 -- test/markdown_processor_test.dart | 2 -- test/model_utils_test.dart | 2 -- test/quiver_test.dart | 16 ---------------- test/resource_loader_test.dart | 9 +-------- test/source_linker_test.dart | 2 -- test/tool_runner_test.dart | 24 ++++++++++-------------- test/utils_test.dart | 6 ++---- test/warnings_test.dart | 17 +++++++---------- 9 files changed, 20 insertions(+), 60 deletions(-) diff --git a/test/io_utils_test.dart b/test/io_utils_test.dart index 119d0421b8..ee24db4243 100644 --- a/test/io_utils_test.dart +++ b/test/io_utils_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.io_utils_test; import 'package:dartdoc/src/io_utils.dart'; diff --git a/test/markdown_processor_test.dart b/test/markdown_processor_test.dart index 9a5dce0a83..61a900bad2 100644 --- a/test/markdown_processor_test.dart +++ b/test/markdown_processor_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.markdown_processor_test; import 'package:dartdoc/src/markdown_processor.dart'; diff --git a/test/model_utils_test.dart b/test/model_utils_test.dart index 1705a51362..850c2d4901 100644 --- a/test/model_utils_test.dart +++ b/test/model_utils_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.model_utils_test; import 'package:dartdoc/src/model_utils.dart'; diff --git a/test/quiver_test.dart b/test/quiver_test.dart index a44c2f1330..07cdb6e472 100644 --- a/test/quiver_test.dart +++ b/test/quiver_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - import 'package:dartdoc/src/quiver.dart'; import 'package:test/test.dart'; @@ -30,20 +28,6 @@ void main() { [1, 2, 3, -1, -2, -3]); }); - test('should throw for null input', () { - expect(() => concat(null), throwsNoSuchMethodError); - }); - - test('should throw if any input is null', () { - expect( - () => concat([ - [1, 2], - null, - [3, 4] - ]).toList(), - throwsNoSuchMethodError); - }); - test('should reflectchanges in the inputs', () { var a = [1, 2]; var b = [4, 5]; diff --git a/test/resource_loader_test.dart b/test/resource_loader_test.dart index 2962f71ba9..8b267a9312 100644 --- a/test/resource_loader_test.dart +++ b/test/resource_loader_test.dart @@ -2,22 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.resource_loader_test; -import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/file_system/physical_file_system.dart'; import 'package:dartdoc/src/generator/resource_loader.dart'; import 'package:test/test.dart'; void main() { group('Resource Loader', () { - ResourceProvider resourceProvider; - - setUp(() { - resourceProvider = PhysicalResourceProvider(); - }); + var resourceProvider = PhysicalResourceProvider(); test('load from packages', () async { var contents = await resourceProvider diff --git a/test/source_linker_test.dart b/test/source_linker_test.dart index 3dadd46e89..3cf1f50f56 100644 --- a/test/source_linker_test.dart +++ b/test/source_linker_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.source_linker_test; import 'package:dartdoc/src/dartdoc_options.dart'; diff --git a/test/tool_runner_test.dart b/test/tool_runner_test.dart index 20985b7d99..18fab74391 100644 --- a/test/tool_runner_test.dart +++ b/test/tool_runner_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.model_test; import 'dart:io'; @@ -21,18 +19,17 @@ final Directory _toolExecutableDir = Directory('testing/tool_executables'); void main() { ToolConfiguration toolMap; - Directory tempDir; - File setupFile; + Directory? tempDir; + late File setupFile; - ToolRunner runner; - ToolTempFileTracker tracker; - ToolErrorCallback errorCallback; + late ToolRunner runner; + late ToolErrorCallback errorCallback; final errors = []; setUpAll(() async { - ProcessResult result; + ProcessResult? result; tempDir = Directory.systemTemp.createTempSync('tool_runner_test_'); - var snapshotFile = path.join(tempDir.path, 'drill.snapshot'); + var snapshotFile = path.join(tempDir!.path, 'drill.snapshot'); try { result = Process.runSync( Platform.resolvedExecutable, @@ -52,7 +49,7 @@ void main() { stderr.writeln(result.stderr); } expect(result?.exitCode, equals(0)); - setupFile = File(path.join(tempDir.path, 'setup.stamp')); + setupFile = File(path.join(tempDir!.path, 'setup.stamp')); var nonDartName = Platform.isWindows ? 'non_dart.bat' : 'non_dart.sh'; var nonDartExecutable = path.join(_toolExecutableDir.absolute.path, nonDartName); @@ -94,13 +91,11 @@ echo: runner = ToolRunner(toolMap); errorCallback = (String message) => errors.add(message); }); + tearDownAll(() { tempDir?.deleteSync(recursive: true); - tracker?.dispose(); SnapshotCache.instanceFor(pubPackageMetaProvider.resourceProvider) .dispose(); - setupFile = null; - tempDir = null; }); group('ToolRunner', () { @@ -110,7 +105,8 @@ echo: // This test must come first, to verify that the first run creates // a snapshot. test('Tool definition includes compile arguments.', () async { - DartToolDefinition definition = runner.toolConfiguration.tools['drill']; + var definition = + runner.toolConfiguration.tools['drill'] as DartToolDefinition; expect(definition.compileArgs, equals(['--no-sound-null-safety'])); }); test('can invoke a Dart tool, and second run is a snapshot.', () async { diff --git a/test/utils_test.dart b/test/utils_test.dart index 4dcf171d2b..28a75e2c72 100644 --- a/test/utils_test.dart +++ b/test/utils_test.dart @@ -2,16 +2,14 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.utils_test; import 'package:dartdoc/src/utils.dart'; import 'package:test/test.dart'; void main() { - String comment; - String documentation; + late String comment; + late String documentation; // For readability, the multiline strings below have a left margin. This // is the length of that left margin. diff --git a/test/warnings_test.dart b/test/warnings_test.dart index f4f571abf9..d38455dce3 100644 --- a/test/warnings_test.dart +++ b/test/warnings_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - /// Unit tests for lib/src/warnings.dart. library dartdoc.warnings_test; @@ -17,12 +15,11 @@ import 'package:test/test.dart'; void main() { ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; - Folder tempDir, testPackageOne, testPackageTwo, testPackageThree; - File pubspecYamlOne, pubspecYamlTwo, pubspecYamlThree, dartdocYamlThree; - DartdocOptionSet optionSet; + late Folder testPackageOne, testPackageTwo, testPackageThree; + late DartdocOptionSet optionSet; setUpAll(() { - tempDir = resourceProvider.createSystemTemp('warnings_test'); + var tempDir = resourceProvider.createSystemTemp('warnings_test'); testPackageOne = resourceProvider.getFolder( resourceProvider.pathContext.join(tempDir.path, 'test_package_one')) ..create(); @@ -32,13 +29,13 @@ void main() { testPackageThree = resourceProvider.getFolder( resourceProvider.pathContext.join(tempDir.path, 'test_package_three')) ..create(); - pubspecYamlOne = resourceProvider.getFile( + var pubspecYamlOne = resourceProvider.getFile( resourceProvider.pathContext.join(testPackageOne.path, 'pubspec.yaml')); pubspecYamlOne.writeAsStringSync('name: test_package_one'); - pubspecYamlTwo = resourceProvider.getFile( + var pubspecYamlTwo = resourceProvider.getFile( resourceProvider.pathContext.join(testPackageTwo.path, 'pubspec.yaml')); pubspecYamlTwo.writeAsStringSync('name: test_package_two'); - dartdocYamlThree = resourceProvider.getFile(resourceProvider.pathContext + var dartdocYamlThree = resourceProvider.getFile(resourceProvider.pathContext .join(testPackageThree.path, 'dartdoc_options.yaml')); dartdocYamlThree.writeAsStringSync(''' dartdoc: @@ -50,7 +47,7 @@ dartdoc: ignore: - ambiguous-reexport '''); - pubspecYamlThree = resourceProvider.getFile(resourceProvider.pathContext + var pubspecYamlThree = resourceProvider.getFile(resourceProvider.pathContext .join(testPackageThree.path, 'pubspec.yaml')); pubspecYamlThree.writeAsStringSync('name: test_package_three'); }); From 4e59993dd34a6966125061da5e934524e91ae708 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 31 Dec 2021 08:42:38 -0700 Subject: [PATCH 2/3] revert io_utils_test --- test/io_utils_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/io_utils_test.dart b/test/io_utils_test.dart index ee24db4243..119d0421b8 100644 --- a/test/io_utils_test.dart +++ b/test/io_utils_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart=2.9 + library dartdoc.io_utils_test; import 'package:dartdoc/src/io_utils.dart'; From bef6172a727b8263145a8942a91a474cc98a7255 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 31 Dec 2021 16:16:41 -0700 Subject: [PATCH 3/3] revert warnings_test; weird failures --- test/warnings_test.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/warnings_test.dart b/test/warnings_test.dart index d38455dce3..e4abd2320a 100644 --- a/test/warnings_test.dart +++ b/test/warnings_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart=2.9 + /// Unit tests for lib/src/warnings.dart. library dartdoc.warnings_test; @@ -15,8 +17,8 @@ import 'package:test/test.dart'; void main() { ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; - late Folder testPackageOne, testPackageTwo, testPackageThree; - late DartdocOptionSet optionSet; + Folder testPackageOne, testPackageTwo, testPackageThree; + DartdocOptionSet optionSet; setUpAll(() { var tempDir = resourceProvider.createSystemTemp('warnings_test');