| 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:async"; | 11 import "dart:async"; |
| 12 import "package:path/path.dart"; |
| 12 | 13 |
| 13 // Coverage tool script relative to the path of this test. | 14 // Coverage tool script relative to the path of this test. |
| 14 var coverageToolScript = "../../tools/coverage.dart"; | 15 var coverageToolScript = "../../tools/coverage.dart"; |
| 15 | 16 |
| 16 // Coverage target script relative to this test. | 17 // Coverage target script relative to this test. |
| 17 var coverageTargetScript = "../language/hello_dart_test.dart"; | 18 var coverageTargetScript = "../language/hello_dart_test.dart"; |
| 18 var targPath; | 19 var targPath; |
| 19 | 20 |
| 20 Process coverageToolProcess; | 21 Process coverageToolProcess; |
| 21 List sourceLines; | 22 List sourceLines; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 print("Successfully matched all lines of '$targPath'"); | 43 print("Successfully matched all lines of '$targPath'"); |
| 43 } else { | 44 } else { |
| 44 print("Error: could not match all source code lines of '$targPath'"); | 45 print("Error: could not match all source code lines of '$targPath'"); |
| 45 exit(-1); | 46 exit(-1); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 void main() { | 50 void main() { |
| 50 // Compute paths for coverage tool and coverage target relative | 51 // Compute paths for coverage tool and coverage target relative |
| 51 // the the path of this script. | 52 // the the path of this script. |
| 52 var scriptPath = new Path(Platform.script).directoryPath; | 53 var scriptPath = dirname(Platform.script); |
| 53 var toolPath = scriptPath.join(new Path(coverageToolScript)).canonicalize(); | 54 var toolPath = normalize(join(scriptPath, coverageToolScript)); |
| 54 targPath = scriptPath.join(new Path(coverageTargetScript)).canonicalize(); | 55 targPath = normalize(join(scriptPath, coverageTargetScript)); |
| 55 | 56 |
| 56 sourceLines = new File(targPath.toNativePath()).readAsLinesSync(); | 57 sourceLines = new File(targPath).readAsLinesSync(); |
| 57 assert(sourceLines != null); | 58 assert(sourceLines != null); |
| 58 | 59 |
| 59 var processOpts = [ "--compile_all", | 60 var processOpts = [ "--compile_all", toolPath, targPath ]; |
| 60 toolPath.toNativePath(), | |
| 61 targPath.toNativePath() ]; | |
| 62 | 61 |
| 63 Process.start(Platform.executable, processOpts).then((Process process) { | 62 Process.start(Platform.executable, processOpts).then((Process process) { |
| 64 coverageToolProcess = process; | 63 coverageToolProcess = process; |
| 65 coverageToolProcess.stdin.close(); | 64 coverageToolProcess.stdin.close(); |
| 66 var stdoutStringStream = coverageToolProcess.stdout | 65 var stdoutStringStream = coverageToolProcess.stdout |
| 67 .transform(new StringDecoder()) | 66 .transform(new StringDecoder()) |
| 68 .transform(new LineTransformer()); | 67 .transform(new LineTransformer()); |
| 69 | 68 |
| 70 var stderrStringStream = coverageToolProcess.stderr | 69 var stderrStringStream = coverageToolProcess.stderr |
| 71 .transform(new StringDecoder()) | 70 .transform(new StringDecoder()) |
| 72 .transform(new LineTransformer()); | 71 .transform(new LineTransformer()); |
| 73 | 72 |
| 74 // Wait for 3 future events: stdout and stderr streams of the coverage | 73 // Wait for 3 future events: stdout and stderr streams of the coverage |
| 75 // tool process closed, and coverage tool process terminated. | 74 // tool process closed, and coverage tool process terminated. |
| 76 var futures = []; | 75 var futures = []; |
| 77 var subscription = stdoutStringStream.listen(onCoverageOutput); | 76 var subscription = stdoutStringStream.listen(onCoverageOutput); |
| 78 futures.add(subscription.asFuture(true)); | 77 futures.add(subscription.asFuture(true)); |
| 79 subscription = stderrStringStream.listen(onCoverageOutput); | 78 subscription = stderrStringStream.listen(onCoverageOutput); |
| 80 futures.add(subscription.asFuture(true)); | 79 futures.add(subscription.asFuture(true)); |
| 81 futures.add(coverageToolProcess.exitCode.then(checkExitCode)); | 80 futures.add(coverageToolProcess.exitCode.then(checkExitCode)); |
| 82 Future.wait(futures).then((results) { | 81 Future.wait(futures).then((results) { |
| 83 checkSuccess(); | 82 checkSuccess(); |
| 84 if (results.contains(false)) exit(-1); | 83 if (results.contains(false)) exit(-1); |
| 85 }); | 84 }); |
| 86 }); | 85 }); |
| 87 } | 86 } |
| OLD | NEW |