| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library testing.log; | 5 library testing.log; |
| 6 | 6 |
| 7 import 'chain.dart' show | 7 import 'chain.dart' show Result, Step; |
| 8 Result, | |
| 9 Step; | |
| 10 | 8 |
| 11 import 'suite.dart' show | 9 import 'suite.dart' show Suite; |
| 12 Suite; | |
| 13 | 10 |
| 14 import 'test_description.dart' show | 11 import 'test_description.dart' show TestDescription; |
| 15 TestDescription; | |
| 16 | 12 |
| 17 import 'expectation.dart' show | 13 import 'expectation.dart' show Expectation; |
| 18 Expectation; | |
| 19 | 14 |
| 20 /// ANSI escape code for moving cursor one line up. | 15 /// ANSI escape code for moving cursor one line up. |
| 21 /// See [CSI codes](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes). | 16 /// See [CSI codes](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes). |
| 22 const String cursorUp = "\u001b[1A"; | 17 const String cursorUp = "\u001b[1A"; |
| 23 | 18 |
| 24 /// ANSI escape code for erasing the entire line. | 19 /// ANSI escape code for erasing the entire line. |
| 25 /// See [CSI codes](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes). | 20 /// See [CSI codes](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes). |
| 26 const String eraseLine = "\u001b[2K"; | 21 const String eraseLine = "\u001b[2K"; |
| 27 | 22 |
| 28 final Stopwatch wallclock = new Stopwatch()..start(); | 23 final Stopwatch wallclock = new Stopwatch()..start(); |
| 29 | 24 |
| 30 bool _isVerbose = const bool.fromEnvironment("verbose"); | 25 bool _isVerbose = const bool.fromEnvironment("verbose"); |
| 31 | 26 |
| 32 bool get isVerbose => _isVerbose; | 27 bool get isVerbose => _isVerbose; |
| 33 | 28 |
| 34 void enableVerboseOutput() { | 29 void enableVerboseOutput() { |
| 35 _isVerbose = true; | 30 _isVerbose = true; |
| 36 } | 31 } |
| 37 | 32 |
| 38 void logTestComplete(int completed, int failed, int total, | 33 void logTestComplete(int completed, int failed, int total, Suite suite, |
| 39 Suite suite, TestDescription description) { | 34 TestDescription description) { |
| 40 String message = formatProgress(completed, failed, total); | 35 String message = formatProgress(completed, failed, total); |
| 41 if (suite != null) { | 36 if (suite != null) { |
| 42 message += ": ${formatTestDescription(suite, description)}"; | 37 message += ": ${formatTestDescription(suite, description)}"; |
| 43 } | 38 } |
| 44 logProgress(message); | 39 logProgress(message); |
| 45 } | 40 } |
| 46 | 41 |
| 47 void logStepStart(int completed, int failed, int total, | 42 void logStepStart(int completed, int failed, int total, Suite suite, |
| 48 Suite suite, TestDescription description, Step step) { | 43 TestDescription description, Step step) { |
| 49 String message = formatProgress(completed, failed, total); | 44 String message = formatProgress(completed, failed, total); |
| 50 if (suite != null) { | 45 if (suite != null) { |
| 51 message += ": ${formatTestDescription(suite, description)} ${step.name}"; | 46 message += ": ${formatTestDescription(suite, description)} ${step.name}"; |
| 52 if (step.isAsync) { | 47 if (step.isAsync) { |
| 53 message += "..."; | 48 message += "..."; |
| 54 } | 49 } |
| 55 } | 50 } |
| 56 logProgress(message); | 51 logProgress(message); |
| 57 } | 52 } |
| 58 | 53 |
| 59 void logStepComplete(int completed, int failed, int total, | 54 void logStepComplete(int completed, int failed, int total, Suite suite, |
| 60 Suite suite, TestDescription description, Step step) { | 55 TestDescription description, Step step) { |
| 61 if (!step.isAsync) return; | 56 if (!step.isAsync) return; |
| 62 String message = formatProgress(completed, failed, total); | 57 String message = formatProgress(completed, failed, total); |
| 63 if (suite != null) { | 58 if (suite != null) { |
| 64 message += ": ${formatTestDescription(suite, description)} ${step.name}!"; | 59 message += ": ${formatTestDescription(suite, description)} ${step.name}!"; |
| 65 } | 60 } |
| 66 logProgress(message); | 61 logProgress(message); |
| 67 } | 62 } |
| 68 | 63 |
| 69 void logProgress(String message) { | 64 void logProgress(String message) { |
| 70 if (isVerbose) { | 65 if (isVerbose) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 paddedLineNumber.substring(paddedLineNumber.length - pad); | 150 paddedLineNumber.substring(paddedLineNumber.length - pad); |
| 156 result.write("$paddedLineNumber: $line"); | 151 result.write("$paddedLineNumber: $line"); |
| 157 lineNumber++; | 152 lineNumber++; |
| 158 } | 153 } |
| 159 return '$result'; | 154 return '$result'; |
| 160 } | 155 } |
| 161 | 156 |
| 162 List<String> splitLines(String text) { | 157 List<String> splitLines(String text) { |
| 163 return text.split(new RegExp('^', multiLine: true)); | 158 return text.split(new RegExp('^', multiLine: true)); |
| 164 } | 159 } |
| OLD | NEW |