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'; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 group(".loadFile()", () { | 47 group(".loadFile()", () { |
48 var suite; | 48 var suite; |
49 setUp(() async { | 49 setUp(() async { |
50 /// TODO(nweiz): Use scheduled_test for this once it's compatible with | 50 /// TODO(nweiz): Use scheduled_test for this once it's compatible with |
51 /// this version of test. | 51 /// this version of test. |
52 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); | 52 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); |
53 var suites = await _loader.loadFile(p.join(_sandbox, 'a_test.dart')) | 53 var suites = await _loader.loadFile(p.join(_sandbox, 'a_test.dart')) |
54 .toList(); | 54 .toList(); |
55 expect(suites, hasLength(1)); | 55 expect(suites, hasLength(1)); |
56 suite = suites.first; | 56 var loadSuite = suites.first; |
| 57 suite = await loadSuite.getSuite(); |
57 }); | 58 }); |
58 | 59 |
59 test("returns a suite with the file path and platform", () { | 60 test("returns a suite with the file path and platform", () { |
60 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); | 61 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); |
61 expect(suite.platform, equals('VM')); | 62 expect(suite.platform, equals('VM')); |
62 }); | 63 }); |
63 | 64 |
64 test("returns tests with the correct names and platforms", () { | 65 test("returns tests with the correct names and platforms", () { |
65 expect(suite.tests, hasLength(3)); | 66 expect(suite.tests, hasLength(3)); |
66 expect(suite.tests[0].name, equals("success")); | 67 expect(suite.tests[0].name, equals("success")); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 setUp(() async { | 118 setUp(() async { |
118 /// TODO(nweiz): Use scheduled_test for this once it's compatible with | 119 /// TODO(nweiz): Use scheduled_test for this once it's compatible with |
119 /// this version of test. | 120 /// this version of test. |
120 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); | 121 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); |
121 new File(p.join(_sandbox, 'another_test.dart')) | 122 new File(p.join(_sandbox, 'another_test.dart')) |
122 .writeAsStringSync(_tests); | 123 .writeAsStringSync(_tests); |
123 new Directory(p.join(_sandbox, 'dir')).createSync(); | 124 new Directory(p.join(_sandbox, 'dir')).createSync(); |
124 new File(p.join(_sandbox, 'dir/sub_test.dart')) | 125 new File(p.join(_sandbox, 'dir/sub_test.dart')) |
125 .writeAsStringSync(_tests); | 126 .writeAsStringSync(_tests); |
126 | 127 |
127 suites = await _loader.loadDir(_sandbox).toList(); | 128 suites = await _loader.loadDir(_sandbox) |
| 129 .asyncMap((loadSuite) => loadSuite.getSuite()) |
| 130 .toList(); |
128 }); | 131 }); |
129 | 132 |
130 test("gives those suites the correct paths", () { | 133 test("gives those suites the correct paths", () { |
131 expect(suites.map((suite) => suite.path), unorderedEquals([ | 134 expect(suites.map((suite) => suite.path), unorderedEquals([ |
132 p.join(_sandbox, 'a_test.dart'), | 135 p.join(_sandbox, 'a_test.dart'), |
133 p.join(_sandbox, 'another_test.dart'), | 136 p.join(_sandbox, 'another_test.dart'), |
134 p.join(_sandbox, 'dir', 'sub_test.dart') | 137 p.join(_sandbox, 'dir', 'sub_test.dart') |
135 ])); | 138 ])); |
136 }); | 139 }); |
137 | 140 |
138 test("can run tests in those suites", () { | 141 test("can run tests in those suites", () { |
139 var suite = suites.firstWhere((suite) => suite.path.contains("a_test")); | 142 var suite = suites.firstWhere((suite) => suite.path.contains("a_test")); |
140 var liveTest = suite.tests[1].load(suite); | 143 var liveTest = suite.tests[1].load(suite); |
141 expectSingleFailure(liveTest); | 144 expectSingleFailure(liveTest); |
142 return liveTest.run().whenComplete(() => liveTest.close()); | 145 return liveTest.run().whenComplete(() => liveTest.close()); |
143 }); | 146 }); |
144 }); | 147 }); |
145 }); | 148 }); |
| 149 |
| 150 test("a print in a loaded file is piped through the LoadSuite", () async { |
| 151 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(""" |
| 152 void main() { |
| 153 print('print within test'); |
146 } | 154 } |
| 155 """); |
| 156 var suites = await _loader.loadFile(p.join(_sandbox, 'a_test.dart')) |
| 157 .toList(); |
| 158 expect(suites, hasLength(1)); |
| 159 var loadSuite = suites.first; |
| 160 |
| 161 var liveTest = await loadSuite.tests.single.load(loadSuite); |
| 162 expect(liveTest.onPrint.first, completion(equals("print within test"))); |
| 163 await liveTest.run(); |
| 164 expectTestPassed(liveTest); |
| 165 }); |
| 166 |
| 167 // TODO: Test load suites. Don't forget to test that prints in loaded files |
| 168 // are piped through the suite. Also for browser tests! |
| 169 } |
OLD | NEW |