Chromium Code Reviews| OLD | NEW |
|---|---|
| 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:async"; |
| 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) { |
| 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 bool checkExitCode(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 " |
| 36 if (nextLineToMatch < sourceLines.length) { | 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 { | |
| 37 print("Error: could not match all source code lines of '$targPath'"); | 44 print("Error: could not match all source code lines of '$targPath'"); |
| 38 exit(-1); | 45 exit(-1); |
| 39 } else { | |
| 40 print("Successfully matched all lines of '$targPath'"); | |
| 41 } | 46 } |
| 42 } | 47 } |
| 43 | 48 |
| 44 void main() { | 49 void main() { |
| 45 var options = new Options(); | 50 var options = new Options(); |
| 46 | 51 |
| 47 // Compute paths for coverage tool and coverage target relative | 52 // Compute paths for coverage tool and coverage target relative |
| 48 // the the path of this script. | 53 // the the path of this script. |
| 49 var scriptPath = new Path(options.script).directoryPath; | 54 var scriptPath = new Path(options.script).directoryPath; |
| 50 var toolPath = scriptPath.join(new Path(coverageToolScript)).canonicalize(); | 55 var toolPath = scriptPath.join(new Path(coverageToolScript)).canonicalize(); |
| 51 targPath = scriptPath.join(new Path(coverageTargetScript)).canonicalize(); | 56 targPath = scriptPath.join(new Path(coverageTargetScript)).canonicalize(); |
| 52 | 57 |
| 53 sourceLines = new File(targPath.toNativePath()).readAsLinesSync(); | 58 sourceLines = new File(targPath.toNativePath()).readAsLinesSync(); |
| 54 assert(sourceLines != null); | 59 assert(sourceLines != null); |
| 55 | 60 |
| 56 var processOpts = [ "--compile_all", | 61 var processOpts = [ "--compile_all", |
| 57 toolPath.toNativePath(), | 62 toolPath.toNativePath(), |
| 58 targPath.toNativePath() ]; | 63 targPath.toNativePath() ]; |
| 59 | 64 |
| 60 Process.start(options.executable, processOpts).then((Process process) { | 65 Process.start(options.executable, processOpts).then((Process process) { |
| 61 coverageToolProcess = process; | 66 coverageToolProcess = process; |
| 62 coverageToolProcess.stdin.close(); | 67 coverageToolProcess.stdin.close(); |
| 63 var stdoutStringStream = coverageToolProcess.stdout | 68 var stdoutStringStream = coverageToolProcess.stdout |
| 64 .transform(new StringDecoder()) | 69 .transform(new StringDecoder()) |
| 65 .transform(new LineTransformer()); | 70 .transform(new LineTransformer()); |
| 66 stdoutStringStream.listen(onCoverageOutput); | |
| 67 | 71 |
| 68 var stderrStringStream = coverageToolProcess.stderr | 72 var stderrStringStream = coverageToolProcess.stderr |
| 69 .transform(new StringDecoder()) | 73 .transform(new StringDecoder()) |
| 70 .transform(new LineTransformer()); | 74 .transform(new LineTransformer()); |
| 71 stderrStringStream.listen(onCoverageOutput); | |
| 72 | 75 |
| 73 coverageToolProcess.exitCode.then(onCoverageExit); | 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(); | |
|
ricow1
2013/06/04 05:49:00
you don't really use the return values for anythin
hausner
2013/06/04 16:03:41
Done.
| |
| 86 }); | |
| 74 }); | 87 }); |
| 75 } | 88 } |
| OLD | NEW |