Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library test.runner.reporter.no_io_compact; | 5 library test.runner.reporter.no_io_compact; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../../backend/live_test.dart'; | 9 import '../../backend/live_test.dart'; |
| 10 import '../../backend/state.dart'; | 10 import '../../backend/state.dart'; |
| 11 import '../../backend/suite.dart'; | 11 import '../../backend/suite.dart'; |
| 12 import '../../utils.dart'; | 12 import '../../utils.dart'; |
| 13 import '../engine.dart'; | 13 import '../engine.dart'; |
| 14 | 14 |
| 15 /// The maximum console line length. | 15 /// The maximum console line length. |
| 16 /// | 16 /// |
| 17 /// Lines longer than this will be cropped. | 17 /// Lines longer than this will be cropped. |
| 18 const _lineLength = 100; | 18 const _lineLength = 100; |
| 19 | 19 |
| 20 // TODO(nweiz): Get rid of this when issue 6943 is fixed. | 20 /// A reporter that prints each test on its own line. |
| 21 /// A reporter that doesn't import `dart:io`, even transitively. | |
| 22 /// | 21 /// |
| 23 /// This is used in place of [CompactReporter] by `lib/test.dart`, which | 22 /// This is currently used in place of [CompactReporter] by `lib/test.dart`, |
| 24 /// can't transitively import `dart:io` but still needs access to a runner so | 23 /// which can't transitively import `dart:io` but still needs access to a runner |
| 25 /// that test files can be run directly. | 24 /// so that test files can be run directly. This means that until issue 6943 is |
| 26 class NoIoCompactReporter { | 25 /// fixed, this must not import `dart:io`. |
| 26 class ExpandedReporter { | |
| 27 /// The terminal escape for green text, or the empty string if this is Windows | 27 /// The terminal escape for green text, or the empty string if this is Windows |
| 28 /// or not outputting to a terminal. | 28 /// or not outputting to a terminal. |
| 29 final String _green; | 29 final String _green; |
| 30 | 30 |
| 31 /// The terminal escape for red text, or the empty string if this is Windows | 31 /// The terminal escape for red text, or the empty string if this is Windows |
| 32 /// or not outputting to a terminal. | 32 /// or not outputting to a terminal. |
| 33 final String _red; | 33 final String _red; |
| 34 | 34 |
| 35 /// The terminal escape for yellow text, or the empty string if this is | 35 /// The terminal escape for yellow text, or the empty string if this is |
| 36 /// Windows or not outputting to a terminal. | 36 /// Windows or not outputting to a terminal. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 54 | 54 |
| 55 /// The set of tests that have completed and been marked as passing. | 55 /// The set of tests that have completed and been marked as passing. |
| 56 final _passed = new Set<LiveTest>(); | 56 final _passed = new Set<LiveTest>(); |
| 57 | 57 |
| 58 /// The set of tests that have completed and been marked as skipped. | 58 /// The set of tests that have completed and been marked as skipped. |
| 59 final _skipped = new Set<LiveTest>(); | 59 final _skipped = new Set<LiveTest>(); |
| 60 | 60 |
| 61 /// The set of tests that have completed and been marked as failing or error. | 61 /// The set of tests that have completed and been marked as failing or error. |
| 62 final _failed = new Set<LiveTest>(); | 62 final _failed = new Set<LiveTest>(); |
| 63 | 63 |
| 64 /// The set of tests that are still running. | |
| 65 final _active = new List<LiveTest>(); | |
| 66 | |
| 64 /// The size of [_passed] last time a progress notification was printed. | 67 /// The size of [_passed] last time a progress notification was printed. |
| 65 int _lastProgressPassed; | 68 int _lastProgressPassed; |
| 66 | 69 |
| 67 /// The size of [_skipped] last time a progress notification was printed. | 70 /// The size of [_skipped] last time a progress notification was printed. |
| 68 int _lastProgressSkipped; | 71 int _lastProgressSkipped; |
| 69 | 72 |
| 70 /// The size of [_failed] last time a progress notification was printed. | 73 /// The size of [_failed] last time a progress notification was printed. |
| 71 int _lastProgressFailed; | 74 int _lastProgressFailed; |
| 72 | 75 |
| 73 /// The message printed for the last progress notification. | 76 /// The message printed for the last progress notification. |
| 74 String _lastProgressMessage; | 77 String _lastProgressMessage; |
| 75 | 78 |
| 76 /// Creates a [NoIoCompactReporter] that will run all tests in [suites]. | 79 /// Creates a [NoIoCompactReporter] that will run all tests in [suites]. |
| 77 /// | 80 /// |
| 78 /// If [color] is `true`, this will use terminal colors; if it's `false`, it | 81 /// If [color] is `true`, this will use terminal colors; if it's `false`, it |
| 79 /// won't. | 82 /// won't. |
| 80 NoIoCompactReporter(Iterable<Suite> suites, {bool color: true}) | 83 ExpandedReporter(Iterable<Suite> suites, {int concurrency, bool color: true}) |
|
kevmoo
2015/04/23 00:13:14
TODO: document concurrency here
nweiz
2015/04/23 00:15:52
Done.
| |
| 81 : _multiplePaths = suites.map((suite) => suite.path).toSet().length > 1, | 84 : _multiplePaths = suites.map((suite) => suite.path).toSet().length > 1, |
| 82 _multiplePlatforms = | 85 _multiplePlatforms = |
| 83 suites.map((suite) => suite.platform).toSet().length > 1, | 86 suites.map((suite) => suite.platform).toSet().length > 1, |
| 84 _engine = new Engine(suites), | 87 _engine = new Engine(suites, concurrency: concurrency), |
| 85 _green = color ? '\u001b[32m' : '', | 88 _green = color ? '\u001b[32m' : '', |
| 86 _red = color ? '\u001b[31m' : '', | 89 _red = color ? '\u001b[31m' : '', |
| 87 _yellow = color ? '\u001b[33m' : '', | 90 _yellow = color ? '\u001b[33m' : '', |
| 88 _noColor = color ? '\u001b[0m' : '' { | 91 _noColor = color ? '\u001b[0m' : '' { |
| 89 _engine.onTestStarted.listen((liveTest) { | 92 _engine.onTestStarted.listen((liveTest) { |
| 93 if (_active.isEmpty) _progressLine(_description(liveTest)); | |
| 94 _active.add(liveTest); | |
| 95 | |
| 90 liveTest.onStateChange.listen((state) { | 96 liveTest.onStateChange.listen((state) { |
| 91 if (state.status != Status.complete) return; | 97 if (state.status != Status.complete) return; |
| 98 _active.remove(liveTest); | |
| 92 | 99 |
| 93 if (state.result != Result.success) { | 100 if (state.result != Result.success) { |
| 94 _passed.remove(liveTest); | 101 _passed.remove(liveTest); |
| 95 _failed.add(liveTest); | 102 _failed.add(liveTest); |
| 96 } else if (liveTest.test.metadata.skip) { | 103 } else if (liveTest.test.metadata.skip) { |
| 97 _skipped.add(liveTest); | 104 _skipped.add(liveTest); |
| 98 } else { | 105 } else { |
| 99 _passed.add(liveTest); | 106 _passed.add(liveTest); |
| 100 } | 107 } |
| 101 | 108 |
| 102 _progressLine(_description(liveTest)); | |
| 103 | |
| 104 if (liveTest.test.metadata.skip && | 109 if (liveTest.test.metadata.skip && |
| 105 liveTest.test.metadata.skipReason != null) { | 110 liveTest.test.metadata.skipReason != null) { |
| 111 _progressLine(_description(liveTest)); | |
| 106 print(indent('${_yellow}Skip: ${liveTest.test.metadata.skipReason}' | 112 print(indent('${_yellow}Skip: ${liveTest.test.metadata.skipReason}' |
| 107 '$_noColor')); | 113 '$_noColor')); |
| 114 } else if (_active.isNotEmpty) { | |
| 115 // If any tests are running, display the name of the oldest active | |
| 116 // test. | |
| 117 _progressLine(_description(_active.first)); | |
| 108 } | 118 } |
| 109 }); | 119 }); |
| 110 | 120 |
| 111 liveTest.onError.listen((error) { | 121 liveTest.onError.listen((error) { |
| 112 if (liveTest.state.status != Status.complete) return; | 122 if (liveTest.state.status != Status.complete) return; |
| 113 | 123 |
| 114 _progressLine(_description(liveTest)); | 124 _progressLine(_description(liveTest)); |
| 115 print(indent(error.error.toString())); | 125 print(indent(error.error.toString())); |
| 116 print(indent(terseChain(error.stackTrace).toString())); | 126 print(indent(terseChain(error.stackTrace).toString())); |
| 117 }); | 127 }); |
| 118 | 128 |
| 119 liveTest.onPrint.listen((line) { | 129 liveTest.onPrint.listen((line) { |
| 120 _progressLine(_description(liveTest)); | 130 _progressLine(_description(liveTest)); |
| 121 print(line); | 131 print(line); |
| 122 }); | 132 }); |
| 123 }); | 133 }); |
| 124 } | 134 } |
| 125 | 135 |
| 126 /// Runs all tests in all provided suites. | 136 /// Runs all tests in all provided suites. |
| 127 /// | 137 /// |
| 128 /// This returns `true` if all tests succeed, and `false` otherwise. It will | 138 /// This returns `true` if all tests succeed, and `false` otherwise. It will |
| 129 /// only return once all tests have finished running. | 139 /// only return once all tests have finished running. |
| 130 Future<bool> run() { | 140 Future<bool> run() { |
| 131 if (_stopwatch.isRunning) { | 141 if (_stopwatch.isRunning) { |
| 132 throw new StateError("CompactReporter.run() may not be called more than " | 142 throw new StateError("ExpandedReporter.run() may not be called more than " |
| 133 "once."); | 143 "once."); |
| 134 } | 144 } |
| 135 | 145 |
| 136 if (_engine.liveTests.isEmpty) { | 146 if (_engine.liveTests.isEmpty) { |
| 137 print("No tests ran."); | 147 print("No tests ran."); |
| 138 return new Future.value(true); | 148 return new Future.value(true); |
| 139 } | 149 } |
| 140 | 150 |
| 141 _stopwatch.start(); | 151 _stopwatch.start(); |
| 142 return _engine.run().then((success) { | 152 return _engine.run().then((success) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 173 _lastProgressPassed = _passed.length; | 183 _lastProgressPassed = _passed.length; |
| 174 _lastProgressSkipped = _skipped.length; | 184 _lastProgressSkipped = _skipped.length; |
| 175 _lastProgressFailed = _failed.length; | 185 _lastProgressFailed = _failed.length; |
| 176 _lastProgressMessage = message; | 186 _lastProgressMessage = message; |
| 177 | 187 |
| 178 if (color == null) color = ''; | 188 if (color == null) color = ''; |
| 179 var duration = _stopwatch.elapsed; | 189 var duration = _stopwatch.elapsed; |
| 180 var buffer = new StringBuffer(); | 190 var buffer = new StringBuffer(); |
| 181 | 191 |
| 182 // \r moves back to the beginning of the current line. | 192 // \r moves back to the beginning of the current line. |
| 183 buffer.write('\r${_timeString(duration)} '); | 193 buffer.write('${_timeString(duration)} '); |
| 184 buffer.write(_green); | 194 buffer.write(_green); |
| 185 buffer.write('+'); | 195 buffer.write('+'); |
| 186 buffer.write(_passed.length); | 196 buffer.write(_passed.length); |
| 187 buffer.write(_noColor); | 197 buffer.write(_noColor); |
| 188 | 198 |
| 189 if (_skipped.isNotEmpty) { | 199 if (_skipped.isNotEmpty) { |
| 190 buffer.write(_yellow); | 200 buffer.write(_yellow); |
| 191 buffer.write(' ~'); | 201 buffer.write(' ~'); |
| 192 buffer.write(_skipped.length); | 202 buffer.write(_skipped.length); |
| 193 buffer.write(_noColor); | 203 buffer.write(_noColor); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 /// This differs from the test's own description in that it may also include | 236 /// This differs from the test's own description in that it may also include |
| 227 /// the suite's name. | 237 /// the suite's name. |
| 228 String _description(LiveTest liveTest) { | 238 String _description(LiveTest liveTest) { |
| 229 var name = liveTest.test.name; | 239 var name = liveTest.test.name; |
| 230 | 240 |
| 231 if (_multiplePaths && liveTest.suite.path != null) { | 241 if (_multiplePaths && liveTest.suite.path != null) { |
| 232 name = "${liveTest.suite.path}: $name"; | 242 name = "${liveTest.suite.path}: $name"; |
| 233 } | 243 } |
| 234 | 244 |
| 235 if (_multiplePlatforms && liveTest.suite.platform != null) { | 245 if (_multiplePlatforms && liveTest.suite.platform != null) { |
| 236 name = "[$liveTest.suite.platform] $name"; | 246 name = "[${liveTest.suite.platform}] $name"; |
| 237 } | 247 } |
| 238 | 248 |
| 239 return name; | 249 return name; |
| 240 } | 250 } |
| 241 } | 251 } |
| OLD | NEW |