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

Side by Side Diff: pkg/unittest/lib/unittest.dart

Issue 10917275: Update unittest to new package layout. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | pkg/unittest/lib/vm_config.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * A library for writing dart unit tests. 6 * A library for writing dart unit tests.
7 * 7 *
8 * To import this library, specify the relative path to 8 * To import this library, specify the relative path to
9 * pkg/unittest/unittest.dart. 9 * pkg/unittest/lib/unittest.dart.
10 * 10 *
11 * ##Concepts## 11 * ##Concepts##
12 * 12 *
13 * * Tests: Tests are specified via the top-level function [test], they can be 13 * * Tests: Tests are specified via the top-level function [test], they can be
14 * organized together using [group]. 14 * organized together using [group].
15 * * Checks: Test expectations can be specified via [expect] 15 * * Checks: Test expectations can be specified via [expect]
16 * * Matchers: [expect] assertions are written declaratively using [Matcher]s 16 * * Matchers: [expect] assertions are written declaratively using [Matcher]s
17 * * Configuration: The framework can be adapted by calling [configure] with a 17 * * Configuration: The framework can be adapted by calling [configure] with a
18 * [Configuration]. Common configurations can be found in this package 18 * [Configuration]. Common configurations can be found in this package
19 * under: 'dom\_config.dart' (deprecated), 'html\_config.dart' (for running 19 * under: 'dom\_config.dart' (deprecated), 'html\_config.dart' (for running
20 * tests compiled to Javascript in a browser), and 'vm\_config.dart' (for 20 * tests compiled to Javascript in a browser), and 'vm\_config.dart' (for
21 * running native Dart tests on the VM). 21 * running native Dart tests on the VM).
22 * 22 *
23 * ##Examples## 23 * ##Examples##
24 * 24 *
25 * A trivial test: 25 * A trivial test:
26 * 26 *
27 * #import('path-to-dart/pkg/unittest/unitest.dart'); 27 * #import('package:unittest/unittest.dart');
28 * main() { 28 * main() {
29 * test('this is a test', () { 29 * test('this is a test', () {
30 * int x = 2 + 3; 30 * int x = 2 + 3;
31 * expect(x, equals(5)); 31 * expect(x, equals(5));
32 * }); 32 * });
33 * } 33 * }
34 * 34 *
35 * Multiple tests: 35 * Multiple tests:
36 * 36 *
37 * #import('path-to-dart/pkg/unittest/unitest.dart'); 37 * #import('package:unittest/unittest.dart');
38 * main() { 38 * main() {
39 * test('this is a test', () { 39 * test('this is a test', () {
40 * int x = 2 + 3; 40 * int x = 2 + 3;
41 * expect(x, equals(5)); 41 * expect(x, equals(5));
42 * }); 42 * });
43 * test('this is another test', () { 43 * test('this is another test', () {
44 * int x = 2 + 3; 44 * int x = 2 + 3;
45 * expect(x, equals(5)); 45 * expect(x, equals(5));
46 * }); 46 * });
47 * } 47 * }
48 * 48 *
49 * Multiple tests, grouped by category: 49 * Multiple tests, grouped by category:
50 * 50 *
51 * #import('path-to-dart/pkg/unittest/unitest.dart'); 51 * #import('package:unittest/unittest.dart');
52 * main() { 52 * main() {
53 * group('group A', () { 53 * group('group A', () {
54 * test('test A.1', () { 54 * test('test A.1', () {
55 * int x = 2 + 3; 55 * int x = 2 + 3;
56 * expect(x, equals(5)); 56 * expect(x, equals(5));
57 * }); 57 * });
58 * test('test A.2', () { 58 * test('test A.2', () {
59 * int x = 2 + 3; 59 * int x = 2 + 3;
60 * expect(x, equals(5)); 60 * expect(x, equals(5));
61 * }); 61 * });
62 * }); 62 * });
63 * group('group B', () { 63 * group('group B', () {
64 * test('this B.1', () { 64 * test('this B.1', () {
65 * int x = 2 + 3; 65 * int x = 2 + 3;
66 * expect(x, equals(5)); 66 * expect(x, equals(5));
67 * }); 67 * });
68 * }); 68 * });
69 * } 69 * }
70 * 70 *
71 * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments, 71 * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments,
72 * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a 72 * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a
73 * function into a new callback and will not consider the test complete until 73 * function into a new callback and will not consider the test complete until
74 * that callback is run. A count argument can be provided to specify the number 74 * that callback is run. A count argument can be provided to specify the number
75 * of times the callback should be called (the default is 1). 75 * of times the callback should be called (the default is 1).
76 * 76 *
77 * #import('path-to-dart/pkg/unittest/unitest.dart'); 77 * #import('package:unittest/unittest.dart');
78 * #import('dart:html'); 78 * #import('dart:html');
79 * main() { 79 * main() {
80 * test('calllback is executed once', () { 80 * test('calllback is executed once', () {
81 * // wrap the callback of an asynchronous call with [expectAsync0] if 81 * // wrap the callback of an asynchronous call with [expectAsync0] if
82 * // the callback takes 0 arguments... 82 * // the callback takes 0 arguments...
83 * window.setTimeout(expectAsync0(() { 83 * window.setTimeout(expectAsync0(() {
84 * int x = 2 + 3; 84 * int x = 2 + 3;
85 * expect(x, equals(5)); 85 * expect(x, equals(5));
86 * }), 0); 86 * }), 0);
87 * }); 87 * });
(...skipping 20 matching lines...) Expand all
108 * depending on the number of positional arguments of the callback. In the 108 * depending on the number of positional arguments of the callback. In the
109 * future, we plan to expose a single `expectAsync` function that can be used 109 * future, we plan to expose a single `expectAsync` function that can be used
110 * regardless of the number of positional arguments. This requires new langauge 110 * regardless of the number of positional arguments. This requires new langauge
111 * features or fixes to the current spec (e.g. see 111 * features or fixes to the current spec (e.g. see
112 * [Issue 2706](http://dartbug.com/2706)). 112 * [Issue 2706](http://dartbug.com/2706)).
113 * 113 *
114 * Meanwhile, we plan to add this alternative API for callbacks of more than 2 114 * Meanwhile, we plan to add this alternative API for callbacks of more than 2
115 * arguments or that take named parameters. (this is not implemented yet, 115 * arguments or that take named parameters. (this is not implemented yet,
116 * but will be coming here soon). 116 * but will be coming here soon).
117 * 117 *
118 * #import('path-to-dart/pkg/unittest/unitest.dart'); 118 * #import('package:unittest/unittest.dart');
119 * #import('dart:html'); 119 * #import('dart:html');
120 * main() { 120 * main() {
121 * test('calllback is executed', () { 121 * test('calllback is executed', () {
122 * // indicate ahead of time that an async callback is expected. 122 * // indicate ahead of time that an async callback is expected.
123 * var async = startAsync(); 123 * var async = startAsync();
124 * window.setTimeout(() { 124 * window.setTimeout(() {
125 * // Guard the body of the callback, so errors are propagated 125 * // Guard the body of the callback, so errors are propagated
126 * // correctly 126 * // correctly
127 * guardAsync(() { 127 * guardAsync(() {
128 * int x = 2 + 3; 128 * int x = 2 + 3;
129 * expect(x, equals(5)); 129 * expect(x, equals(5));
130 * }); 130 * });
131 * // indicate that the asynchronous callback was invoked. 131 * // indicate that the asynchronous callback was invoked.
132 * async.complete(); 132 * async.complete();
133 * }), 0); 133 * }), 0);
134 * }); 134 * });
135 * 135 *
136 */ 136 */
137 #library('unittest'); 137 #library('unittest');
138 138
139 #import('dart:isolate'); 139 #import('dart:isolate');
140 140
141 #source('collection_matchers.dart'); 141 #source('src/collection_matchers.dart');
142 #source('config.dart'); 142 #source('src/config.dart');
143 #source('core_matchers.dart'); 143 #source('src/core_matchers.dart');
144 #source('description.dart'); 144 #source('src/description.dart');
145 #source('expect.dart'); 145 #source('src/expect.dart');
146 #source('future_matchers.dart'); 146 #source('src/future_matchers.dart');
147 #source('interfaces.dart'); 147 #source('src/interfaces.dart');
148 #source('map_matchers.dart'); 148 #source('src/map_matchers.dart');
149 #source('matcher.dart'); 149 #source('src/matcher.dart');
150 #source('mock.dart'); 150 #source('src/mock.dart');
151 #source('numeric_matchers.dart'); 151 #source('src/numeric_matchers.dart');
152 #source('operator_matchers.dart'); 152 #source('src/operator_matchers.dart');
153 #source('string_matchers.dart'); 153 #source('src/string_matchers.dart');
154 #source('test_case.dart'); 154 #source('src/test_case.dart');
155 155
156 /** [Configuration] used by the unittest library. */ 156 /** [Configuration] used by the unittest library. */
157 Configuration _config = null; 157 Configuration _config = null;
158 158
159 Configuration get config => _config; 159 Configuration get config => _config;
160 160
161 /** 161 /**
162 * Set the [Configuration] used by the unittest library. Returns any 162 * Set the [Configuration] used by the unittest library. Returns any
163 * previous configuration. 163 * previous configuration.
164 * TODO: consider deprecating in favor of a setter now we have a getter. 164 * TODO: consider deprecating in favor of a setter now we have a getter.
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 865 }
866 866
867 /** Enable a test by ID. */ 867 /** Enable a test by ID. */
868 void enableTest(int testId) => _setTestEnabledState(testId, true); 868 void enableTest(int testId) => _setTestEnabledState(testId, true);
869 869
870 /** Disable a test by ID. */ 870 /** Disable a test by ID. */
871 void disableTest(int testId) => _setTestEnabledState(testId, false); 871 void disableTest(int testId) => _setTestEnabledState(testId, false);
872 872
873 /** Signature for a test function. */ 873 /** Signature for a test function. */
874 typedef void TestFunction(); 874 typedef void TestFunction();
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | pkg/unittest/lib/vm_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698