| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 | 2 |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 /** The entry point for the analyzer. */ | 7 /** The entry point for the analyzer. */ |
| 8 library analyzer; | 8 library analyzer; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 typedef ErrorSeverity BatchRunnerHandler(List<String> args); | 90 typedef ErrorSeverity BatchRunnerHandler(List<String> args); |
| 91 | 91 |
| 92 /// Provides a framework to read command line options from stdin and feed them t
o a callback. | 92 /// Provides a framework to read command line options from stdin and feed them t
o a callback. |
| 93 class BatchRunner { | 93 class BatchRunner { |
| 94 /** | 94 /** |
| 95 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail | 95 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail |
| 96 * status through stdout. This feature is intended for use in unit testing. | 96 * status through stdout. This feature is intended for use in unit testing. |
| 97 */ | 97 */ |
| 98 static ErrorSeverity runAsBatch(List<String> sharedArgs, BatchRunnerHandler ha
ndler) { | 98 static void runAsBatch(List<String> sharedArgs, BatchRunnerHandler handler) { |
| 99 stdout.writeln('>>> BATCH START'); | 99 stdout.writeln('>>> BATCH START'); |
| 100 Stopwatch stopwatch = new Stopwatch(); | 100 Stopwatch stopwatch = new Stopwatch(); |
| 101 stopwatch.start(); | 101 stopwatch.start(); |
| 102 int testsFailed = 0; | 102 int testsFailed = 0; |
| 103 int totalTests = 0; | 103 int totalTests = 0; |
| 104 ErrorSeverity batchResult = ErrorSeverity.NONE; | 104 ErrorSeverity batchResult = ErrorSeverity.NONE; |
| 105 // read line from stdin | 105 // read line from stdin |
| 106 Stream cmdLine = stdin | 106 Stream cmdLine = stdin |
| 107 .transform(UTF8.decoder) | 107 .transform(UTF8.decoder) |
| 108 .transform(new LineSplitter()); | 108 .transform(new LineSplitter()); |
| 109 var subscription = cmdLine.listen((String line) { | 109 var subscription = cmdLine.listen((String line) { |
| 110 // may be finish | 110 // may be finish |
| 111 if (line.isEmpty) { | 111 if (line.isEmpty) { |
| 112 var time = stopwatch.elapsedMilliseconds; | 112 var time = stopwatch.elapsedMilliseconds; |
| 113 stdout.writeln('>>> BATCH END (${totalTests - testsFailed}/$totalTests)
${time}ms'); | 113 stdout.writeln('>>> BATCH END (${totalTests - testsFailed}/$totalTests)
${time}ms'); |
| 114 exit(batchResult.ordinal); | 114 exitCode = batchResult.ordinal; |
| 115 } | 115 } |
| 116 // prepare aruments | 116 // prepare aruments |
| 117 var args; | 117 var args; |
| 118 { | 118 { |
| 119 var lineArgs = line.split(new RegExp('\\s+')); | 119 var lineArgs = line.split(new RegExp('\\s+')); |
| 120 args = new List<String>(); | 120 args = new List<String>(); |
| 121 args.addAll(sharedArgs); | 121 args.addAll(sharedArgs); |
| 122 args.addAll(lineArgs); | 122 args.addAll(lineArgs); |
| 123 args.remove('-b'); | 123 args.remove('-b'); |
| 124 args.remove('--batch'); | 124 args.remove('--batch'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 140 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); | 140 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); |
| 141 } catch (e, stackTrace) { | 141 } catch (e, stackTrace) { |
| 142 stderr.writeln(e); | 142 stderr.writeln(e); |
| 143 stderr.writeln(stackTrace); | 143 stderr.writeln(stackTrace); |
| 144 stderr.writeln('>>> EOF STDERR'); | 144 stderr.writeln('>>> EOF STDERR'); |
| 145 stdout.writeln('>>> TEST CRASH'); | 145 stdout.writeln('>>> TEST CRASH'); |
| 146 } | 146 } |
| 147 }); | 147 }); |
| 148 } | 148 } |
| 149 } | 149 } |
| OLD | NEW |