| 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:async"; | |
| 11 import "dart:convert"; | |
| 12 import "dart:io"; | |
| 13 | |
| 14 import "package:path/path.dart"; | |
| 15 | |
| 16 // Coverage tool script relative to the path of this test. | |
| 17 var coverageToolScript = "../../tools/coverage.dart"; | |
| 18 | |
| 19 // Coverage target script relative to this test. | |
| 20 var coverageTargetScript = "../language/hello_dart_test.dart"; | |
| 21 var targPath; | |
| 22 | |
| 23 Process coverageToolProcess; | |
| 24 List sourceLines; | |
| 25 int nextLineToMatch = 0; | |
| 26 | |
| 27 void onCoverageOutput(String line) { | |
| 28 print("COV: $line"); | |
| 29 if (nextLineToMatch < sourceLines.length) { | |
| 30 if (line.endsWith("|" + sourceLines[nextLineToMatch])) { | |
| 31 nextLineToMatch++; | |
| 32 } | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 bool checkExitCode(exitCode) { | |
| 37 var pid = coverageToolProcess.pid; | |
| 38 print("Coverage tool process (pid $pid) terminated with " | |
| 39 "exit code $exitCode."); | |
| 40 return exitCode == 0; | |
| 41 } | |
| 42 | |
| 43 void checkSuccess() { | |
| 44 if (nextLineToMatch == sourceLines.length) { | |
| 45 print("Successfully matched all lines of '$targPath'"); | |
| 46 } else { | |
| 47 print("Error: could not match all source code lines of '$targPath'"); | |
| 48 exit(-1); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void main() { | |
| 53 // Compute paths for coverage tool and coverage target relative | |
| 54 // the the path of this script. | |
| 55 var scriptPath = dirname(Platform.script.toFilePath()); | |
| 56 var toolPath = normalize(join(scriptPath, coverageToolScript)); | |
| 57 targPath = normalize(join(scriptPath, coverageTargetScript)); | |
| 58 | |
| 59 sourceLines = new File(targPath).readAsLinesSync(); | |
| 60 assert(sourceLines != null); | |
| 61 | |
| 62 var processOpts = [ "--compile_all", toolPath, targPath ]; | |
| 63 | |
| 64 Process.start(Platform.executable, processOpts).then((Process process) { | |
| 65 coverageToolProcess = process; | |
| 66 coverageToolProcess.stdin.close(); | |
| 67 var stdoutStringStream = coverageToolProcess.stdout | |
| 68 .transform(UTF8.decoder) | |
| 69 .transform(new LineSplitter()); | |
| 70 | |
| 71 var stderrStringStream = coverageToolProcess.stderr | |
| 72 .transform(UTF8.decoder) | |
| 73 .transform(new LineSplitter()); | |
| 74 | |
| 75 // Wait for 3 future events: stdout and stderr streams of the coverage | |
| 76 // tool process closed, and coverage tool process terminated. | |
| 77 var futures = []; | |
| 78 var subscription = stdoutStringStream.listen(onCoverageOutput); | |
| 79 futures.add(subscription.asFuture(true)); | |
| 80 subscription = stderrStringStream.listen(onCoverageOutput); | |
| 81 futures.add(subscription.asFuture(true)); | |
| 82 futures.add(coverageToolProcess.exitCode.then(checkExitCode)); | |
| 83 Future.wait(futures).then((results) { | |
| 84 checkSuccess(); | |
| 85 if (results.contains(false)) exit(-1); | |
| 86 }); | |
| 87 }); | |
| 88 } | |
| OLD | NEW |