Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: dart/tests/standalone/coverage_test.dart

Issue 15793010: Version 0.5.14.1 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This test forks a second vm process that runs the script tools/coverage.dart
6 // and verifies that the coverage tool produces its expected output.
7 // This test is mainly here to ensure that the coverage tool compiles and
8 // runs.
9
10 import "dart:io";
11 import "dart:async";
12
13 // Coverage tool script relative to the path of this test.
14 var coverageToolScript = "../../tools/coverage.dart";
15
16 // Coverage target script relative to this test.
17 var coverageTargetScript = "../language/hello_dart_test.dart";
18 var targPath;
19
20 Process coverageToolProcess;
21 List sourceLines;
22 int nextLineToMatch = 0;
23
24 void onCoverageOutput(String line) {
25 print("COV: $line");
26 if (nextLineToMatch < sourceLines.length) {
27 if (line.endsWith("|" + sourceLines[nextLineToMatch])) {
28 nextLineToMatch++;
29 }
30 }
31 }
32
33 bool checkExitCode(exitCode) {
34 var pid = coverageToolProcess.pid;
35 print("Coverage tool process (pid $pid) terminated with "
36 "exit code $exitCode.");
37 return exitCode == 0;
38 }
39
40 void checkSuccess() {
41 if (nextLineToMatch == sourceLines.length) {
42 print("Successfully matched all lines of '$targPath'");
43 } else {
44 print("Error: could not match all source code lines of '$targPath'");
45 exit(-1);
46 }
47 }
48
49 void main() {
50 var options = new Options();
51
52 // Compute paths for coverage tool and coverage target relative
53 // the the path of this script.
54 var scriptPath = new Path(options.script).directoryPath;
55 var toolPath = scriptPath.join(new Path(coverageToolScript)).canonicalize();
56 targPath = scriptPath.join(new Path(coverageTargetScript)).canonicalize();
57
58 sourceLines = new File(targPath.toNativePath()).readAsLinesSync();
59 assert(sourceLines != null);
60
61 var processOpts = [ "--compile_all",
62 toolPath.toNativePath(),
63 targPath.toNativePath() ];
64
65 Process.start(options.executable, processOpts).then((Process process) {
66 coverageToolProcess = process;
67 coverageToolProcess.stdin.close();
68 var stdoutStringStream = coverageToolProcess.stdout
69 .transform(new StringDecoder())
70 .transform(new LineTransformer());
71
72 var stderrStringStream = coverageToolProcess.stderr
73 .transform(new StringDecoder())
74 .transform(new LineTransformer());
75
76 // Wait for 3 future events: stdout and stderr streams of the coverage
77 // tool process closed, and coverage tool process terminated.
78 var futures = [];
79 var subscription = stdoutStringStream.listen(onCoverageOutput);
80 futures.add(subscription.asFuture(true));
81 subscription = stderrStringStream.listen(onCoverageOutput);
82 futures.add(subscription.asFuture(true));
83 futures.add(coverageToolProcess.exitCode.then(checkExitCode));
84 Future.wait(futures).then((results) {
85 checkSuccess();
86 if (results.contains(false)) exit(-1);
87 });
88 });
89 }
OLDNEW
« no previous file with comments | « dart/sdk/lib/_internal/pub/test/hosted/version_negotiation_test.dart ('k') | dart/tools/VERSION » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698