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

Side by Side Diff: test/runner_test.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: Code review changes 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
« no previous file with comments | « test/returning_future_using_runasync_test.dart ('k') | test/runtests_without_tests_test.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) 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 import 'dart:io'; 5 import 'dart:io';
6 6
7 import 'package:path/path.dart' as p; 7 import 'package:path/path.dart' as p;
8 import 'package:unittest/src/exit_codes.dart' as exit_codes; 8 import 'package:unittest/src/exit_codes.dart' as exit_codes;
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
11 import 'io.dart'; 11 import 'io.dart';
12 12
13 String _sandbox; 13 String _sandbox;
14 14
15 final _success = """ 15 final _success = """
16 import 'dart:async'; 16 import 'dart:async';
17 17
18 import 'package:unittest/unittest.dart';
19
18 void main() { 20 void main() {
19 var declarer = Zone.current[#unittest.declarer]; 21 test("success", () {});
20 declarer.test("success", () {});
21 } 22 }
22 """; 23 """;
23 24
24 final _failure = """ 25 final _failure = """
25 import 'dart:async'; 26 import 'dart:async';
26 27
27 import 'package:unittest/unittest.dart'; 28 import 'package:unittest/unittest.dart';
28 29
29 void main() { 30 void main() {
30 var declarer = Zone.current[#unittest.declarer]; 31 test("failure", () => throw new TestFailure("oh no"));
31 declarer.test("failure", () => throw new TestFailure("oh no"));
32 } 32 }
33 """; 33 """;
34 34
35 void main() { 35 void main() {
36 setUp(() { 36 setUp(() {
37 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; 37 _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
38 }); 38 });
39 39
40 tearDown(() { 40 tearDown(() {
41 new Directory(_sandbox).deleteSync(recursive: true); 41 new Directory(_sandbox).deleteSync(recursive: true);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 test("defaulting to the test directory", () { 160 test("defaulting to the test directory", () {
161 new Directory(p.join(_sandbox, "test")).createSync(); 161 new Directory(p.join(_sandbox, "test")).createSync();
162 for (var i = 0; i < 3; i++) { 162 for (var i = 0; i < 3; i++) {
163 new File(p.join(_sandbox, "test", "${i}_test.dart")) 163 new File(p.join(_sandbox, "test", "${i}_test.dart"))
164 .writeAsStringSync(_success); 164 .writeAsStringSync(_success);
165 } 165 }
166 166
167 var result = _runUnittest([]); 167 var result = _runUnittest([]);
168 expect(result.exitCode, equals(0)); 168 expect(result.exitCode, equals(0));
169 }); 169 });
170
171 test("directly", () {
172 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
173 var result = _runDart([
174 "--package-root=${p.join(packageDir, 'packages')}",
175 "test.dart"
176 ]);
177 expect(result.stdout, contains("All tests passed!"));
178 });
170 }); 179 });
171 180
172 group("runs failing tests", () { 181 group("runs failing tests", () {
173 test("defined in a single file", () { 182 test("defined in a single file", () {
174 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 183 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
175 var result = _runUnittest(["test.dart"]); 184 var result = _runUnittest(["test.dart"]);
176 expect(result.exitCode, equals(1)); 185 expect(result.exitCode, equals(1));
177 }); 186 });
178 187
179 test("defined in a directory", () { 188 test("defined in a directory", () {
180 for (var i = 0; i < 3; i++) { 189 for (var i = 0; i < 3; i++) {
181 new File(p.join(_sandbox, "${i}_test.dart")) 190 new File(p.join(_sandbox, "${i}_test.dart"))
182 .writeAsStringSync(_failure); 191 .writeAsStringSync(_failure);
183 } 192 }
184 193
185 var result = _runUnittest(["."]); 194 var result = _runUnittest(["."]);
186 expect(result.exitCode, equals(1)); 195 expect(result.exitCode, equals(1));
187 }); 196 });
188 197
189 test("defaulting to the test directory", () { 198 test("defaulting to the test directory", () {
190 new Directory(p.join(_sandbox, "test")).createSync(); 199 new Directory(p.join(_sandbox, "test")).createSync();
191 for (var i = 0; i < 3; i++) { 200 for (var i = 0; i < 3; i++) {
192 new File(p.join(_sandbox, "test", "${i}_test.dart")) 201 new File(p.join(_sandbox, "test", "${i}_test.dart"))
193 .writeAsStringSync(_failure); 202 .writeAsStringSync(_failure);
194 } 203 }
195 204
196 var result = _runUnittest([]); 205 var result = _runUnittest([]);
197 expect(result.exitCode, equals(1)); 206 expect(result.exitCode, equals(1));
198 }); 207 });
208
209 test("directly", () {
210 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
211 var result = _runDart([
212 "--package-root=${p.join(packageDir, 'packages')}",
213 "test.dart"
214 ]);
215 expect(result.stdout, contains("Some tests failed."));
216 });
199 }); 217 });
200 } 218 }
201 219
202 ProcessResult _runUnittest(List<String> args) => 220 ProcessResult _runUnittest(List<String> args) =>
203 runUnittest(args, workingDirectory: _sandbox); 221 runUnittest(args, workingDirectory: _sandbox);
222
223 ProcessResult _runDart(List<String> args) =>
224 runDart(args, workingDirectory: _sandbox);
OLDNEW
« no previous file with comments | « test/returning_future_using_runasync_test.dart ('k') | test/runtests_without_tests_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698