OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 scheduled_process_test; | 5 library scheduled_process_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 test('test 1', () { | 56 test('test 1', () { |
57 currentSchedule.onException.schedule(() { | 57 currentSchedule.onException.schedule(() { |
58 errors = currentSchedule.errors; | 58 errors = currentSchedule.errors; |
59 }); | 59 }); |
60 | 60 |
61 var process = startDartProcess('exitCode = 1;'); | 61 var process = startDartProcess('exitCode = 1;'); |
62 process.shouldExit(0); | 62 process.shouldExit(0); |
63 }); | 63 }); |
64 | 64 |
65 test('test 2', () { | 65 test('test 2', () { |
66 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 66 expect(errors.single, new isInstanceOf<ScheduleError>()); |
67 expect(errors.length, equals(1)); | |
68 expect(errors.first.error, new isInstanceOf<TestFailure>()); | |
69 }); | 67 }); |
70 }, passing: ['test 2']); | 68 }, passing: ['test 2']); |
71 | 69 |
72 expectTestsPass("a killed process doesn't care about its exit code", () { | 70 expectTestsPass("a killed process doesn't care about its exit code", () { |
73 test('exit code 0', () { | 71 test('exit code 0', () { |
74 var process = startDartProcess('exitCode = 0;'); | 72 var process = startDartProcess('exitCode = 0;'); |
75 process.kill(); | 73 process.kill(); |
76 }); | 74 }); |
77 | 75 |
78 test('exit code 1', () { | 76 test('exit code 1', () { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 134 |
137 test('test 2', () { | 135 test('test 2', () { |
138 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 136 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
139 expect(errors.length, anyOf(1, 2)); | 137 expect(errors.length, anyOf(1, 2)); |
140 expect(errors[0].error, isStateError); | 138 expect(errors[0].error, isStateError); |
141 expect(errors[0].error.message, equals("No elements")); | 139 expect(errors[0].error.message, equals("No elements")); |
142 | 140 |
143 // Whether or not this error appears depends on how quickly the "no | 141 // Whether or not this error appears depends on how quickly the "no |
144 // elements" error is handled. | 142 // elements" error is handled. |
145 if (errors.length == 2) { | 143 if (errors.length == 2) { |
146 expect(errors[1].error, matches(r"^Process " | 144 expect(errors[1].error.toString(), matches(r"^Process " |
147 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " | 145 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " |
148 r"exit code 0\.")); | 146 r"exit code 0\.")); |
149 } | 147 } |
150 }); | 148 }); |
151 }, passing: ['test 2']); | 149 }, passing: ['test 2']); |
152 | 150 |
153 expectTestsPass("a process that ends during the task immediately before it's " | 151 expectTestsPass("a process that ends during the task immediately before it's " |
154 "scheduled to end shouldn't cause an error", () { | 152 "scheduled to end shouldn't cause an error", () { |
155 test('test', () { | 153 test('test', () { |
156 var process = startDartProcess('stdin.toList();'); | 154 var process = startDartProcess('stdin.toList();'); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 187 |
190 test('test 2', () { | 188 test('test 2', () { |
191 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 189 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
192 expect(errors.length, anyOf(1, 2)); | 190 expect(errors.length, anyOf(1, 2)); |
193 expect(errors[0].error, isStateError); | 191 expect(errors[0].error, isStateError); |
194 expect(errors[0].error.message, equals("No elements")); | 192 expect(errors[0].error.message, equals("No elements")); |
195 | 193 |
196 // Whether or not this error appears depends on how quickly the "no | 194 // Whether or not this error appears depends on how quickly the "no |
197 // elements" error is handled. | 195 // elements" error is handled. |
198 if (errors.length == 2) { | 196 if (errors.length == 2) { |
199 expect(errors[1].error, matches(r"^Process " | 197 expect(errors[1].error.toString(), matches(r"^Process " |
200 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " | 198 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " |
201 r"exit code 0\.")); | 199 r"exit code 0\.")); |
202 } | 200 } |
203 }); | 201 }); |
204 }, passing: ['test 2']); | 202 }, passing: ['test 2']); |
205 | 203 |
206 expectTestsPass("nextErrLine returns the next line of stderr from the " | 204 expectTestsPass("nextErrLine returns the next line of stderr from the " |
207 "process", () { | 205 "process", () { |
208 test('test', () { | 206 test('test', () { |
209 var process = startDartProcess(r''' | 207 var process = startDartProcess(r''' |
(...skipping 23 matching lines...) Expand all Loading... |
233 | 231 |
234 test('test 2', () { | 232 test('test 2', () { |
235 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 233 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
236 expect(errors.length, anyOf(1, 2)); | 234 expect(errors.length, anyOf(1, 2)); |
237 expect(errors[0].error, isStateError); | 235 expect(errors[0].error, isStateError); |
238 expect(errors[0].error.message, equals("No elements")); | 236 expect(errors[0].error.message, equals("No elements")); |
239 | 237 |
240 // Whether or not this error appears depends on how quickly the "no | 238 // Whether or not this error appears depends on how quickly the "no |
241 // elements" error is handled. | 239 // elements" error is handled. |
242 if (errors.length == 2) { | 240 if (errors.length == 2) { |
243 expect(errors[1].error, matches(r"^Process " | 241 expect(errors[1].error.toString(), matches(r"^Process " |
244 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " | 242 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " |
245 r"exit code 0\.")); | 243 r"exit code 0\.")); |
246 } | 244 } |
247 }); | 245 }); |
248 }, passing: ['test 2']); | 246 }, passing: ['test 2']); |
249 | 247 |
250 expectTestsPass("remainingStdout returns all the stdout if it's not consumed " | 248 expectTestsPass("remainingStdout returns all the stdout if it's not consumed " |
251 "any other way", () { | 249 "any other way", () { |
252 test('test', () { | 250 test('test', () { |
253 var process = startDartProcess(r'print("hello\n\nworld"); print("hi");'); | 251 var process = startDartProcess(r'print("hello\n\nworld"); print("hi");'); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 382 |
385 currentSchedule.onComplete.schedule(() { | 383 currentSchedule.onComplete.schedule(() { |
386 return tempDir.catchError((_) => null).then((dir) { | 384 return tempDir.catchError((_) => null).then((dir) { |
387 if (dir == null) return; | 385 if (dir == null) return; |
388 return new Directory(dir).delete(recursive: true); | 386 return new Directory(dir).delete(recursive: true); |
389 }); | 387 }); |
390 }, 'clean up temp dir'); | 388 }, 'clean up temp dir'); |
391 | 389 |
392 return new ScheduledProcess.start(dartExecutable, ['--checked', dartPath]); | 390 return new ScheduledProcess.start(dartExecutable, ['--checked', dartPath]); |
393 } | 391 } |
OLD | NEW |