From 585923ebf1547c562b59980f923acc7a5ecbb2e2 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Wed, 8 Nov 2017 13:35:45 -0800 Subject: [PATCH] Fix warnings related to fuzzy arrows. These will become an arrow in Dart 2.0. See this bug for more context: https://github.com/dart-lang/sdk/issues/29630 I also fixed a couple of unused variable warnings while I was at it. I bumped the version number in the pubspec. This is technically a potentially breaking change because the signatures of createHitmap() and mergeHitmaps() are more precise now. The only code I could find calling that was in flutter_tools and that seems to be happy with the change. If you'd rather I keep the old version, let me know. --- lib/src/collect.dart | 8 +++++--- lib/src/hitmap.dart | 9 +++++---- lib/src/resolver.dart | 2 +- pubspec.yaml | 2 +- test/collect_coverage_api_test.dart | 3 ++- test/lcov_test.dart | 3 --- test/test_files/test_app_isolate.dart | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/src/collect.dart b/lib/src/collect.dart index 29aa9be9..13134db3 100644 --- a/lib/src/collect.dart +++ b/lib/src/collect.dart @@ -80,9 +80,11 @@ Future _waitIsolatesPaused(VMServiceClient service, {Duration timeout}) async { Future>> _getCoverageJson( VMServiceClient service, VMSourceReport report) async { var scriptRefs = report.ranges.map((r) => r.script).toSet(); - var scripts = new Map.fromIterable( - await Future.wait(scriptRefs.map((ref) => ref.load()).toList()), - key: (VMScript s) => s.uri); + var scripts = {}; + for (var script in await Future + .wait(scriptRefs.map((ref) => ref.load()).toList())) { + scripts[script.uri] = script; + } // script uri -> { line -> hit count } var hitMaps = >{}; diff --git a/lib/src/hitmap.dart b/lib/src/hitmap.dart index 732d340c..6e4f072d 100644 --- a/lib/src/hitmap.dart +++ b/lib/src/hitmap.dart @@ -8,7 +8,7 @@ import 'dart:io'; /// Creates a single hitmap from a raw json object. Throws away all entries that /// are not resolvable. -Map createHitmap(List json) { +Map> createHitmap(List json) { // Map of source file to map of line to hit count for that line. var globalHitMap = >{}; @@ -51,8 +51,9 @@ Map createHitmap(List json) { } /// Merges [newMap] into [result]. -void mergeHitmaps(Map newMap, Map result) { - newMap.forEach((String file, Map v) { +void mergeHitmaps( + Map> newMap, Map> result) { + newMap.forEach((String file, Map v) { if (result.containsKey(file)) { v.forEach((int line, int cnt) { if (result[file][line] == null) { @@ -69,7 +70,7 @@ void mergeHitmaps(Map newMap, Map result) { /// Generates a merged hitmap from a set of coverage JSON files. Future parseCoverage(Iterable files, int _) async { - Map globalHitmap = >{}; + var globalHitmap = >{}; for (var file in files) { String contents = file.readAsStringSync(); List> json = JSON.decode(contents)['coverage']; diff --git a/lib/src/resolver.dart b/lib/src/resolver.dart index e2e6d435..4ff6175c 100644 --- a/lib/src/resolver.dart +++ b/lib/src/resolver.dart @@ -157,7 +157,7 @@ class Loader { final List failed = []; /// Loads an imported resource and returns a [Future] with a [List] of lines. - /// Returns [null] if the resource could not be loaded. + /// Returns `null` if the resource could not be loaded. Future> load(String path) async { try { return new File(path).readAsLines(); diff --git a/pubspec.yaml b/pubspec.yaml index 3d5d9d5d..57e8e3f6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: coverage -version: 0.9.4-dev +version: 0.10.0-dev author: Dart Team description: Coverage data manipulation and formatting homepage: https://github.com/dart-lang/coverage diff --git a/test/collect_coverage_api_test.dart b/test/collect_coverage_api_test.dart index 3c8a5e5d..fb353981 100644 --- a/test/collect_coverage_api_test.dart +++ b/test/collect_coverage_api_test.dart @@ -26,7 +26,8 @@ void main() { List coverage = json['coverage']; expect(coverage, isNotEmpty); - var sources = coverage.fold({}, (Map map, Map value) { + var sources = coverage.fold({}, + (Map map, dynamic value) { String sourceUri = value['source']; map.putIfAbsent(sourceUri, () => []).add(value); return map; diff --git a/test/lcov_test.dart b/test/lcov_test.dart index 051f4c7c..6a56db89 100644 --- a/test/lcov_test.dart +++ b/test/lcov_test.dart @@ -13,13 +13,10 @@ import 'package:test/test.dart'; final _sampleAppPath = p.join('test', 'test_files', 'test_app.dart'); final _isolateLibPath = p.join('test', 'test_files', 'test_app_isolate.dart'); -final _collectAppPath = p.join('bin', 'collect_coverage.dart'); final _sampleAppFileUri = p.toUri(p.absolute(_sampleAppPath)).toString(); final _isolateLibFileUri = p.toUri(p.absolute(_isolateLibPath)).toString(); -const _timeout = const Duration(seconds: 5); - void main() { test('validate hitMap', () async { var hitmap = await _getHitMap(); diff --git a/test/test_files/test_app_isolate.dart b/test/test_files/test_app_isolate.dart index bcdbc63a..8342be77 100644 --- a/test/test_files/test_app_isolate.dart +++ b/test/test_files/test_app_isolate.dart @@ -23,7 +23,7 @@ Future fooAsync(int x) async { /// The number of covered lines is tested and expected to be 4. /// /// If you modify this method, you may have to update the tests! -void isolateTask(List threeThings) { +void isolateTask(dynamic threeThings) { sleep(const Duration(milliseconds: 500)); fooSync(42);