| 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 @TestOn("vm") | 5 @TestOn("vm") |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:test/src/backend/state.dart'; | 10 import 'package:test/src/backend/state.dart'; |
| 11 import 'package:test/src/backend/test_platform.dart'; | 11 import 'package:test/src/backend/test_platform.dart'; |
| 12 import 'package:test/src/runner/configuration.dart'; |
| 12 import 'package:test/src/runner/loader.dart'; | 13 import 'package:test/src/runner/loader.dart'; |
| 13 import 'package:test/src/util/io.dart'; | 14 import 'package:test/src/util/io.dart'; |
| 14 import 'package:test/test.dart'; | 15 import 'package:test/test.dart'; |
| 15 | 16 |
| 16 import '../io.dart'; | 17 import '../io.dart'; |
| 17 import '../utils.dart'; | 18 import '../utils.dart'; |
| 18 | 19 |
| 19 Loader _loader; | 20 Loader _loader; |
| 20 String _sandbox; | 21 String _sandbox; |
| 21 | 22 |
| 22 final _tests = """ | 23 final _tests = """ |
| 23 import 'dart:async'; | 24 import 'dart:async'; |
| 24 | 25 |
| 25 import 'package:test/test.dart'; | 26 import 'package:test/test.dart'; |
| 26 | 27 |
| 27 void main() { | 28 void main() { |
| 28 test("success", () {}); | 29 test("success", () {}); |
| 29 test("failure", () => throw new TestFailure('oh no')); | 30 test("failure", () => throw new TestFailure('oh no')); |
| 30 test("error", () => throw 'oh no'); | 31 test("error", () => throw 'oh no'); |
| 31 } | 32 } |
| 32 """; | 33 """; |
| 33 | 34 |
| 34 void main() { | 35 void main() { |
| 35 setUp(() { | 36 setUp(() { |
| 36 _sandbox = createTempDir(); | 37 _sandbox = createTempDir(); |
| 37 _loader = new Loader([TestPlatform.vm], | 38 _loader = new Loader( |
| 38 root: _sandbox, | 39 new Configuration(packageRoot: p.join(packageDir, 'packages')), |
| 39 packageRoot: p.join(packageDir, 'packages')); | 40 root: _sandbox); |
| 40 }); | 41 }); |
| 41 | 42 |
| 42 tearDown(() { | 43 tearDown(() { |
| 43 new Directory(_sandbox).deleteSync(recursive: true); | 44 new Directory(_sandbox).deleteSync(recursive: true); |
| 44 return _loader.close(); | 45 return _loader.close(); |
| 45 }); | 46 }); |
| 46 | 47 |
| 47 group(".loadFile()", () { | 48 group(".loadFile()", () { |
| 48 var suite; | 49 var suite; |
| 49 setUp(() async { | 50 setUp(() async { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 79 expectErrors(liveTest, []); | 80 expectErrors(liveTest, []); |
| 80 | 81 |
| 81 return liveTest.run().whenComplete(() => liveTest.close()); | 82 return liveTest.run().whenComplete(() => liveTest.close()); |
| 82 }); | 83 }); |
| 83 | 84 |
| 84 test("can load and run a failing test", () { | 85 test("can load and run a failing test", () { |
| 85 var liveTest = suite.tests[1].load(suite); | 86 var liveTest = suite.tests[1].load(suite); |
| 86 expectSingleFailure(liveTest); | 87 expectSingleFailure(liveTest); |
| 87 return liveTest.run().whenComplete(() => liveTest.close()); | 88 return liveTest.run().whenComplete(() => liveTest.close()); |
| 88 }); | 89 }); |
| 89 | |
| 90 test("throws a nice error if the package root doesn't exist", () { | |
| 91 expect(() => new Loader([TestPlatform.chrome], root: _sandbox), | |
| 92 throwsA(isApplicationException( | |
| 93 "Directory ${p.prettyUri(p.toUri(p.join(_sandbox, 'packages')))} " | |
| 94 "does not exist."))); | |
| 95 }); | |
| 96 }); | 90 }); |
| 97 | 91 |
| 98 group(".loadDir()", () { | 92 group(".loadDir()", () { |
| 99 test("ignores non-Dart files", () { | 93 test("ignores non-Dart files", () { |
| 100 new File(p.join(_sandbox, 'a_test.txt')).writeAsStringSync(_tests); | 94 new File(p.join(_sandbox, 'a_test.txt')).writeAsStringSync(_tests); |
| 101 expect(_loader.loadDir(_sandbox).toList(), completion(isEmpty)); | 95 expect(_loader.loadDir(_sandbox).toList(), completion(isEmpty)); |
| 102 }); | 96 }); |
| 103 | 97 |
| 104 test("ignores files in packages/ directories", () { | 98 test("ignores files in packages/ directories", () { |
| 105 var dir = p.join(_sandbox, 'packages'); | 99 var dir = p.join(_sandbox, 'packages'); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 154 |
| 161 var liveTest = await loadSuite.tests.single.load(loadSuite); | 155 var liveTest = await loadSuite.tests.single.load(loadSuite); |
| 162 expect(liveTest.onPrint.first, completion(equals("print within test"))); | 156 expect(liveTest.onPrint.first, completion(equals("print within test"))); |
| 163 await liveTest.run(); | 157 await liveTest.run(); |
| 164 expectTestPassed(liveTest); | 158 expectTestPassed(liveTest); |
| 165 }); | 159 }); |
| 166 | 160 |
| 167 // TODO: Test load suites. Don't forget to test that prints in loaded files | 161 // TODO: Test load suites. Don't forget to test that prints in loaded files |
| 168 // are piped through the suite. Also for browser tests! | 162 // are piped through the suite. Also for browser tests! |
| 169 } | 163 } |
| OLD | NEW |