| 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:unittest/src/backend/state.dart'; | 10 import 'package:test/src/backend/state.dart'; |
| 11 import 'package:unittest/src/backend/test_platform.dart'; | 11 import 'package:test/src/backend/test_platform.dart'; |
| 12 import 'package:unittest/src/runner/loader.dart'; | 12 import 'package:test/src/runner/loader.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:test/test.dart'; |
| 14 | 14 |
| 15 import '../io.dart'; | 15 import '../io.dart'; |
| 16 import '../utils.dart'; | 16 import '../utils.dart'; |
| 17 | 17 |
| 18 Loader _loader; | 18 Loader _loader; |
| 19 String _sandbox; | 19 String _sandbox; |
| 20 | 20 |
| 21 final _tests = """ | 21 final _tests = """ |
| 22 import 'dart:async'; | 22 import 'dart:async'; |
| 23 | 23 |
| 24 import 'package:unittest/unittest.dart'; | 24 import 'package:test/test.dart'; |
| 25 | 25 |
| 26 void main() { | 26 void main() { |
| 27 test("success", () {}); | 27 test("success", () {}); |
| 28 test("failure", () => throw new TestFailure('oh no')); | 28 test("failure", () => throw new TestFailure('oh no')); |
| 29 test("error", () => throw 'oh no'); | 29 test("error", () => throw 'oh no'); |
| 30 } | 30 } |
| 31 """; | 31 """; |
| 32 | 32 |
| 33 void main() { | 33 void main() { |
| 34 setUp(() { | 34 setUp(() { |
| 35 _loader = new Loader([TestPlatform.vm], | 35 _loader = new Loader([TestPlatform.vm], |
| 36 packageRoot: p.join(packageDir, 'packages')); | 36 packageRoot: p.join(packageDir, 'packages')); |
| 37 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; | 37 _sandbox = Directory.systemTemp.createTempSync('test_').path; |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 tearDown(() { | 40 tearDown(() { |
| 41 new Directory(_sandbox).deleteSync(recursive: true); | 41 new Directory(_sandbox).deleteSync(recursive: true); |
| 42 return _loader.close(); | 42 return _loader.close(); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 group(".loadFile()", () { | 45 group(".loadFile()", () { |
| 46 var suite; | 46 var suite; |
| 47 setUp(() { | 47 setUp(() { |
| 48 /// TODO(nweiz): Use scheduled_test for this once it's compatible with | 48 /// TODO(nweiz): Use scheduled_test for this once it's compatible with |
| 49 /// this version of unittest. | 49 /// this version of test. |
| 50 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); | 50 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); |
| 51 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')).then((suites) { | 51 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')).then((suites) { |
| 52 expect(suites, hasLength(1)); | 52 expect(suites, hasLength(1)); |
| 53 suite = suites.first; | 53 suite = suites.first; |
| 54 }); | 54 }); |
| 55 }); | 55 }); |
| 56 | 56 |
| 57 test("returns a suite with the file path and platform", () { | 57 test("returns a suite with the file path and platform", () { |
| 58 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); | 58 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); |
| 59 expect(suite.platform, equals('VM')); | 59 expect(suite.platform, equals('VM')); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 test("ignores files that don't end in _test.dart", () { | 110 test("ignores files that don't end in _test.dart", () { |
| 111 new File(p.join(_sandbox, 'test.dart')).writeAsStringSync(_tests); | 111 new File(p.join(_sandbox, 'test.dart')).writeAsStringSync(_tests); |
| 112 expect(_loader.loadDir(_sandbox), completion(isEmpty)); | 112 expect(_loader.loadDir(_sandbox), completion(isEmpty)); |
| 113 }); | 113 }); |
| 114 | 114 |
| 115 group("with suites loaded from a directory", () { | 115 group("with suites loaded from a directory", () { |
| 116 var suites; | 116 var suites; |
| 117 setUp(() { | 117 setUp(() { |
| 118 /// TODO(nweiz): Use scheduled_test for this once it's compatible with | 118 /// TODO(nweiz): Use scheduled_test for this once it's compatible with |
| 119 /// this version of unittest. | 119 /// this version of test. |
| 120 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); | 120 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); |
| 121 new File(p.join(_sandbox, 'another_test.dart')) | 121 new File(p.join(_sandbox, 'another_test.dart')) |
| 122 .writeAsStringSync(_tests); | 122 .writeAsStringSync(_tests); |
| 123 new Directory(p.join(_sandbox, 'dir')).createSync(); | 123 new Directory(p.join(_sandbox, 'dir')).createSync(); |
| 124 new File(p.join(_sandbox, 'dir/sub_test.dart')) | 124 new File(p.join(_sandbox, 'dir/sub_test.dart')) |
| 125 .writeAsStringSync(_tests); | 125 .writeAsStringSync(_tests); |
| 126 | 126 |
| 127 return _loader.loadDir(_sandbox).then((suites_) => suites = suites_); | 127 return _loader.loadDir(_sandbox).then((suites_) => suites = suites_); |
| 128 }); | 128 }); |
| 129 | 129 |
| 130 test("gives those suites the correct paths", () { | 130 test("gives those suites the correct paths", () { |
| 131 expect(suites.map((suite) => suite.path), unorderedEquals([ | 131 expect(suites.map((suite) => suite.path), unorderedEquals([ |
| 132 p.join(_sandbox, 'a_test.dart'), | 132 p.join(_sandbox, 'a_test.dart'), |
| 133 p.join(_sandbox, 'another_test.dart'), | 133 p.join(_sandbox, 'another_test.dart'), |
| 134 p.join(_sandbox, 'dir/sub_test.dart') | 134 p.join(_sandbox, 'dir/sub_test.dart') |
| 135 ])); | 135 ])); |
| 136 }); | 136 }); |
| 137 | 137 |
| 138 test("can run tests in those suites", () { | 138 test("can run tests in those suites", () { |
| 139 var suite = suites.firstWhere((suite) => suite.path.contains("a_test")); | 139 var suite = suites.firstWhere((suite) => suite.path.contains("a_test")); |
| 140 var liveTest = suite.tests[1].load(suite); | 140 var liveTest = suite.tests[1].load(suite); |
| 141 expectSingleFailure(liveTest); | 141 expectSingleFailure(liveTest); |
| 142 return liveTest.run().whenComplete(() => liveTest.close()); | 142 return liveTest.run().whenComplete(() => liveTest.close()); |
| 143 }); | 143 }); |
| 144 }); | 144 }); |
| 145 }); | 145 }); |
| 146 } | 146 } |
| OLD | NEW |