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

Side by Side Diff: lib/src/simple_configuration.dart

Issue 934413002: Replace the existing unittest APIs with the new runner infrastructure. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Rebase Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 unittest.simple_configuration; 5 library unittest.simple_configuration;
kevmoo 2015/02/19 23:13:19 Mark the library as deprecated – its lights up nic
6 6
7 import 'dart:isolate'; 7 import 'test_case.dart';
8 import 'configuration.dart';
8 9
9 import '../unittest.dart'; 10 /// This is a stub class used to preserve compatibility with unittest 0.11.*.
10 import 'configuration.dart';
11 import 'utils.dart';
12
13 /// A configuration that provides hooks to configure the unittest library for
14 /// different platforms.
15 /// 11 ///
16 /// This class implements the [Configuration] API in a platform-independent way. 12 /// It will be removed before the next version is released.
17 /// Tests that want to take advantage of the platform can create a subclass and 13 @deprecated
18 /// override methods from this class.
19 class SimpleConfiguration extends Configuration { 14 class SimpleConfiguration extends Configuration {
20 /// A port that keeps the VM alive while we wait for asynchronous tests to
21 /// finish.
22 ///
23 /// The VM won't shut down as long as there's an open receive port.
24 ReceivePort _receivePort;
25
26 /// If true (the default), throw an exception at the end if any tests failed.
27 bool throwOnTestFailures = true; 15 bool throwOnTestFailures = true;
28
29 /// The constructor sets up a failure handler for [expect] that redirects
30 /// [expect] failures to [onExpectFailure].
31 SimpleConfiguration() : super.blank(); 16 SimpleConfiguration() : super.blank();
32 17
33 void onInit() { 18 String formatResult(TestCase testCase) => "";
34 // For Dart internal tests, we don't want stack frame filtering.
35 // We turn it off here in the default config, but by default turn
36 // it back on in the vm and html configs.
37 filterStacks = false;
38 _receivePort = new ReceivePort();
39 _postMessage('unittest-suite-wait-for-done');
40 }
41
42 /// Called when each test starts. Useful to show intermediate progress on
43 /// a test suite. Derived classes should call this first before their own
44 /// override code.
45 void onTestStart(TestCase testCase) {}
46
47 /// Handles the logging of messages by a test case.
48 ///
49 /// The default in this base configuration is to call [print].
50 void onLogMessage(TestCase testCase, String message) {
51 print(message);
52 }
53
54 /// Format a test result.
55 String formatResult(TestCase testCase) {
56 var result = new StringBuffer();
57 result.write(testCase.result.toUpperCase());
58 result.write(": ");
59 result.write(testCase.description);
60 result.write("\n");
61
62 if (testCase.message != '') {
63 result.write(indent(testCase.message));
64 result.write("\n");
65 }
66
67 if (testCase.stackTrace != null) {
68 result.write(indent(testCase.stackTrace.toString()));
69 result.write("\n");
70 }
71 return result.toString();
72 }
73
74 /// Called with the result of all test cases.
75 ///
76 /// The default implementation prints the result summary using [print],
77 /// formatted with [formatResult]. Browser tests commonly override this to
78 /// reformat the output.
79 ///
80 /// When [uncaughtError] is not null, it contains an error that occured
81 /// outside of tests (e.g. setting up the test).
82 void onSummary(int passed, int failed, int errors, List<TestCase> results,
83 String uncaughtError) {
84 // Print each test's result.
85 for (var test in results) {
86 print(formatResult(test).trim());
87 }
88
89 // Show the summary.
90 print('');
91
92 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) {
93 print('No tests found.');
94 // This is considered a failure too.
95 } else if (failed == 0 && errors == 0 && uncaughtError == null) {
96 print('All $passed tests passed.');
97 } else {
98 if (uncaughtError != null) {
99 print('Top-level uncaught error: $uncaughtError');
100 }
101 print('$passed PASSED, $failed FAILED, $errors ERRORS');
102 }
103 }
104
105 void onDone(bool success) {
106 if (success) {
107 _postMessage('unittest-suite-success');
108 _receivePort.close();
109 } else {
110 _receivePort.close();
111 if (throwOnTestFailures) {
112 throw new Exception('Some tests failed.');
113 }
114 }
115 }
116
117 void _postMessage(String message) {
118 // In dart2js browser tests, the JavaScript-based test controller
119 // intercepts calls to print and listens for "secret" messages.
120 print(message);
121 }
122 } 19 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698