| OLD | NEW |
| 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 library unittest.loader; | |
| 6 | |
| 7 import 'dart:io'; | 5 import 'dart:io'; |
| 8 | 6 |
| 9 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
| 10 import 'package:unittest/src/loader.dart'; | 8 import 'package:unittest/src/loader.dart'; |
| 11 import 'package:unittest/src/state.dart'; | 9 import 'package:unittest/src/state.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 13 | 11 |
| 14 import 'io.dart'; | 12 import 'io.dart'; |
| 15 import 'utils.dart'; | 13 import 'utils.dart'; |
| 16 | 14 |
| 17 Loader _loader; | 15 Loader _loader; |
| 18 String _sandbox; | 16 String _sandbox; |
| 19 | 17 |
| 20 final _tests = """ | 18 final _tests = """ |
| 21 import 'dart:async'; | 19 import 'dart:async'; |
| 22 | 20 |
| 23 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 24 | 22 |
| 25 void main() { | 23 void main() { |
| 26 var declarer = Zone.current[#unittest.declarer]; | 24 test("success", () {}); |
| 27 declarer.test("success", () {}); | 25 test("failure", () => throw new TestFailure('oh no')); |
| 28 declarer.test("failure", () => throw new TestFailure('oh no')); | 26 test("error", () => throw 'oh no'); |
| 29 declarer.test("error", () => throw 'oh no'); | |
| 30 } | 27 } |
| 31 """; | 28 """; |
| 32 | 29 |
| 33 void main() { | 30 void main() { |
| 34 setUp(() { | 31 setUp(() { |
| 35 _loader = new Loader(packageRoot: p.join(packageDir, 'packages')); | 32 _loader = new Loader(packageRoot: p.join(packageDir, 'packages')); |
| 36 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; | 33 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; |
| 37 }); | 34 }); |
| 38 | 35 |
| 39 tearDown(() { | 36 tearDown(() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 73 |
| 77 test("can load and run a failing test", () { | 74 test("can load and run a failing test", () { |
| 78 var liveTest = suite.tests[1].load(suite); | 75 var liveTest = suite.tests[1].load(suite); |
| 79 expectSingleFailure(liveTest); | 76 expectSingleFailure(liveTest); |
| 80 return liveTest.run().whenComplete(() => liveTest.close()); | 77 return liveTest.run().whenComplete(() => liveTest.close()); |
| 81 }); | 78 }); |
| 82 | 79 |
| 83 test("throws a nice error if the package root doesn't exist", () { | 80 test("throws a nice error if the package root doesn't exist", () { |
| 84 var loader = new Loader(); | 81 var loader = new Loader(); |
| 85 expect(() => loader.loadFile(p.join(_sandbox, 'a_test.dart')), | 82 expect(() => loader.loadFile(p.join(_sandbox, 'a_test.dart')), |
| 86 throwsA(isFileSystemException( | 83 throwsA(isLoadException( |
| 87 "Directory ${p.join(_sandbox, 'packages')} does not exist."))); | 84 "Directory ${p.join(_sandbox, 'packages')} does not exist."))); |
| 88 }); | 85 }); |
| 89 }); | 86 }); |
| 90 | 87 |
| 91 group(".loadDir()", () { | 88 group(".loadDir()", () { |
| 92 test("ignores non-Dart files", () { | 89 test("ignores non-Dart files", () { |
| 93 new File(p.join(_sandbox, 'a_test.txt')).writeAsStringSync(_tests); | 90 new File(p.join(_sandbox, 'a_test.txt')).writeAsStringSync(_tests); |
| 94 expect(_loader.loadDir(_sandbox), completion(isEmpty)); | 91 expect(_loader.loadDir(_sandbox), completion(isEmpty)); |
| 95 }); | 92 }); |
| 96 | 93 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 128 |
| 132 test("can run tests in those suites", () { | 129 test("can run tests in those suites", () { |
| 133 var suite = suites.firstWhere((suite) => suite.name.contains("a_test")); | 130 var suite = suites.firstWhere((suite) => suite.name.contains("a_test")); |
| 134 var liveTest = suite.tests[1].load(suite); | 131 var liveTest = suite.tests[1].load(suite); |
| 135 expectSingleFailure(liveTest); | 132 expectSingleFailure(liveTest); |
| 136 return liveTest.run().whenComplete(() => liveTest.close()); | 133 return liveTest.run().whenComplete(() => liveTest.close()); |
| 137 }); | 134 }); |
| 138 }); | 135 }); |
| 139 }); | 136 }); |
| 140 } | 137 } |
| OLD | NEW |