Pass packages argument to format_coverage (#336)

* Packages path

* changelog

* add test

* more test coverage
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 519f484..7fd762d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.0.2 - 2021-03-15
+
+* Fix an issue where the `--packages` argument wasn't passed to `format_coverage`. 
+
+
 ## 1.0.1 - 2021-02-25
 
 * Allow the chrome `sourceUriProvider` to return `null`.
diff --git a/bin/format_coverage.dart b/bin/format_coverage.dart
index ab643ed..2f32875 100644
--- a/bin/format_coverage.dart
+++ b/bin/format_coverage.dart
@@ -60,6 +60,7 @@
     files,
     env.workers,
     checkIgnoredLines: env.checkIgnore,
+    packagesPath: env.packagesPath,
   );
 
   // All workers are done. Process the data.
diff --git a/lib/src/hitmap.dart b/lib/src/hitmap.dart
index fa32a27..70dfe06 100644
--- a/lib/src/hitmap.dart
+++ b/lib/src/hitmap.dart
@@ -135,6 +135,7 @@
   Iterable<File> files,
   int _, {
   bool checkIgnoredLines = false,
+  String? packagesPath,
 }) async {
   final globalHitmap = <String, Map<int, int>>{};
   for (var file in files) {
@@ -146,6 +147,7 @@
         await createHitmap(
           jsonResult.cast<Map<String, dynamic>>(),
           checkIgnoredLines: checkIgnoredLines,
+          packagesPath: packagesPath,
         ),
         globalHitmap,
       );
diff --git a/pubspec.yaml b/pubspec.yaml
index a118e91..bddcf22 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: coverage
-version: 1.0.1
+version: 1.0.2
 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 49d4efb..6bb6ce1 100644
--- a/test/collect_coverage_api_test.dart
+++ b/test/collect_coverage_api_test.dart
@@ -74,8 +74,8 @@
 
     final testAppCoverage = _getScriptCoverage(coverage, 'test_app.dart')!;
     var hits = testAppCoverage['hits'] as List<int>;
-    _expectHitCount(hits, 44, 0);
-    _expectHitCount(hits, 48, 0);
+    _expectHitCount(hits, 46, 0);
+    _expectHitCount(hits, 50, 0);
 
     final isolateCoverage =
         _getScriptCoverage(coverage, 'test_app_isolate.dart')!;
diff --git a/test/collect_coverage_test.dart b/test/collect_coverage_test.dart
index 0407389..58ababd 100644
--- a/test/collect_coverage_test.dart
+++ b/test/collect_coverage_test.dart
@@ -55,26 +55,38 @@
     final coverage = jsonResult['coverage'] as List;
     final hitMap = await createHitmap(
       coverage.cast<Map<String, dynamic>>(),
-      checkIgnoredLines: true,
     );
     expect(hitMap, contains(_sampleAppFileUri));
 
     final isolateFile = hitMap[_isolateLibFileUri];
     final expectedHits = {
+      11: 1,
       12: 1,
       13: 1,
       15: 0,
+      28: 1,
+      29: 1,
+      31: 1,
+      32: 3,
+      38: 1,
+      41: 1,
+      42: 1,
+      43: 1,
+      46: 1,
+      47: 1,
+      49: 1,
+      50: 1,
+      51: 1,
+      53: 1,
+      54: 1,
+      55: 1,
+      18: 1,
       19: 1,
       20: 1,
       22: 0,
-      29: 1,
-      31: 1,
-      32: 2,
       33: 1,
       34: 3,
-      35: 1,
-      46: 1,
-      47: 1,
+      35: 1
     };
     if (Platform.version.startsWith('1.')) {
       // Dart VMs prior to 2.0.0-dev.5.0 contain a bug that emits coverage on the
@@ -109,6 +121,26 @@
       await tempDir.delete(recursive: true);
     }
   });
