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 36 matching lines...) Loading... |
47 return _loader.close(); | 47 return _loader.close(); |
48 }); | 48 }); |
49 | 49 |
50 group(".loadFile()", () { | 50 group(".loadFile()", () { |
51 var suite; | 51 var suite; |
52 setUp(() async { | 52 setUp(() async { |
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 | 55 |
56 expect(suites, hasLength(1)); | 56 expect(suites, hasLength(1)); |
57 suite = suites.first; | 57 var loadSuite = suites.first; |
| 58 suite = await loadSuite.getSuite(); |
58 }); | 59 }); |
59 | 60 |
60 test("returns a suite with the file path and platform", () { | 61 test("returns a suite with the file path and platform", () { |
61 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); | 62 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); |
62 expect(suite.platform, equals('Chrome')); | 63 expect(suite.platform, equals('Chrome')); |
63 }); | 64 }); |
64 | 65 |
65 test("returns tests with the correct names", () { | 66 test("returns tests with the correct names", () { |
66 expect(suite.tests, hasLength(3)); | 67 expect(suite.tests, hasLength(3)); |
67 expect(suite.tests[0].name, equals("success")); | 68 expect(suite.tests[0].name, equals("success")); |
(...skipping 38 matching lines...) Loading... |
106 test("error", () => throw 'oh no'); | 107 test("error", () => throw 'oh no'); |
107 }); | 108 }); |
108 }); | 109 }); |
109 }); | 110 }); |
110 } | 111 } |
111 """); | 112 """); |
112 | 113 |
113 var suites = await _loader.loadFile(p.join(_sandbox, 'a_test.dart')) | 114 var suites = await _loader.loadFile(p.join(_sandbox, 'a_test.dart')) |
114 .toList(); | 115 .toList(); |
115 expect(suites, hasLength(1)); | 116 expect(suites, hasLength(1)); |
116 var suite = suites.first; | 117 var loadSuite = suites.first; |
| 118 var suite = await loadSuite.getSuite(); |
117 expect(suite.tests, hasLength(3)); | 119 expect(suite.tests, hasLength(3)); |
118 expect(suite.tests[0].name, equals("success")); | 120 expect(suite.tests[0].name, equals("success")); |
119 expect(suite.tests[1].name, equals("failure")); | 121 expect(suite.tests[1].name, equals("failure")); |
120 expect(suite.tests[2].name, equals("error")); | 122 expect(suite.tests[2].name, equals("error")); |
121 }); | 123 }); |
122 | 124 |
123 test("loads a suite both in the browser and the VM", () async { | 125 test("loads a suite both in the browser and the VM", () async { |
124 var loader = new Loader([TestPlatform.vm, TestPlatform.chrome], | 126 var loader = new Loader([TestPlatform.vm, TestPlatform.chrome], |
125 root: _sandbox, | 127 root: _sandbox, |
126 packageRoot: p.join(packageDir, 'packages')); | 128 packageRoot: p.join(packageDir, 'packages')); |
127 var path = p.join(_sandbox, 'a_test.dart'); | 129 var path = p.join(_sandbox, 'a_test.dart'); |
128 | 130 |
129 try { | 131 try { |
130 var suites = await loader.loadFile(path).toList(); | 132 var suites = await loader.loadFile(path) |
| 133 .asyncMap((loadSuite) => loadSuite.getSuite()).toList(); |
131 expect(suites[0].platform, equals('VM')); | 134 expect(suites[0].platform, equals('VM')); |
132 expect(suites[0].path, equals(path)); | 135 expect(suites[0].path, equals(path)); |
133 expect(suites[1].platform, equals('Chrome')); | 136 expect(suites[1].platform, equals('Chrome')); |
134 expect(suites[1].path, equals(path)); | 137 expect(suites[1].path, equals(path)); |
135 | 138 |
136 for (var suite in suites) { | 139 for (var suite in suites) { |
137 expect(suite.tests, hasLength(3)); | 140 expect(suite.tests, hasLength(3)); |
138 expect(suite.tests[0].name, equals("success")); | 141 expect(suite.tests[0].name, equals("success")); |
139 expect(suite.tests[1].name, equals("failure")); | 142 expect(suite.tests[1].name, equals("failure")); |
140 expect(suite.tests[2].name, equals("error")); | 143 expect(suite.tests[2].name, equals("error")); |
141 } | 144 } |
142 } finally { | 145 } finally { |
143 await loader.close(); | 146 await loader.close(); |
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 } |
OLD | NEW |