diff --git a/lib/runtime.dart b/lib/runtime.dart index 5035666..b407c10 100644 --- a/lib/runtime.dart +++ b/lib/runtime.dart @@ -2,7 +2,7 @@ library runtime; import 'dart:io'; -import 'package:runtime/src/compiler.dart'; +import 'src/compiler.dart'; import 'package:runtime/src/mirror_context.dart'; export 'src/analyzer.dart'; @@ -29,8 +29,8 @@ class RuntimePackageCompiler extends Compiler { void deflectPackage(Directory destinationDirectory) { final libraryFile = File.fromUri( destinationDirectory.uri.resolve("lib/").resolve("runtime.dart")); - libraryFile - .writeAsStringSync("library runtime;\nexport 'src/context.dart';\nexport 'src/exceptions.dart';"); + libraryFile.writeAsStringSync( + "library runtime;\nexport 'src/context.dart';\nexport 'src/exceptions.dart';"); final contextFile = File.fromUri(destinationDirectory.uri .resolve("lib/") @@ -41,9 +41,11 @@ class RuntimePackageCompiler extends Compiler { "import 'package:generated_runtime/generated_runtime.dart' as context;"); contextFile.writeAsStringSync(contextFileContents); - final pubspecFile = File.fromUri(destinationDirectory.uri.resolve("pubspec.yaml")); - final pubspecContents = pubspecFile.readAsStringSync().replaceFirst("\ndependencies:", - "\ndependencies:\n generated_runtime:\n path: ../../generated_runtime/"); + final pubspecFile = + File.fromUri(destinationDirectory.uri.resolve("pubspec.yaml")); + final pubspecContents = pubspecFile.readAsStringSync().replaceFirst( + "\ndependencies:", + "\ndependencies:\n generated_runtime:\n path: ../../generated_runtime/"); pubspecFile.writeAsStringSync(pubspecContents); } } diff --git a/lib/slow_coerce.dart b/lib/slow_coerce.dart index e7ce986..797e0de 100644 --- a/lib/slow_coerce.dart +++ b/lib/slow_coerce.dart @@ -4,38 +4,50 @@ const String _listPrefix = "List<"; const String _mapPrefix = "Map(dynamic input) { - if (input == null) { - return null; - } - try { - final typeString = T.toString(); + var typeString = T.toString(); + if (typeString.endsWith('?')) { + if (input == null) { + return null as T; + } else { + typeString = typeString.substring(0, typeString.length - 1); + } + } if (typeString.startsWith(_listPrefix)) { if (input is! List) { throw TypeError(); } - if (typeString == "List") { + if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List") { + } else if (typeString.startsWith("List")) { return List.from(input) as T; - } else if (typeString == "List>") { + } else if (typeString.startsWith("List")) { + return List.from(input) as T; + } else if (typeString.startsWith("List")) { + return List.from(input) as T; + } else if (typeString.startsWith("List")) { + return List.from(input) as T; + } else if (typeString.startsWith("List")) { + return List.from(input) as T; + } else if (typeString.startsWith("List")) { + return List.from(input) as T; + } else if (typeString.startsWith("List>")) { final objects = >[]; - (input as List).forEach((o) { - if (o == null) { - objects.add(null); - } else { - if (o is! Map) { - throw TypeError(); - } - objects.add(o); - } + input.forEach((o) { + objects.add(o); + }); + return objects as T; + } else if (typeString.startsWith("List?>")) { + final objects = ?>[]; + input.forEach((o) { + objects.add(o); }); return objects as T; } @@ -45,23 +57,31 @@ T cast(dynamic input) { } final inputMap = input as Map; - if (typeString == "Map") { + if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; - } else if (typeString == "Map") { + } else if (typeString.startsWith("Map")) { return Map.from(inputMap) as T; + } else if (typeString.startsWith("Map")) { + return Map.from(inputMap) as T; + } else if (typeString.startsWith("Map")) { + return Map.from(inputMap) as T; + } else if (typeString.startsWith("Map")) { + return Map.from(inputMap) as T; + } else if (typeString.startsWith("Map")) { + return Map.from(inputMap) as T; + } else if (typeString.startsWith("Map")) { + return Map.from(inputMap) as T; } } return input as T; - } on CastError { - throw TypeCoercionException(T, input.runtimeType as Type); } on TypeError { - throw TypeCoercionException(T, input.runtimeType as Type); + throw TypeCoercionException(T, input.runtimeType); } } diff --git a/lib/src/analyzer.dart b/lib/src/analyzer.dart index 87be105..89c995f 100644 --- a/lib/src/analyzer.dart +++ b/lib/src/analyzer.dart @@ -20,13 +20,13 @@ class CodeAnalyzer { return getPath(uri); } - final Uri uri; + late final Uri uri; - AnalysisContextCollection contexts; + late AnalysisContextCollection contexts; Map _resolvedAsts = {}; - Future resolveUnitAt(Uri uri) async { + Future resolveUnitAt(Uri uri) async { for (var ctx in contexts.contexts) { final path = getPath(uri); if (_resolvedAsts.containsKey(path)) { @@ -44,11 +44,11 @@ class CodeAnalyzer { "${contexts.contexts.map((c) => c.contextRoot.root.toUri()).join(", ")})"); } - ClassDeclaration getClassFromFile(String className, Uri fileUri) { + ClassDeclaration? getClassFromFile(String className, Uri fileUri) { return _getFileAstRoot(fileUri) .declarations - .whereType() - .firstWhere((c) => c.name.name == className, orElse: () => null); + .whereType() + .firstWhere((c) => c!.name.name == className, orElse: () => null); } List getSubclassesFromFile( @@ -56,14 +56,14 @@ class CodeAnalyzer { return _getFileAstRoot(fileUri) .declarations .whereType() - .where((c) => c.extendsClause.superclass.name.name == superclassName) + .where((c) => c.extendsClause!.superclass.name.name == superclassName) .toList(); } CompilationUnit _getFileAstRoot(Uri fileUri) { final path = getPath(fileUri); if (_resolvedAsts.containsKey(path)) { - return _resolvedAsts[path].unit; + return _resolvedAsts[path]!.unit!; } final unit = contexts.contextFor(path).currentSession.getParsedUnit(path); diff --git a/lib/src/build.dart b/lib/src/build.dart index 2d0b5e4..ebdb2d7 100644 --- a/lib/src/build.dart +++ b/lib/src/build.dart @@ -2,8 +2,10 @@ import 'dart:convert'; import 'dart:io'; import 'dart:mirrors'; -import 'package:runtime/runtime.dart'; import 'package:runtime/src/build_context.dart'; +import 'package:runtime/src/compiler.dart'; +import 'package:runtime/src/file_system.dart'; +import 'package:runtime/src/generator.dart'; class Build { Build(this.context); @@ -11,21 +13,22 @@ class Build { final BuildContext context; Map get packageMap => _packageMap ??= context.resolvedPackages; - Map _packageMap; + Map? _packageMap; Future execute() async { final compilers = context.context.compilers; print("Resolving ASTs..."); - final astsToResolve = Set.from(compilers.expand((c) => c.getUrisToResolve(context))); + final astsToResolve = + Set.from(compilers.expand((c) => c.getUrisToResolve(context))); await Future.forEach(astsToResolve, (astUri) async { - await context.analyzer.resolveUnitAt(context.resolveUri(astUri)); + await context.analyzer.resolveUnitAt(context.resolveUri(astUri as Uri)!); }); print("Generating runtime..."); final runtimeGenerator = RuntimeGenerator(); - context.context.runtimes.map.forEach((typeName, runtime) { + context.context.runtimes?.map.forEach((typeName, runtime) { if (runtime is SourceCompiler) { runtimeGenerator.addRuntime( name: typeName, source: runtime.compile(context)); @@ -39,10 +42,10 @@ class Build { final pubspecMap = { 'name': 'runtime_target', 'version': '1.0.0', - 'environment': {'sdk': '>=2.7.0 <3.0.0'}, + 'environment': {'sdk': '>=2.12.0-0 <3.0.0'}, 'dependency_overrides': {} }; - Map overrides = pubspecMap['dependency_overrides']; + Map? overrides = pubspecMap['dependency_overrides'] as Map?; var sourcePackageIsCompiled = false; compilers.forEach((compiler) { @@ -56,7 +59,7 @@ class Build { compiler.deflectPackage(Directory.fromUri(targetDirUri)); if (packageInfo.name != nameOfPackageBeingCompiled) { - overrides[packageInfo.name] = { + overrides![packageInfo.name] = { "path": targetDirUri.toFilePath(windows: Platform.isWindows) }; } else { @@ -158,7 +161,7 @@ class Build { } _PackageInfo _getPackageInfoForCompiler(Compiler compiler) { - final compilerUri = reflect(compiler).type.location.sourceUri; + final compilerUri = reflect(compiler).type.location!.sourceUri; final parser = RegExp("package\:([^\/]+)"); final parsed = parser.firstMatch(compilerUri.toString()); if (parsed == null) { @@ -167,7 +170,7 @@ class Build { } final packageName = parsed.group(1); - return _getPackageInfoForName(packageName); + return _getPackageInfoForName(packageName!); } } diff --git a/lib/src/build_context.dart b/lib/src/build_context.dart index 5953697..932b19c 100644 --- a/lib/src/build_context.dart +++ b/lib/src/build_context.dart @@ -2,18 +2,19 @@ import 'dart:io'; import 'dart:mirrors'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:pubspec_parse/pubspec_parse.dart'; +import 'package:pubspec/pubspec.dart'; import 'package:runtime/src/analyzer.dart'; import 'package:runtime/src/context.dart'; import 'package:runtime/src/file_system.dart'; import 'package:runtime/src/mirror_context.dart'; import 'package:yaml/yaml.dart'; +import 'package:path/path.dart'; /// Configuration and context values used during [Build.execute]. class BuildContext { BuildContext(this.rootLibraryFileUri, this.buildDirectoryUri, this.executableUri, this.source, - {bool forTests}) + {bool? forTests}) : this.forTests = forTests ?? false { analyzer = CodeAnalyzer(sourceApplicationDirectory.uri); } @@ -35,7 +36,7 @@ class BuildContext { 'forTests': forTests }; - CodeAnalyzer analyzer; + late CodeAnalyzer analyzer; /// A [Uri] to the library file of the application to be compiled. final Uri rootLibraryFileUri; @@ -61,7 +62,7 @@ class BuildContext { .resolve("main_test.dart") : buildDirectoryUri.resolve("main.dart"); - Pubspec get sourceApplicationPubspec => Pubspec.parse( + PubSpec get sourceApplicationPubspec => PubSpec.fromYamlString( File.fromUri(sourceApplicationDirectory.uri.resolve("pubspec.yaml")) .readAsStringSync()); @@ -117,16 +118,16 @@ class BuildContext { return file; } - Uri resolveUri(Uri uri) { + Uri? resolveUri(Uri? uri) { var outputUri = uri; if (outputUri?.scheme == "package") { - final segments = outputUri.pathSegments; - outputUri = resolvedPackages[segments.first].resolve("lib/"); + final segments = outputUri!.pathSegments; + outputUri = resolvedPackages[segments.first]!.resolve("lib/"); for (var i = 1; i < segments.length; i++) { if (i < segments.length - 1) { - outputUri = outputUri.resolve("${segments[i]}/"); + outputUri = outputUri!.resolve("${segments[i]}/"); } else { - outputUri = outputUri.resolve(segments[i]); + outputUri = outputUri!.resolve(segments[i]); } } } else if (outputUri != null && !outputUri.isAbsolute) { @@ -137,7 +138,7 @@ class BuildContext { } List getImportDirectives( - {Uri uri, String source, bool alsoImportOriginalFile = false}) { + {Uri? uri, String? source, bool alsoImportOriginalFile = false}) { if (uri != null && source != null) { throw ArgumentError( "either uri or source must be non-null, but not both"); @@ -154,15 +155,15 @@ class BuildContext { } var fileUri = resolveUri(uri); - final text = source ?? File.fromUri(fileUri).readAsStringSync(); + final text = source ?? File.fromUri(fileUri!).readAsStringSync(); final importRegex = RegExp("import [\\'\\\"]([^\\'\\\"]*)[\\'\\\"];"); final imports = importRegex.allMatches(text).map((m) { - var importedUri = Uri.parse(m.group(1)); - if (importedUri.scheme != "package" && !importedUri.isAbsolute) { - throw ArgumentError( - "Cannot resolve relative URIs in file located at $uri. " - "Replace imported URIs with package or absolute URIs"); + var importedUri = Uri.parse(m.group(1)!); + + if (!importedUri.isAbsolute) { + final path = fileUri!.resolve(importedUri.path); + return 'import \'file:${absolute(path.path)}\';'; } return text.substring(m.start, m.end); @@ -175,26 +176,26 @@ class BuildContext { return imports; } - ClassDeclaration getClassDeclarationFromType(Type type) { + ClassDeclaration? getClassDeclarationFromType(Type type) { final classMirror = reflectType(type); return analyzer.getClassFromFile( MirrorSystem.getName(classMirror.simpleName), - resolveUri(classMirror.location.sourceUri)); + resolveUri(classMirror.location!.sourceUri)!); } List getAnnotationsFromField(Type _type, String propertyName) { var type = reflectClass(_type); var field = - getClassDeclarationFromType(type.reflectedType).getField(propertyName); + getClassDeclarationFromType(type.reflectedType)!.getField(propertyName); while (field == null) { - type = type.superclass; + type = type.superclass!; if (type.reflectedType == Object) { break; } - field = getClassDeclarationFromType(type.reflectedType) + field = getClassDeclarationFromType(type.reflectedType)! .getField(propertyName); } - return (field.parent.parent as FieldDeclaration).metadata.toList(); + return (field!.parent!.parent as FieldDeclaration).metadata.toList(); } } diff --git a/lib/src/build_manager.dart b/lib/src/build_manager.dart index 0d1a441..a75b1e9 100644 --- a/lib/src/build_manager.dart +++ b/lib/src/build_manager.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:isolate_executor/isolate_executor.dart'; +import 'package:conduit_isolate_exec/conduit_isolate_exec.dart'; import 'package:runtime/runtime.dart'; import 'build_context.dart'; @@ -11,7 +11,7 @@ class BuildExecutable extends Executable { context = BuildContext.fromMap(message); } - BuildContext context; + late BuildContext context; @override Future execute() async { @@ -36,10 +36,8 @@ class BuildManager { // Here is where we need to provide a temporary copy of the script file with the main function stripped; // this is because when the RuntimeGenerator loads, it needs Mirror access to any declarations in this file var scriptSource = context.source; - final strippedScriptFile = - File.fromUri(context.targetScriptFileUri) - ..writeAsStringSync(scriptSource); - + final strippedScriptFile = File.fromUri(context.targetScriptFileUri) + ..writeAsStringSync(scriptSource); final analyzer = CodeAnalyzer(strippedScriptFile.absolute.uri); final analyzerContext = analyzer.contexts.contextFor(analyzer.path); final mainFunctions = analyzerContext.currentSession diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart index 1dbf802..1525cd2 100644 --- a/lib/src/compiler.dart +++ b/lib/src/compiler.dart @@ -18,9 +18,7 @@ abstract class Compiler { /// Returns a map of runtime objects that can be used at runtime while running in mirrored mode. Map compile(MirrorContext context); - void didFinishPackageGeneration(BuildContext context) { - - } + void didFinishPackageGeneration(BuildContext context) {} List getUrisToResolve(BuildContext context) => []; } @@ -29,4 +27,4 @@ abstract class Compiler { abstract class SourceCompiler { /// The source code, including directives, that declare a class that is equivalent in behavior to this runtime. String compile(BuildContext ctx); -} \ No newline at end of file +} diff --git a/lib/src/context.dart b/lib/src/context.dart index 1f18609..9a338e3 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -14,10 +14,10 @@ abstract class RuntimeContext { _current = runtime; } - static RuntimeContext _current; + static RuntimeContext? _current; /// The runtimes available to the executing application. - RuntimeCollection runtimes; + RuntimeCollection? runtimes; /// Gets a runtime object for [type]. /// @@ -30,7 +30,7 @@ abstract class RuntimeContext { /// In other words, if the type `Base` has a runtime and the type `Subclass` extends `Base`, /// `Subclass` must also have a runtime. The runtime objects for both `Subclass` and `Base` /// must be the same type. - dynamic operator [](Type type) => runtimes[type]; + dynamic operator [](Type type) => runtimes?[type]; T coerce(dynamic input); } diff --git a/lib/src/file_system.dart b/lib/src/file_system.dart index 275089f..54d247d 100644 --- a/lib/src/file_system.dart +++ b/lib/src/file_system.dart @@ -1,11 +1,9 @@ import 'dart:io'; -import 'package:meta/meta.dart'; - /// Recursively copies the contents of the directory at [src] to [dst]. /// /// Creates directory at [dst] recursively if it doesn't exist. -void copyDirectory({@required Uri src, @required Uri dst}) { +void copyDirectory({required Uri src, required Uri dst}) { final srcDir = Directory.fromUri(src); final dstDir = Directory.fromUri(dst); if (!dstDir.existsSync()) { @@ -30,7 +28,8 @@ void copyDirectory({@required Uri src, @required Uri dst}) { /// /// If locations on disk are relative Uris, they are resolved by [relativeTo]. [relativeTo] defaults /// to the CWD. -Map getResolvedPackageUris(Uri packagesFileUri, {Uri relativeTo}) { +Map getResolvedPackageUris(Uri packagesFileUri, + {Uri? relativeTo}) { relativeTo ??= Directory.current.uri; final packagesFile = File.fromUri(packagesFileUri); @@ -53,7 +52,7 @@ Map getResolvedPackageUris(Uri packagesFileUri, {Uri relativeTo}) { return MapEntry( packageName, - Directory.fromUri(relativeTo.resolveUri(uri).normalizePath()) + Directory.fromUri(relativeTo!.resolveUri(uri).normalizePath()) .parent .uri); })); diff --git a/lib/src/generator.dart b/lib/src/generator.dart index a246953..0435db6 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -1,15 +1,13 @@ import 'dart:async'; import 'dart:io'; -import 'package:meta/meta.dart'; - const String _directiveToken = "___DIRECTIVES___"; const String _assignmentToken = "___ASSIGNMENTS___"; class RuntimeGenerator { List<_RuntimeElement> _elements = []; - void addRuntime({@required String name, @required String source}) { + void addRuntime({required String name, required String source}) { _elements.add(_RuntimeElement(name, source)); } @@ -24,7 +22,8 @@ class RuntimeGenerator { srcDir.createSync(recursive: true); } - final libraryFile = File.fromUri(libDir.uri.resolve("generated_runtime.dart")); + final libraryFile = + File.fromUri(libDir.uri.resolve("generated_runtime.dart")); await libraryFile.writeAsString(loaderSource); final pubspecFile = File.fromUri(dir.uri.resolve("pubspec.yaml")); @@ -46,7 +45,7 @@ description: A runtime generated by package:runtime version: 1.0.0 environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' """; String get _loaderShell => """ @@ -67,15 +66,15 @@ class GeneratedContext extends RuntimeContext { @override T coerce(dynamic input) { - return runtime_cast.cast(input); + return runtime_cast.cast(input); } } """; String get loaderSource { return _loaderShell - .replaceFirst(_directiveToken, _directives) - .replaceFirst(_assignmentToken, _assignments); + .replaceFirst(_directiveToken, _directives) + .replaceFirst(_assignmentToken, _assignments); } String get _directives { diff --git a/lib/src/mirror_coerce.dart b/lib/src/mirror_coerce.dart index 74e4e8e..9f86302 100644 --- a/lib/src/mirror_coerce.dart +++ b/lib/src/mirror_coerce.dart @@ -4,7 +4,7 @@ import 'package:runtime/src/exceptions.dart'; dynamic runtimeCast(dynamic object, TypeMirror intoType) { final exceptionToThrow = - TypeCoercionException(intoType.reflectedType, object.runtimeType as Type); + TypeCoercionException(intoType.reflectedType, object.runtimeType); try { final objectType = reflect(object).type; @@ -18,7 +18,7 @@ dynamic runtimeCast(dynamic object, TypeMirror intoType) { } final elementType = intoType.typeArguments.first; - final elements = (object as List).map((e) => runtimeCast(e, elementType)); + final elements = object.map((e) => runtimeCast(e, elementType)); return (intoType as ClassMirror).newInstance(#from, [elements]).reflectee; } else if (intoType.isSubtypeOf(reflectType(Map, [String, dynamic]))) { if (object is! Map) { @@ -28,15 +28,13 @@ dynamic runtimeCast(dynamic object, TypeMirror intoType) { final output = (intoType as ClassMirror) .newInstance(const Symbol(""), []).reflectee as Map; final valueType = intoType.typeArguments.last; - (object as Map).forEach((key, val) { + object.forEach((key, val) { output[key] = runtimeCast(val, valueType); }); return output; } } on TypeError { throw exceptionToThrow; - } on CastError { - throw exceptionToThrow; } on TypeCoercionException { throw exceptionToThrow; } diff --git a/lib/src/mirror_context.dart b/lib/src/mirror_context.dart index 4cd8a9b..0fa6ada 100644 --- a/lib/src/mirror_context.dart +++ b/lib/src/mirror_context.dart @@ -65,9 +65,13 @@ class MirrorContext extends RuntimeContext { } } -T firstMetadataOfType(DeclarationMirror dm, {TypeMirror dynamicType}) { +T? firstMetadataOfType(DeclarationMirror dm, {TypeMirror? dynamicType}) { final tMirror = dynamicType ?? reflectType(T); - return dm.metadata - .firstWhere((im) => im.type.isSubtypeOf(tMirror), orElse: () => null) - ?.reflectee as T; + try { + return dm.metadata + .firstWhere((im) => im.type.isSubtypeOf(tMirror)) + .reflectee; + } on StateError { + return null; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 4449af4..735ac69 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,17 +5,17 @@ author: Joe Conway homepage: https://stablekernel.com environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: - analyzer: '>=0.32.0 <0.50.0' - args: ^1.5.0 - pubspec_parse: '>=0.1.4 <1.0.0' - isolate_executor: ^2.0.0 - meta: ^1.1.5 - yaml: ^2.1.15 + analyzer: ^1.2.0 + args: ^2.0.0 + pubspec: ^2.0.1 + conduit_isolate_exec: ^1.0.0-b1 + yaml: ^3.1.0 dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 - command_line_agent: ^1.0.0-b1 \ No newline at end of file + pedantic: ^1.11.0 + test: ^1.16.5 + command_line_agent: + git: https://github.com/j4qfrost/dart-test-terminal \ No newline at end of file diff --git a/test/coerce_test.dart b/test/coerce_test.dart index 66c0fdf..be5dcaa 100644 --- a/test/coerce_test.dart +++ b/test/coerce_test.dart @@ -15,7 +15,8 @@ void main() { return cast(input); }; - final testInvocation = (String suiteName, T Function(dynamic input) coerce) { + final testInvocation = + (String suiteName, T? Function(dynamic input) coerce) { group("($suiteName) Primitive Types (success)", () { test("dynamic", () { final x = coerce(wash("foo")); @@ -26,22 +27,22 @@ void main() { final x = coerce(wash(2)); expect(x, 2); - expect(coerce(null), null); + expect(coerce(null), null); }); test("String", () { final x = coerce(wash("string")); expect(x, "string"); - expect(coerce(null), null); + expect(coerce(null), null); }); test("bool", () { final x = coerce(wash(true)); expect(x, true); - expect(coerce(null), null); + expect(coerce(null), null); }); test("num", () { final x = coerce(wash(3.2)); expect(x, 3.2); - expect(coerce(null), null); + expect(coerce(null), null); final y = coerce(wash(3)); expect(y, 3); @@ -49,7 +50,7 @@ void main() { test("double", () { final x = coerce(wash(3.2)); expect(x, 3.2); - expect(coerce(null), null); + expect(coerce(null), null); }); }); @@ -103,50 +104,50 @@ void main() { group("($suiteName) List Types (success)", () { test("null/empty", () { - List x = coerce>(null); + List? x = coerce?>(null); expect(x, null); - x = coerce>([]); + x = coerce>([])!; expect(x, []); }); test("int", () { - List x = coerce>(wash([2, 4])); + List x = coerce>(wash([2, 4]))!; expect(x, [2, 4]); }); test("String", () { - List x = coerce>(wash(["a", "b", "c"])); + List x = coerce>(wash(["a", "b", "c"]))!; expect(x, ["a", "b", "c"]); }); test("num", () { - List x = coerce>(wash([3.0, 2])); + List x = coerce>(wash([3.0, 2]))!; expect(x, [3.0, 2]); }); test("bool", () { - List x = coerce>(wash([false, true])); + List x = coerce>(wash([false, true]))!; expect(x, [false, true]); }); - test("list of map", () { - List> x = coerce>>(wash([ + List?> x = + coerce?>>(wash([ {"a": "b"}, null, {"a": 1} - ])); + ]))!; expect(x, [ {"a": "b"}, null, {"a": 1} ]); - expect(coerce>>(null), null); - expect(coerce>>([]), >[]); + expect(coerce>?>(null), null); + expect( + coerce>>([]), >[]); }); - }); group("($suiteName) List Types (cast error)", () { @@ -199,28 +200,30 @@ void main() { group("($suiteName) Map types (success)", () { test("null", () { - Map x = coerce>(null); + Map? x = coerce?>(null); expect(x, null); }); test("string->dynamic", () { Map x = - coerce>(wash({"a": 1, "b": "c"})); + coerce>(wash({"a": 1, "b": "c"}))!; expect(x, {"a": 1, "b": "c"}); }); test("string->int", () { - Map x = coerce>(wash({"a": 1, "b": 2})); + Map x = coerce>(wash({"a": 1, "b": 2}))!; expect(x, {"a": 1, "b": 2}); }); test("string->num", () { - Map x = coerce>(wash({"a": 1, "b": 2.0})); + Map x = + coerce>(wash({"a": 1, "b": 2.0}))!; expect(x, {"a": 1, "b": 2.0}); }); test("string->string", () { - Map x = coerce>(wash({"a": "1", "b": "2.0"})); + Map x = + coerce>(wash({"a": "1", "b": "2.0"}))!; expect(x, {"a": "1", "b": "2.0"}); }); }); diff --git a/test/context_test.dart b/test/context_test.dart index f94c2cf..29cf23d 100644 --- a/test/context_test.dart +++ b/test/context_test.dart @@ -10,7 +10,7 @@ void main() { .resolve("application/") .resolve("lib/") .toFilePath(); - BuildContext ctx; + late BuildContext ctx; setUpAll(() async { final cmd = Platform.isWindows ? "pub.bat" : "pub"; diff --git a/test/project_analyzer_test.dart b/test/project_analyzer_test.dart index 2af6512..0203d14 100644 --- a/test/project_analyzer_test.dart +++ b/test/project_analyzer_test.dart @@ -18,7 +18,7 @@ void main() { final klass = p.getClassFromFile("ConsumerSubclass", terminal.libraryDirectory.absolute.uri.resolve("application.dart")); expect(klass, isNotNull); - expect(klass.name.name, "ConsumerSubclass"); - expect(klass.extendsClause.superclass.name.name, "Consumer"); + expect(klass!.name.name, "ConsumerSubclass"); + expect(klass.extendsClause!.superclass.name.name, "Consumer"); }); } diff --git a/test/test_packages/application/pubspec.yaml b/test/test_packages/application/pubspec.yaml index 11a9bca..7cf361c 100644 --- a/test/test_packages/application/pubspec.yaml +++ b/test/test_packages/application/pubspec.yaml @@ -3,13 +3,13 @@ description: A starting point for Dart libraries or applications. version: 1.0.0 environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: - meta: ^1.0.0 + meta: ^1.3.0 dependency: path: ../dependency/ dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.16.5 diff --git a/test/test_packages/dependency/pubspec.yaml b/test/test_packages/dependency/pubspec.yaml index 0085740..cff8604 100644 --- a/test/test_packages/dependency/pubspec.yaml +++ b/test/test_packages/dependency/pubspec.yaml @@ -3,12 +3,12 @@ description: A starting point for Dart libraries or applications. version: 1.0.0 environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' dependencies: runtime: path: ../../.. dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.16.5