Chromium Code Reviews| Index: tests/standalone/coverage_test.dart |
| =================================================================== |
| --- tests/standalone/coverage_test.dart (revision 0) |
| +++ tests/standalone/coverage_test.dart (revision 0) |
| @@ -0,0 +1,62 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// This test forks a second vm process that runs the script tools/coverage.dart |
| +// and verifies that the coverage tool produces its expected output. |
| +// This test is mainly here to ensure that the coverage tool compiles and |
| +// runs. |
| + |
| +import "dart:io"; |
| +import "dart:utf"; |
| + |
| +var coverageToolUrl = "tools/coverage.dart"; |
| +var coverageTargetUrl = "tests/language/hello_dart_test.dart"; |
|
kustermann
2013/05/31 13:41:28
Using paths relative to dart/ requires this script
kustermann
2013/05/31 13:41:28
These are not really urls. You could rename them t
hausner
2013/05/31 21:53:02
Done.
hausner
2013/05/31 21:53:02
Changed to use paths relative to the path of this
|
| +Process coverageToolProcess; |
| +List sourceLines; |
| +int nextLineToMatch = 0; |
| + |
| +void onCoverageOutput(String line) { |
| + print("COV: $line"); |
| + if (nextLineToMatch < sourceLines.length) { |
| + if (line.endsWith(sourceLines[nextLineToMatch])) { |
| + nextLineToMatch++; |
|
kustermann
2013/05/31 13:41:28
If I see this correct, you actually don't verify t
hausner
2013/05/31 21:53:02
Correct. I just want to make sure the coverage too
|
| + } |
| + } |
| +} |
| + |
| +void onCoverageExit(exitCode) { |
| + var pid = coverageToolProcess.pid; |
| + print("process $pid terminated with exit code $exitCode."); |
| + if (nextLineToMatch < sourceLines.length) { |
| + print("Error: could not match all source code lines " |
| + "of '$coverageTargetUrl'"); |
| + exit(-1); |
| + } else { |
| + print("Successfully matched all lines of '$coverageTargetUrl'"); |
| + } |
| +} |
| + |
| +void main() { |
| + var options = new Options(); |
| + var targetOpts = [ "--compile_all", coverageToolUrl, coverageTargetUrl ]; |
| + |
| + sourceLines = new File(Uri.parse(coverageTargetUrl).path).readAsLinesSync(); |
|
kustermann
2013/05/31 13:41:28
Uri.path will give you always forward slashes AFAI
hausner
2013/05/31 21:53:02
Done.
|
| + assert(sourceLines != null); |
| + |
| + Process.start(options.executable, targetOpts).then((Process process) { |
|
ricow1
2013/05/31 05:29:02
No need to use Process.start here, use Process.run
kustermann
2013/05/31 13:41:28
agreed.
hausner
2013/05/31 21:53:02
I don't know how I'd get to stdout and stderr of t
ricow1
2013/06/01 06:27:58
Process.run(bin, args).then((result) {
print(res
|
| + coverageToolProcess = process; |
| + coverageToolProcess.stdin.close(); |
| + var stdoutStringStream = coverageToolProcess.stdout |
| + .transform(new StringDecoder()) |
| + .transform(new LineTransformer()); |
| + stdoutStringStream.listen(onCoverageOutput); |
| + |
| + var stderrStringStream = coverageToolProcess.stderr |
| + .transform(new StringDecoder()) |
| + .transform(new LineTransformer()); |
| + stderrStringStream.listen(onCoverageOutput); |
| + |
| + coverageToolProcess.exitCode.then(onCoverageExit); |
| + }); |
| +} |