+
+  test('parseCoverage with packagesPath and checkIgnoredLines', () async {
+    final tempDir = await Directory.systemTemp.createTemp('coverage.test.');
+
+    try {
+      final outputFile = File(p.join(tempDir.path, 'coverage.json'));
+
+      final coverageResults = await _getCoverageResult();
+      await outputFile.writeAsString(coverageResults, flush: true);
+
+      final parsedResult = await parseCoverage([outputFile], 1,
+          packagesPath: '.packages', checkIgnoredLines: true);
+
+      // This file has ignore:coverage-file.
+      expect(parsedResult, isNot(contains(_sampleAppFileUri)));
+      expect(parsedResult, contains(_isolateLibFileUri));
+    } finally {
+      await tempDir.delete(recursive: true);
+    }
+  });
 }
 
 String? _coverageData;
diff --git a/test/lcov_test.dart b/test/lcov_test.dart
index 1399820..6d28aac 100644
--- a/test/lcov_test.dart
+++ b/test/lcov_test.dart
@@ -27,11 +27,11 @@
 
     final sampleAppHitMap = hitmap[_sampleAppFileUri];
 
-    expect(sampleAppHitMap, containsPair(44, greaterThanOrEqualTo(1)),
+    expect(sampleAppHitMap, containsPair(46, greaterThanOrEqualTo(1)),
         reason: 'be careful if you modify the test file');
-    expect(sampleAppHitMap, containsPair(48, 0),
+    expect(sampleAppHitMap, containsPair(50, 0),
         reason: 'be careful if you modify the test file');
-    expect(sampleAppHitMap, isNot(contains(30)),
+    expect(sampleAppHitMap, isNot(contains(32)),
         reason: 'be careful if you modify the test file');
   });
 
diff --git a/test/run_and_collect_test.dart b/test/run_and_collect_test.dart
index aa0fe2a..99b0e92 100644
--- a/test/run_and_collect_test.dart
+++ b/test/run_and_collect_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.
 
-import 'dart:io';
-
 import 'package:coverage/coverage.dart';
 import 'package:path/path.dart' as p;
 import 'package:test/test.dart';
@@ -40,42 +38,30 @@
       expect(sampleCoverageData['hits'], isNotEmpty);
     }
 
-    final hitMap = await createHitmap(
-      coverage,
-      checkIgnoredLines: true,
-    );
-    expect(hitMap, contains(_sampleAppFileUri));
+    final hitMap = await createHitmap(coverage, checkIgnoredLines: true);
+    expect(hitMap, isNot(contains(_sampleAppFileUri)));
 
     final actualHits = hitMap[_isolateLibFileUri];
     final expectedHits = {
+      11: 1,
       12: 1,
       13: 1,
       15: 0,
+      28: 1,
+      29: 1,
+      31: 1,
+      32: 3,
+      46: 1,
+      47: 1,
+      18: 1,
       19: 1,
       20: 1,
       22: 0,
-      29: 1,
-      31: 1,
-      32: 2,
       33: 1,
       34: 3,
-      35: 1,
-      46: 1,
-      47: 1,
+      35: 1
     };
-    // Dart VMs prior to 2.0.0-dev.5.0 contain a bug that emits coverage on the
-    // closing brace of async function blocks.
-    // See: https://github.com/dart-lang/coverage/issues/196
-    if (Platform.version.startsWith('1.')) {
-      expectedHits[23] = 0;
-    } else {
-      // Dart VMs version 2.0.0-dev.6.0 mark the opening brace of a function as
-      // coverable.
-      expectedHits[11] = 1;
-      expectedHits[18] = 1;
-      expectedHits[28] = 1;
-      expectedHits[32] = 3;
-    }
+
     expect(actualHits, expectedHits);
   });
 }
diff --git a/test/test_files/test_app.dart b/test/test_files/test_app.dart
index 79c5f2a..bf9256f 100644
--- a/test/test_files/test_app.dart
+++ b/test/test_files/test_app.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.
 
+// coverage:ignore-file
+
 import 'dart:async';
 import 'dart:developer';
 import 'dart:isolate';