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