From a7e0d74b7616f6acf3847cad9259a73c0782b8e8 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 12 Jul 2022 16:42:26 -0700 Subject: [PATCH 1/6] Convert test files to null-safety --- dwds/test/build/ensure_version_test.dart | 2 -- dwds/test/build/min_sdk_test.dart | 7 +++---- .../expression_compiler_service_test.dart | 21 +++++++------------ dwds/test/extension_backend_test.dart | 4 +--- dwds/test/metadata/class_test.dart | 2 -- dwds/test/metadata_test.dart | 2 -- dwds/test/objects_test.dart | 12 +++++------ .../frontend_server_asset_reader_test.dart | 10 ++++----- dwds/test/sdk_configuration_test.dart | 14 ++++++------- dwds/test/skip_list_test.dart | 4 +--- dwds/test/web/batched_stream_test.dart | 2 -- 11 files changed, 29 insertions(+), 51 deletions(-) diff --git a/dwds/test/build/ensure_version_test.dart b/dwds/test/build/ensure_version_test.dart index 5b306a794..17bd18843 100644 --- a/dwds/test/build/ensure_version_test.dart +++ b/dwds/test/build/ensure_version_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 - @TestOn('vm') import 'dart:io'; diff --git a/dwds/test/build/min_sdk_test.dart b/dwds/test/build/min_sdk_test.dart index c3676a544..8d7817f54 100644 --- a/dwds/test/build/min_sdk_test.dart +++ b/dwds/test/build/min_sdk_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 - @TestOn('vm') @Skip('Intended to run in analyze stage on stable SDK only, see mono_pkg.yaml') import 'dart:io'; @@ -19,8 +17,9 @@ void main() { sdkVersion = Version(sdkVersion.major, sdkVersion.minor, 0); final sdkConstraint = VersionConstraint.compatibleWith(sdkVersion); - final pubspecSdkConstraint = pubspec.environment['sdk']; - expect(sdkConstraint.allowsAll(pubspecSdkConstraint), true, + final pubspecSdkConstraint = pubspec.environment?['sdk']; + expect(pubspecSdkConstraint, isNotNull); + expect(sdkConstraint.allowsAll(pubspecSdkConstraint!), true, reason: 'Min sdk constraint is outdated. Please update SDK constraint in ' 'pubspec to allow latest stable and backwards compatible versions.' diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 18a8fa9e9..83e3ea22f 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_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 - @TestOn('vm') import 'dart:async'; import 'dart:convert'; @@ -22,18 +20,15 @@ import 'fixtures/logging.dart'; void main() async { group('expression compiler service with fake asset server', () { final logger = Logger('ExpressionCompilerServiceTest'); - ExpressionCompilerService service; - HttpServer server; - StreamController output; - Directory outputDir; + late ExpressionCompilerService service; + late HttpServer server; + late StreamController output; + late Directory outputDir; Future stop() async { - await service?.stop(); - await server?.close(); - await output?.close(); - service = null; - server = null; - output = null; + await service.stop(); + await server.close(); + await output.close(); } setUp(() async { @@ -126,7 +121,7 @@ void main() async { test('works with no errors', () async { expect(output.stream, neverEmits(contains('[SEVERE]'))); expect( - output.stream, + output!.stream, emitsThrough(contains( '[INFO] ExpressionCompilerService: Updating dependencies...'))); expect( diff --git a/dwds/test/extension_backend_test.dart b/dwds/test/extension_backend_test.dart index d4fc893ba..7d687255f 100644 --- a/dwds/test/extension_backend_test.dart +++ b/dwds/test/extension_backend_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 'dart:async'; import 'package:async/src/stream_queue.dart'; @@ -31,7 +29,7 @@ class MockSocketHandler implements SocketHandler { } void main() { - ExtensionBackend extensionBackend; + late ExtensionBackend extensionBackend; setUpAll(() async { extensionBackend = diff --git a/dwds/test/metadata/class_test.dart b/dwds/test/metadata/class_test.dart index 2e56ba0e8..2aa4daff7 100644 --- a/dwds/test/metadata/class_test.dart +++ b/dwds/test/metadata/class_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:dwds/src/debugging/metadata/class.dart'; import 'package:test/test.dart'; diff --git a/dwds/test/metadata_test.dart b/dwds/test/metadata_test.dart index d2b750674..39ce010f0 100644 --- a/dwds/test/metadata_test.dart +++ b/dwds/test/metadata_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:dwds/asset_reader.dart'; import 'package:dwds/src/debugging/metadata/module_metadata.dart'; import 'package:dwds/src/debugging/metadata/provider.dart'; diff --git a/dwds/test/objects_test.dart b/dwds/test/objects_test.dart index c0fdd7e23..821e60d5b 100644 --- a/dwds/test/objects_test.dart +++ b/dwds/test/objects_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 - @TestOn('vm') import 'package:dwds/src/utilities/objects.dart'; import 'package:test/test.dart'; @@ -18,16 +16,18 @@ void main() { // or from a RemoteObject. final property = Property({'name': 'prop', 'value': exampleMap}); expect(property.rawValue, exampleMap); - expect(property.value.objectId, '1234'); - expect(property.value.value, 'abcd'); + final value = property.value!; + expect(value.objectId, '1234'); + expect(value.value, 'abcd'); expect(property.name, 'prop'); }); test('from a RemoteObject', () { final remoteObject = RemoteObject({'objectId': '1234', 'value': 'abcd'}); final property = Property({'name': 'prop', 'value': remoteObject}); expect(property.rawValue, remoteObject); - expect(property.value.objectId, '1234'); - expect(property.value.value, 'abcd'); + final value = property.value!; + expect(value.objectId, '1234'); + expect(value.value, 'abcd'); expect(property.name, 'prop'); }); diff --git a/dwds/test/readers/frontend_server_asset_reader_test.dart b/dwds/test/readers/frontend_server_asset_reader_test.dart index ddd05c929..4ee4be2eb 100644 --- a/dwds/test/readers/frontend_server_asset_reader_test.dart +++ b/dwds/test/readers/frontend_server_asset_reader_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 'dart:async'; import 'dart:io'; @@ -16,10 +14,10 @@ import '../fixtures/utilities.dart'; final packagesDir = p.relative('../fixtures/_test', from: p.current); void main() { - FrontendServerAssetReader assetReader; - Directory tempFixtures; - File jsonOriginal; - File mapOriginal; + late FrontendServerAssetReader assetReader; + late Directory tempFixtures; + late File jsonOriginal; + late File mapOriginal; Future createTempFixtures() async { final fixtures = p.join('test', 'fixtures'); diff --git a/dwds/test/sdk_configuration_test.dart b/dwds/test/sdk_configuration_test.dart index 39d7e0a6a..550ad0080 100644 --- a/dwds/test/sdk_configuration_test.dart +++ b/dwds/test/sdk_configuration_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 - @TestOn('vm') import 'dart:io'; @@ -34,7 +32,7 @@ void main() { }); group('Non-standard configuration', () { - Directory outputDir; + late Directory outputDir; setUp(() async { final systemTempDir = Directory.systemTemp; @@ -54,7 +52,7 @@ void main() { final librariesPath = p.join(librariesDir, 'libraries.json'); Directory(librariesDir).createSync(recursive: true); - File(defaultSdkConfiguration.librariesPath).copySync(librariesPath); + File(defaultSdkConfiguration.librariesPath!).copySync(librariesPath); final summariesDir = p.join(sdkDirectory, 'summaries'); final unsoundSdkSummaryPath = p.join(summariesDir, 'ddc_sdk.dill'); @@ -62,16 +60,16 @@ void main() { p.join(summariesDir, 'ddc_outline_sound.dill'); Directory(summariesDir).createSync(recursive: true); - File(defaultSdkConfiguration.unsoundSdkSummaryPath) + File(defaultSdkConfiguration.unsoundSdkSummaryPath!) .copySync(unsoundSdkSummaryPath); - File(defaultSdkConfiguration.soundSdkSummaryPath) + File(defaultSdkConfiguration.soundSdkSummaryPath!) .copySync(soundSdkSummaryPath); final workerDir = p.join(sdkDirectory, 'snapshots'); final compilerWorkerPath = p.join(workerDir, 'dartdevc.dart.snapshot'); Directory(workerDir).createSync(recursive: true); - File(defaultSdkConfiguration.compilerWorkerPath) + File(defaultSdkConfiguration.compilerWorkerPath!) .copySync(compilerWorkerPath); final sdkConfiguration = SdkConfiguration( @@ -118,7 +116,7 @@ void main() { }); group('SDK configuration', () { - MemoryFileSystem fs; + late MemoryFileSystem fs; final root = '/root'; final sdkDirectory = root; diff --git a/dwds/test/skip_list_test.dart b/dwds/test/skip_list_test.dart index 4d23f08c0..6f95707c8 100644 --- a/dwds/test/skip_list_test.dart +++ b/dwds/test/skip_list_test.dart @@ -2,15 +2,13 @@ // 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:dwds/src/debugging/location.dart'; import 'package:dwds/src/debugging/skip_list.dart'; import 'package:source_maps/parser.dart'; import 'package:test/test.dart'; void main() { - SkipLists skipLists; + late SkipLists skipLists; group('SkipLists', () { setUp(() { skipLists = SkipLists(); diff --git a/dwds/test/web/batched_stream_test.dart b/dwds/test/web/batched_stream_test.dart index 1ab818a72..694018db4 100644 --- a/dwds/test/web/batched_stream_test.dart +++ b/dwds/test/web/batched_stream_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 - @Retry(0) import 'dart:async'; From 9fa541a39a827017a7fd31d7f6afb2defc29c625 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:15:03 -0700 Subject: [PATCH 2/6] Fix null-safety errors --- dwds/test/expression_compiler_service_test.dart | 2 +- dwds/test/sdk_configuration_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 83e3ea22f..5b294c761 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -121,7 +121,7 @@ void main() async { test('works with no errors', () async { expect(output.stream, neverEmits(contains('[SEVERE]'))); expect( - output!.stream, + output.stream, emitsThrough(contains( '[INFO] ExpressionCompilerService: Updating dependencies...'))); expect( diff --git a/dwds/test/sdk_configuration_test.dart b/dwds/test/sdk_configuration_test.dart index 550ad0080..79c7ff734 100644 --- a/dwds/test/sdk_configuration_test.dart +++ b/dwds/test/sdk_configuration_test.dart @@ -40,7 +40,7 @@ void main() { }); tearDown(() async { - await outputDir?.delete(recursive: true); + await outputDir.delete(recursive: true); }); test('Can validate existing configuration layout', () async { From 8f0c7a76bfe494441ee28591e8db60357cb0188d Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:17:11 -0700 Subject: [PATCH 3/6] Revert split list test --- dwds/test/skip_list_test.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dwds/test/skip_list_test.dart b/dwds/test/skip_list_test.dart index 6f95707c8..4d23f08c0 100644 --- a/dwds/test/skip_list_test.dart +++ b/dwds/test/skip_list_test.dart @@ -2,13 +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 + import 'package:dwds/src/debugging/location.dart'; import 'package:dwds/src/debugging/skip_list.dart'; import 'package:source_maps/parser.dart'; import 'package:test/test.dart'; void main() { - late SkipLists skipLists; + SkipLists skipLists; group('SkipLists', () { setUp(() { skipLists = SkipLists(); From df192a754d0199ad972ea91b471b613f0a0f775e Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:14:11 -0700 Subject: [PATCH 4/6] wip --- .../expression_compiler_service_test.dart | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 5b294c761..61bd31c85 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -18,17 +18,27 @@ import 'package:test/test.dart'; import 'fixtures/logging.dart'; void main() async { + + T ensureVarNonNull({required T? varValue, required String varName}) { + if (varValue == null) { + throw TestFailure('Expected $varName to be defined, but it is null'); + } + return varValue; + } group('expression compiler service with fake asset server', () { final logger = Logger('ExpressionCompilerServiceTest'); - late ExpressionCompilerService service; - late HttpServer server; - late StreamController output; + late ExpressionCompilerService? service; + late HttpServer? server; + late StreamController? output; late Directory outputDir; Future stop() async { - await service.stop(); - await server.close(); - await output.close(); + await service?.stop(); + await server?.close(); + await output?.close(); + service = null; + server = null; + output = null; } setUp(() async { @@ -43,20 +53,24 @@ void main() async { // redirect logs for testing output = StreamController.broadcast(); + output = ensureVarNonNull(varValue: output, varName: 'output'); + + output.stream.listen(printOnFailure); configureLogWriter( customLogWriter: (level, message, {error, loggerName, stackTrace}) => - output.add('[$level] $loggerName: $message')); + output?.add('[$level] $loggerName: $message')); // start asset server server = await startHttpServer('localhost'); - final port = server.port; + final port = server?.port; // start expression compilation service Response assetHandler(request) => Response(200, body: File.fromUri(kernel).readAsBytesSync()); - service = ExpressionCompilerService('localhost', port, verbose: false); + service = + ExpressionCompilerService('localhost', port ?? 8000, verbose: false); await service.initialize(moduleFormat: 'amd'); From 290fc55c978b3b7ec5b55a886511c1173a3ae9fa Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 19 Jul 2022 14:50:49 -0700 Subject: [PATCH 5/6] Revert expression compiler test --- .../expression_compiler_service_test.dart | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 61bd31c85..9701fe15b 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_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 + @TestOn('vm') import 'dart:async'; import 'dart:convert'; @@ -18,19 +20,12 @@ import 'package:test/test.dart'; import 'fixtures/logging.dart'; void main() async { - - T ensureVarNonNull({required T? varValue, required String varName}) { - if (varValue == null) { - throw TestFailure('Expected $varName to be defined, but it is null'); - } - return varValue; - } group('expression compiler service with fake asset server', () { final logger = Logger('ExpressionCompilerServiceTest'); - late ExpressionCompilerService? service; - late HttpServer? server; - late StreamController? output; - late Directory outputDir; + ExpressionCompilerService service; + HttpServer server; + StreamController output; + Directory outputDir; Future stop() async { await service?.stop(); @@ -53,24 +48,20 @@ void main() async { // redirect logs for testing output = StreamController.broadcast(); - output = ensureVarNonNull(varValue: output, varName: 'output'); - - output.stream.listen(printOnFailure); configureLogWriter( customLogWriter: (level, message, {error, loggerName, stackTrace}) => - output?.add('[$level] $loggerName: $message')); + output.add('[$level] $loggerName: $message')); // start asset server server = await startHttpServer('localhost'); - final port = server?.port; + final port = server.port; // start expression compilation service Response assetHandler(request) => Response(200, body: File.fromUri(kernel).readAsBytesSync()); - service = - ExpressionCompilerService('localhost', port ?? 8000, verbose: false); + service = ExpressionCompilerService('localhost', port, verbose: false); await service.initialize(moduleFormat: 'amd'); @@ -175,4 +166,4 @@ Stream transformToLines(Stream> byteStream) { return byteStream .transform(utf8.decoder) .transform(const LineSplitter()); -} +} \ No newline at end of file From 797cc1b04caf79b7893caffe96decc01e4064716 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 19 Jul 2022 14:55:58 -0700 Subject: [PATCH 6/6] format --- dwds/test/expression_compiler_service_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 9701fe15b..18a8fa9e9 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -166,4 +166,4 @@ Stream transformToLines(Stream> byteStream) { return byteStream .transform(utf8.decoder) .transform(const LineSplitter()); -} \ No newline at end of file +}