Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: tools/testing/dart/test_progress.dart

Issue 12302016: Refactoring of ProgressIndicator (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added the TimingPrinter EventListener Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/test.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/test_progress.dart
diff --git a/tools/testing/dart/test_progress.dart b/tools/testing/dart/test_progress.dart
index 3de6e2f3e86f45c2c1c2ec26b906f4f4becd49d1..f5934072acadbf9f14b308dc4d83c76249608472 100644
--- a/tools/testing/dart/test_progress.dart
+++ b/tools/testing/dart/test_progress.dart
@@ -12,30 +12,110 @@ import "test_runner.dart";
import "test_suite.dart";
import "utils.dart";
-class ProgressIndicator {
- ProgressIndicator(this._startTime, this._printTiming)
- : _tests = [], _failureSummary = [];
+String _padTime(int time) {
+ if (time == 0) {
+ return '00';
+ } else if (time < 10) {
+ return '0$time';
+ } else {
+ return '$time';
+ }
+}
+
+String _timeString(Duration d) {
+ var min = d.inMinutes;
+ var sec = d.inSeconds % 60;
+ return '${_padTime(min)}:${_padTime(sec)}';
+}
+
+class EventListener {
+ void testAdded() { }
+ void start(TestCase test) { }
+ void done(TestCase test) { }
+ void allTestsKnown() { }
+ void allDone() { }
+}
+
+class ExitCodeSetter extends EventListener {
+ bool _failingTest = false;
+
+ void done(TestCase test) {
+ _failingTest = _failingTest || test.lastCommandOutput.unexpectedOutput;
+ }
+ void allDone() {
+ if (_failingTest) {
+ io.exitCode = 1;
+ }
+ }
+}
+
+class SummaryPrinter extends EventListener {
+ void allTestsKnown() {
+ if (SummaryReport.total > 0) {
+ SummaryReport.printReport();
+ }
+ }
+}
+
+class TimingPrinter extends EventListener {
+ List<TestCase> _tests = <TestCase>[];
+ Date _startTime;
+
+ TimingPrinter(this._startTime);
+
+ void done(TestCase testCase) {
+ _tests.add(testCase);
+ }
+
+ void allDone() {
+ // TODO: We should take all the commands into account
ahe 2013/02/19 11:43:42 Please use "TODO(username): Comment".
+ Duration d = (new Date.now()).difference(_startTime);
+ print('\n--- Total time: ${_timeString(d)} ---');
+ _tests.sort((a, b) {
+ Duration aDuration = a.lastCommandOutput.time;
+ Duration bDuration = b.lastCommandOutput.time;
+ return bDuration.inMilliseconds - aDuration.inMilliseconds;
+ });
+ for (int i = 0; i < 20 && i < _tests.length; i++) {
+ var name = _tests[i].displayName;
+ var duration = _tests[i].lastCommandOutput.time;
+ var configuration = _tests[i].configurationString;
+ print('${duration} - $configuration $name');
+ }
+ }
+}
+
+class LineProgressIndicator extends EventListener {
+ void done(TestCase test) {
+ var status = 'pass';
+ if (test.lastCommandOutput.unexpectedOutput) {
+ status = 'fail';
+ }
+ print('Done ${test.configurationString} ${test.displayName}: $status');
+ }
+}
+
+class ProgressIndicator extends EventListener {
+ ProgressIndicator(this._startTime)
+ : _failureSummary = [];
factory ProgressIndicator.fromName(String name,
- Date startTime,
- bool printTiming) {
+ Date startTime) {
switch (name) {
case 'compact':
- return new CompactProgressIndicator(startTime, printTiming);
+ return new CompactProgressIndicator(startTime);
case 'color':
- return new ColorProgressIndicator(startTime, printTiming);
+ return new ColorProgressIndicator(startTime);
case 'line':
- return new LineProgressIndicator(startTime, printTiming);
+ return new LineProgressIndicator();
case 'verbose':
- return new VerboseProgressIndicator(startTime, printTiming);
- case 'silent':
- return new SilentProgressIndicator(startTime, printTiming);
+ return new VerboseProgressIndicator(startTime);
case 'status':
- return new StatusProgressIndicator(startTime, printTiming);
+ return new StatusProgressIndicator(startTime);
case 'buildbot':
- return new BuildbotProgressIndicator(startTime, printTiming);
+ return new BuildbotProgressIndicator(startTime);
case 'diff':
- return new DiffProgressIndicator(startTime, printTiming);
+ return new DiffProgressIndicator(startTime);
default:
assert(false);
break;
@@ -68,13 +148,9 @@ class ProgressIndicator {
_passedTests++;
}
_printDoneProgress(test);
- // If we need to print timing information we hold on to all completed
- // tests.
- if (_printTiming) _tests.add(test);
}
void allTestsKnown() {
- if (!_allTestsKnown) SummaryReport.printReport();
_allTestsKnown = true;
}
@@ -85,35 +161,12 @@ class ProgressIndicator {
}
}
- void _printTimingInformation() {
- if (_printTiming) {
- // TODO: We should take all the commands into account
- Duration d = (new Date.now()).difference(_startTime);
- print('\n--- Total time: ${_timeString(d)} ---');
- _tests.sort((a, b) {
- Duration aDuration = a.lastCommandOutput.time;
- Duration bDuration = b.lastCommandOutput.time;
- return bDuration.inMilliseconds - aDuration.inMilliseconds;
- });
- for (int i = 0; i < 20 && i < _tests.length; i++) {
- var name = _tests[i].displayName;
- var duration = _tests[i].lastCommandOutput.time;
- var configuration = _tests[i].configurationString;
- print('${duration} - $configuration $name');
- }
- }
- }
-
void allDone() {
_printFailureSummary();
_printStatus();
_printSkippedCompilationInfo();
- _printTimingInformation();
stdout.close();
stderr.close();
- if (_failedTests > 0) {
- io.exitCode = 1;
- }
}
void _printStartProgress(TestCase test) {}
@@ -128,22 +181,6 @@ class ProgressIndicator {
return buffer.toString();
}
- String _padTime(int time) {
- if (time == 0) {
- return '00';
- } else if (time < 10) {
- return '0$time';
- } else {
- return '$time';
- }
- }
-
- String _timeString(Duration d) {
- var min = d.inMinutes;
- var sec = d.inSeconds % 60;
- return '${_padTime(min)}:${_padTime(sec)}';
- }
-
String _header(String header) => header;
void _printFailureOutput(TestCase test) {
@@ -257,33 +294,17 @@ class ProgressIndicator {
int _skippedCompilations = 0;
bool _allTestsKnown = false;
Date _startTime;
- bool _printTiming;
- List<TestCase> _tests;
List<String> _failureSummary;
}
-
-class SilentProgressIndicator extends ProgressIndicator {
- SilentProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
- void testAdded() { }
- void start(TestCase test) { }
- void done(TestCase test) { }
- void _printStartProgress(TestCase test) { }
- void _printDoneProgress(TestCase test) { }
- void allTestsKnown() { }
- void allDone() { }
-}
-
abstract class CompactIndicator extends ProgressIndicator {
- CompactIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ CompactIndicator(Date startTime)
+ : super(startTime);
void allDone() {
stdout.write('\n'.charCodes);
_printFailureSummary();
_printSkippedCompilationInfo();
- _printTimingInformation();
if (_failedTests > 0) {
// We may have printed many failure logs, so reprint the summary data.
_printProgress();
@@ -291,19 +312,6 @@ abstract class CompactIndicator extends ProgressIndicator {
}
stdout.close();
stderr.close();
- if (_failedTests > 0) {
- io.exitCode = 1;
- }
- }
-
- void allTestsKnown() {
- if (!_allTestsKnown && SummaryReport.total > 0) {
- // Clear progress indicator before printing summary report.
- stdout.write(
- '\r \r'.charCodes);
- SummaryReport.printReport();
- }
- _allTestsKnown = true;
}
void _printStartProgress(TestCase test) => _printProgress();
@@ -314,8 +322,8 @@ abstract class CompactIndicator extends ProgressIndicator {
class CompactProgressIndicator extends CompactIndicator {
- CompactProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ CompactProgressIndicator(Date startTime)
+ : super(startTime);
void _printProgress() {
var percent = ((_completedTests() / _foundTests) * 100).toInt().toString();
@@ -332,8 +340,8 @@ class CompactProgressIndicator extends CompactIndicator {
class ColorProgressIndicator extends CompactIndicator {
- ColorProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ ColorProgressIndicator(Date startTime)
+ : super(startTime);
static int BOLD = 1;
static int GREEN = 32;
@@ -372,26 +380,9 @@ class ColorProgressIndicator extends CompactIndicator {
}
-class LineProgressIndicator extends ProgressIndicator {
- LineProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
-
- void _printStartProgress(TestCase test) {
- }
-
- void _printDoneProgress(TestCase test) {
- var status = 'pass';
- if (test.lastCommandOutput.unexpectedOutput) {
- status = 'fail';
- }
- print('Done ${test.configurationString} ${test.displayName}: $status');
- }
-}
-
-
class VerboseProgressIndicator extends ProgressIndicator {
- VerboseProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ VerboseProgressIndicator(Date startTime)
+ : super(startTime);
void _printStartProgress(TestCase test) {
print('Starting ${test.configurationString} ${test.displayName}...');
@@ -408,8 +399,8 @@ class VerboseProgressIndicator extends ProgressIndicator {
class StatusProgressIndicator extends ProgressIndicator {
- StatusProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ StatusProgressIndicator(Date startTime)
+ : super(startTime);
void _printStartProgress(TestCase test) {
}
@@ -422,8 +413,8 @@ class StatusProgressIndicator extends ProgressIndicator {
class BuildbotProgressIndicator extends ProgressIndicator {
static String stepName;
- BuildbotProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ BuildbotProgressIndicator(Date startTime)
+ : super(startTime);
void _printStartProgress(TestCase test) {
}
@@ -451,8 +442,8 @@ class BuildbotProgressIndicator extends ProgressIndicator {
class DiffProgressIndicator extends ColorProgressIndicator {
Map<String, List<String>> statusToConfigs = new Map<String, List<String>>();
- DiffProgressIndicator(Date startTime, bool printTiming)
- : super(startTime, printTiming);
+ DiffProgressIndicator(Date startTime)
+ : super(startTime);
void _printFailureOutput(TestCase test) {
String status = '${test.displayName}: ${test.lastCommandOutput.result}';
« no previous file with comments | « tools/test.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698