-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
164 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
library coverage; | ||
|
||
export 'src/hitmap.dart'; | ||
export 'src/collect.dart'; | ||
export 'src/formatter.dart'; | ||
export 'src/hitmap.dart'; | ||
export 'src/resolver.dart'; | ||
export 'src/collect.dart'; | ||
export 'src/run_and_collect.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | ||
// 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. | ||
|
||
library coverage.run_and_collect; | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'collect.dart'; | ||
import 'util.dart'; | ||
|
||
Future<Map> runAndCollect(String scriptPath, | ||
{List<String> scriptArgs, String packageRoot, Duration timeout}) async { | ||
var openPort = await getOpenPort(); | ||
|
||
var dartArgs = ['--enable-vm-service=$openPort', '--pause_isolates_on_exit',]; | ||
|
||
if (packageRoot != null) { | ||
dartArgs.add('--package-root=$packageRoot'); | ||
} | ||
|
||
dartArgs.add(scriptPath); | ||
|
||
if (scriptArgs != null) { | ||
dartArgs.addAll(scriptArgs); | ||
} | ||
|
||
var process = await Process.start('dart', dartArgs); | ||
|
||
try { | ||
return collect('127.0.0.1', openPort, true, true, timeout: timeout); | ||
} finally { | ||
await process.stdout.drain(); | ||
await process.stderr.drain(); | ||
|
||
var code = await process.exitCode; | ||
|
||
if (code < 0) { | ||
throw "A critical exception happened in the process: exit code $code"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | ||
// 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. | ||
|
||
library coverage.test.run_and_collect_test; | ||
|
||
import 'package:coverage/coverage.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
|
||
import 'test_util.dart'; | ||
|
||
final _isolateLibPath = p.join('test', 'test_files', 'test_app_isolate.dart'); | ||
|
||
final _sampleAppFileUri = p.toUri(p.absolute(testAppPath)).toString(); | ||
final _isolateLibFileUri = p.toUri(p.absolute(_isolateLibPath)).toString(); | ||
|
||
void main() { | ||
test('runAndCollect', () async { | ||
// use runAndCollect and verify that the results match w/ running manually | ||
|
||
var json = await runAndCollect(testAppPath); | ||
|
||
expect(json.keys, unorderedEquals(['type', 'coverage'])); | ||
|
||
expect(json, containsPair('type', 'CodeCoverage')); | ||
|
||
var coverage = json['coverage'] as List; | ||
expect(coverage, isNotEmpty); | ||
|
||
var sources = coverage.fold(<String, dynamic>{}, (Map map, Map value) { | ||
var sourceUri = value['source']; | ||
|
||
map.putIfAbsent(sourceUri, () => <Map>[]).add(value); | ||
|
||
return map; | ||
}); | ||
|
||
for (var sampleCoverageData in sources[_sampleAppFileUri]) { | ||
expect(sampleCoverageData['hits'], isNotEmpty); | ||
} | ||
|
||
for (var sampleCoverageData in sources[_isolateLibFileUri]) { | ||
expect(sampleCoverageData['hits'], isNotEmpty); | ||
} | ||
|
||
var hitMap = createHitmap(coverage); | ||
|
||
expect(hitMap, contains(_sampleAppFileUri)); | ||
|
||
var isolateFile = hitMap[_isolateLibFileUri]; | ||
|
||
expect(isolateFile, {11: 1, 12: 1, 14: 1, 16: 3, 18: 1}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | ||
// 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. | ||
|
||
library coverage.test.util; | ||
|
||
import 'package:path/path.dart' as p; | ||
|
||
final testAppPath = p.join('test', 'test_files', 'test_app.dart'); |