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

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

Issue 16305013: Fix coverage test (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This test forks a second vm process that runs the script tools/coverage.dart 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. 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 7 // This test is mainly here to ensure that the coverage tool compiles and
8 // runs. 8 // runs.
9 9
10 import "dart:io"; 10 import "dart:io";
11 import "dart:utf"; 11 import "dart:utf";
12 12
13 // Coverage tool script relative to the path of this test. 13 // Coverage tool script relative to the path of this test.
14 var coverageToolScript = "../../tools/coverage.dart"; 14 var coverageToolScript = "../../tools/coverage.dart";
15 15
16 // Coverage target script relative to this test. 16 // Coverage target script relative to this test.
17 var coverageTargetScript = "../language/hello_dart_test.dart"; 17 var coverageTargetScript = "../language/hello_dart_test.dart";
18 var targPath; 18 var targPath;
19 19
20 Process coverageToolProcess; 20 Process coverageToolProcess;
21 List sourceLines; 21 List sourceLines;
22 int nextLineToMatch = 0; 22 int nextLineToMatch = 0;
23 23
24 void onCoverageOutput(String line) { 24 void onCoverageOutput(String line) {
25 print("COV: $line"); 25 print("COV: $line");
26 if (nextLineToMatch < sourceLines.length) { 26 if (nextLineToMatch < sourceLines.length) {
ricow1 2013/06/03 19:05:57 don't we want an exact match? what should happen i
hausner 2013/06/03 20:48:08 A simple empty line from the coverage tool output
27 if (line.endsWith(sourceLines[nextLineToMatch])) { 27 if (line.endsWith(sourceLines[nextLineToMatch])) {
28 nextLineToMatch++; 28 nextLineToMatch++;
29 } 29 }
30 } 30 }
31 } 31 }
32 32
33 void onCoverageExit(exitCode) { 33 void onCoverageExit(exitCode) {
34 var pid = coverageToolProcess.pid; 34 var pid = coverageToolProcess.pid;
35 print("process $pid terminated with exit code $exitCode."); 35 print("Coverage tool process (pid $pid) terminated with exit code $exitCode.") ;
ricow1 2013/06/03 19:05:57 long line and I assume that this is for debugging
hausner 2013/06/03 20:48:08 Yes, for debugging. But it doesn't hurt to leave i
ricow1 2013/06/04 05:49:43 Nope, that is perfectly fine, just wanted to make
36 }
37
38 void checkSuccess() {
36 if (nextLineToMatch < sourceLines.length) { 39 if (nextLineToMatch < sourceLines.length) {
37 print("Error: could not match all source code lines of '$targPath'"); 40 print("Error: could not match all source code lines of '$targPath'");
38 exit(-1); 41 exit(-1);
39 } else { 42 } else {
40 print("Successfully matched all lines of '$targPath'"); 43 print("Successfully matched all lines of '$targPath'");
41 } 44 }
42 } 45 }
43 46
47 void onStdoutError(err) {
48 print("Error on coverage tool stdout: err");
49 checkSuccess();
50 }
51
44 void main() { 52 void main() {
45 var options = new Options(); 53 var options = new Options();
46 54
47 // Compute paths for coverage tool and coverage target relative 55 // Compute paths for coverage tool and coverage target relative
48 // the the path of this script. 56 // the the path of this script.
49 var scriptPath = new Path(options.script).directoryPath; 57 var scriptPath = new Path(options.script).directoryPath;
50 var toolPath = scriptPath.join(new Path(coverageToolScript)).canonicalize(); 58 var toolPath = scriptPath.join(new Path(coverageToolScript)).canonicalize();
51 targPath = scriptPath.join(new Path(coverageTargetScript)).canonicalize(); 59 targPath = scriptPath.join(new Path(coverageTargetScript)).canonicalize();
52 60
53 sourceLines = new File(targPath.toNativePath()).readAsLinesSync(); 61 sourceLines = new File(targPath.toNativePath()).readAsLinesSync();
54 assert(sourceLines != null); 62 assert(sourceLines != null);
55 63
56 var processOpts = [ "--compile_all", 64 var processOpts = [ "--compile_all",
57 toolPath.toNativePath(), 65 toolPath.toNativePath(),
58 targPath.toNativePath() ]; 66 targPath.toNativePath() ];
59 67
60 Process.start(options.executable, processOpts).then((Process process) { 68 Process.start(options.executable, processOpts).then((Process process) {
61 coverageToolProcess = process; 69 coverageToolProcess = process;
62 coverageToolProcess.stdin.close(); 70 coverageToolProcess.stdin.close();
63 var stdoutStringStream = coverageToolProcess.stdout 71 var stdoutStringStream = coverageToolProcess.stdout
64 .transform(new StringDecoder()) 72 .transform(new StringDecoder())
65 .transform(new LineTransformer()); 73 .transform(new LineTransformer());
66 stdoutStringStream.listen(onCoverageOutput); 74 stdoutStringStream.listen(onCoverageOutput,
75 onError: onStdoutError,
76 onDone: checkSuccess);
67 77
68 var stderrStringStream = coverageToolProcess.stderr 78 var stderrStringStream = coverageToolProcess.stderr
69 .transform(new StringDecoder()) 79 .transform(new StringDecoder())
70 .transform(new LineTransformer()); 80 .transform(new LineTransformer());
71 stderrStringStream.listen(onCoverageOutput); 81 stderrStringStream.listen(onCoverageOutput);
ricow1 2013/06/03 19:05:57 you can potentially get output on stderr after you
hausner 2013/06/03 20:48:08 Fair point. I changed this to use 3 futures, check
72 82
73 coverageToolProcess.exitCode.then(onCoverageExit); 83 coverageToolProcess.exitCode.then(onCoverageExit);
74 }); 84 });
75 } 85 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698