| 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 import 'package:test/src/backend/state.dart'; | 5 import 'package:test/src/backend/state.dart'; |
| 6 import 'package:test/test.dart'; | 6 import 'package:test/test.dart'; |
| 7 | 7 |
| 8 import '../utils.dart'; | 8 import '../utils.dart'; |
| 9 | 9 |
| 10 void main() { | 10 void main() { |
| 11 group("supports a function with this many arguments:", () { | 11 group("supports a function with this many arguments:", () { |
| 12 test("0", () { | 12 test("0", () { |
| 13 var callbackRun = false; | 13 var callbackRun = false; |
| 14 return runTest(() { | 14 return runTestBody(() { |
| 15 expectAsync(() { | 15 expectAsync(() { |
| 16 callbackRun = true; | 16 callbackRun = true; |
| 17 })(); | 17 })(); |
| 18 }).then((liveTest) { | 18 }).then((liveTest) { |
| 19 expectTestPassed(liveTest); | 19 expectTestPassed(liveTest); |
| 20 expect(callbackRun, isTrue); | 20 expect(callbackRun, isTrue); |
| 21 }); | 21 }); |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 test("1", () { | 24 test("1", () { |
| 25 var callbackRun = false; | 25 var callbackRun = false; |
| 26 return runTest(() { | 26 return runTestBody(() { |
| 27 expectAsync((arg) { | 27 expectAsync((arg) { |
| 28 expect(arg, equals(1)); | 28 expect(arg, equals(1)); |
| 29 callbackRun = true; | 29 callbackRun = true; |
| 30 })(1); | 30 })(1); |
| 31 }).then((liveTest) { | 31 }).then((liveTest) { |
| 32 expectTestPassed(liveTest); | 32 expectTestPassed(liveTest); |
| 33 expect(callbackRun, isTrue); | 33 expect(callbackRun, isTrue); |
| 34 }); | 34 }); |
| 35 }); | 35 }); |
| 36 | 36 |
| 37 test("2", () { | 37 test("2", () { |
| 38 var callbackRun = false; | 38 var callbackRun = false; |
| 39 return runTest(() { | 39 return runTestBody(() { |
| 40 expectAsync((arg1, arg2) { | 40 expectAsync((arg1, arg2) { |
| 41 expect(arg1, equals(1)); | 41 expect(arg1, equals(1)); |
| 42 expect(arg2, equals(2)); | 42 expect(arg2, equals(2)); |
| 43 callbackRun = true; | 43 callbackRun = true; |
| 44 })(1, 2); | 44 })(1, 2); |
| 45 }).then((liveTest) { | 45 }).then((liveTest) { |
| 46 expectTestPassed(liveTest); | 46 expectTestPassed(liveTest); |
| 47 expect(callbackRun, isTrue); | 47 expect(callbackRun, isTrue); |
| 48 }); | 48 }); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 test("3", () { | 51 test("3", () { |
| 52 var callbackRun = false; | 52 var callbackRun = false; |
| 53 return runTest(() { | 53 return runTestBody(() { |
| 54 expectAsync((arg1, arg2, arg3) { | 54 expectAsync((arg1, arg2, arg3) { |
| 55 expect(arg1, equals(1)); | 55 expect(arg1, equals(1)); |
| 56 expect(arg2, equals(2)); | 56 expect(arg2, equals(2)); |
| 57 expect(arg3, equals(3)); | 57 expect(arg3, equals(3)); |
| 58 callbackRun = true; | 58 callbackRun = true; |
| 59 })(1, 2, 3); | 59 })(1, 2, 3); |
| 60 }).then((liveTest) { | 60 }).then((liveTest) { |
| 61 expectTestPassed(liveTest); | 61 expectTestPassed(liveTest); |
| 62 expect(callbackRun, isTrue); | 62 expect(callbackRun, isTrue); |
| 63 }); | 63 }); |
| 64 }); | 64 }); |
| 65 | 65 |
| 66 test("4", () { | 66 test("4", () { |
| 67 var callbackRun = false; | 67 var callbackRun = false; |
| 68 return runTest(() { | 68 return runTestBody(() { |
| 69 expectAsync((arg1, arg2, arg3, arg4) { | 69 expectAsync((arg1, arg2, arg3, arg4) { |
| 70 expect(arg1, equals(1)); | 70 expect(arg1, equals(1)); |
| 71 expect(arg2, equals(2)); | 71 expect(arg2, equals(2)); |
| 72 expect(arg3, equals(3)); | 72 expect(arg3, equals(3)); |
| 73 expect(arg4, equals(4)); | 73 expect(arg4, equals(4)); |
| 74 callbackRun = true; | 74 callbackRun = true; |
| 75 })(1, 2, 3, 4); | 75 })(1, 2, 3, 4); |
| 76 }).then((liveTest) { | 76 }).then((liveTest) { |
| 77 expectTestPassed(liveTest); | 77 expectTestPassed(liveTest); |
| 78 expect(callbackRun, isTrue); | 78 expect(callbackRun, isTrue); |
| 79 }); | 79 }); |
| 80 }); | 80 }); |
| 81 | 81 |
| 82 test("5", () { | 82 test("5", () { |
| 83 var callbackRun = false; | 83 var callbackRun = false; |
| 84 return runTest(() { | 84 return runTestBody(() { |
| 85 expectAsync((arg1, arg2, arg3, arg4, arg5) { | 85 expectAsync((arg1, arg2, arg3, arg4, arg5) { |
| 86 expect(arg1, equals(1)); | 86 expect(arg1, equals(1)); |
| 87 expect(arg2, equals(2)); | 87 expect(arg2, equals(2)); |
| 88 expect(arg3, equals(3)); | 88 expect(arg3, equals(3)); |
| 89 expect(arg4, equals(4)); | 89 expect(arg4, equals(4)); |
| 90 expect(arg5, equals(5)); | 90 expect(arg5, equals(5)); |
| 91 callbackRun = true; | 91 callbackRun = true; |
| 92 })(1, 2, 3, 4, 5); | 92 })(1, 2, 3, 4, 5); |
| 93 }).then((liveTest) { | 93 }).then((liveTest) { |
| 94 expectTestPassed(liveTest); | 94 expectTestPassed(liveTest); |
| 95 expect(callbackRun, isTrue); | 95 expect(callbackRun, isTrue); |
| 96 }); | 96 }); |
| 97 }); | 97 }); |
| 98 | 98 |
| 99 test("6", () { | 99 test("6", () { |
| 100 var callbackRun = false; | 100 var callbackRun = false; |
| 101 return runTest(() { | 101 return runTestBody(() { |
| 102 expectAsync((arg1, arg2, arg3, arg4, arg5, arg6) { | 102 expectAsync((arg1, arg2, arg3, arg4, arg5, arg6) { |
| 103 expect(arg1, equals(1)); | 103 expect(arg1, equals(1)); |
| 104 expect(arg2, equals(2)); | 104 expect(arg2, equals(2)); |
| 105 expect(arg3, equals(3)); | 105 expect(arg3, equals(3)); |
| 106 expect(arg4, equals(4)); | 106 expect(arg4, equals(4)); |
| 107 expect(arg5, equals(5)); | 107 expect(arg5, equals(5)); |
| 108 expect(arg6, equals(6)); | 108 expect(arg6, equals(6)); |
| 109 callbackRun = true; | 109 callbackRun = true; |
| 110 })(1, 2, 3, 4, 5, 6); | 110 })(1, 2, 3, 4, 5, 6); |
| 111 }).then((liveTest) { | 111 }).then((liveTest) { |
| 112 expectTestPassed(liveTest); | 112 expectTestPassed(liveTest); |
| 113 expect(callbackRun, isTrue); | 113 expect(callbackRun, isTrue); |
| 114 }); | 114 }); |
| 115 }); | 115 }); |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 group("with optional arguments", () { | 118 group("with optional arguments", () { |
| 119 test("allows them to be passed", () { | 119 test("allows them to be passed", () { |
| 120 var callbackRun = false; | 120 var callbackRun = false; |
| 121 return runTest(() { | 121 return runTestBody(() { |
| 122 expectAsync(([arg = 1]) { | 122 expectAsync(([arg = 1]) { |
| 123 expect(arg, equals(2)); | 123 expect(arg, equals(2)); |
| 124 callbackRun = true; | 124 callbackRun = true; |
| 125 })(2); | 125 })(2); |
| 126 }).then((liveTest) { | 126 }).then((liveTest) { |
| 127 expectTestPassed(liveTest); | 127 expectTestPassed(liveTest); |
| 128 expect(callbackRun, isTrue); | 128 expect(callbackRun, isTrue); |
| 129 }); | 129 }); |
| 130 }); | 130 }); |
| 131 | 131 |
| 132 test("allows them not to be passed", () { | 132 test("allows them not to be passed", () { |
| 133 var callbackRun = false; | 133 var callbackRun = false; |
| 134 return runTest(() { | 134 return runTestBody(() { |
| 135 expectAsync(([arg = 1]) { | 135 expectAsync(([arg = 1]) { |
| 136 expect(arg, equals(1)); | 136 expect(arg, equals(1)); |
| 137 callbackRun = true; | 137 callbackRun = true; |
| 138 })(); | 138 })(); |
| 139 }).then((liveTest) { | 139 }).then((liveTest) { |
| 140 expectTestPassed(liveTest); | 140 expectTestPassed(liveTest); |
| 141 expect(callbackRun, isTrue); | 141 expect(callbackRun, isTrue); |
| 142 }); | 142 }); |
| 143 }); | 143 }); |
| 144 }); | 144 }); |
| 145 | 145 |
| 146 test("doesn't support a function with 7 arguments", () { | 146 test("doesn't support a function with 7 arguments", () { |
| 147 expect(() => expectAsync((_1, _2, _3, _4, _5, _6, _7) {}), | 147 expect(() => expectAsync((_1, _2, _3, _4, _5, _6, _7) {}), |
| 148 throwsArgumentError); | 148 throwsArgumentError); |
| 149 }); | 149 }); |
| 150 | 150 |
| 151 group("by default", () { | 151 group("by default", () { |
| 152 test("won't allow the test to complete until it's called", () { | 152 test("won't allow the test to complete until it's called", () { |
| 153 return expectTestBlocks( | 153 return expectTestBlocks( |
| 154 () => expectAsync(() {}), | 154 () => expectAsync(() {}), |
| 155 (callback) => callback()); | 155 (callback) => callback()); |
| 156 }); | 156 }); |
| 157 | 157 |
| 158 test("may only be called once", () { | 158 test("may only be called once", () { |
| 159 return runTest(() { | 159 return runTestBody(() { |
| 160 var callback = expectAsync(() {}); | 160 var callback = expectAsync(() {}); |
| 161 callback(); | 161 callback(); |
| 162 callback(); | 162 callback(); |
| 163 }).then((liveTest) { | 163 }).then((liveTest) { |
| 164 expectTestFailed(liveTest, | 164 expectTestFailed(liveTest, |
| 165 "Callback called more times than expected (1)."); | 165 "Callback called more times than expected (1)."); |
| 166 }); | 166 }); |
| 167 }); | 167 }); |
| 168 }); | 168 }); |
| 169 | 169 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 190 | 190 |
| 191 return liveTest.run().then((_) { | 191 return liveTest.run().then((_) { |
| 192 expectTestPassed(liveTest); | 192 expectTestPassed(liveTest); |
| 193 // Ensure that the outer test doesn't complete until the inner future | 193 // Ensure that the outer test doesn't complete until the inner future |
| 194 // completes. | 194 // completes. |
| 195 return future; | 195 return future; |
| 196 }); | 196 }); |
| 197 }); | 197 }); |
| 198 | 198 |
| 199 test("will throw an error if it's called more than that many times", () { | 199 test("will throw an error if it's called more than that many times", () { |
| 200 return runTest(() { | 200 return runTestBody(() { |
| 201 var callback = expectAsync(() {}, count: 3); | 201 var callback = expectAsync(() {}, count: 3); |
| 202 callback(); | 202 callback(); |
| 203 callback(); | 203 callback(); |
| 204 callback(); | 204 callback(); |
| 205 callback(); | 205 callback(); |
| 206 }).then((liveTest) { | 206 }).then((liveTest) { |
| 207 expectTestFailed( | 207 expectTestFailed( |
| 208 liveTest, "Callback called more times than expected (3)."); | 208 liveTest, "Callback called more times than expected (3)."); |
| 209 }); | 209 }); |
| 210 }); | 210 }); |
| 211 | 211 |
| 212 group("0,", () { | 212 group("0,", () { |
| 213 test("won't block the test's completion", () { | 213 test("won't block the test's completion", () { |
| 214 expectAsync(() {}, count: 0); | 214 expectAsync(() {}, count: 0); |
| 215 }); | 215 }); |
| 216 | 216 |
| 217 test("will throw an error if it's ever called", () { | 217 test("will throw an error if it's ever called", () { |
| 218 return runTest(() { | 218 return runTestBody(() { |
| 219 expectAsync(() {}, count: 0)(); | 219 expectAsync(() {}, count: 0)(); |
| 220 }).then((liveTest) { | 220 }).then((liveTest) { |
| 221 expectTestFailed( | 221 expectTestFailed( |
| 222 liveTest, "Callback called more times than expected (0)."); | 222 liveTest, "Callback called more times than expected (0)."); |
| 223 }); | 223 }); |
| 224 }); | 224 }); |
| 225 }); | 225 }); |
| 226 }); | 226 }); |
| 227 | 227 |
| 228 group("with max", () { | 228 group("with max", () { |
| 229 test("will allow the callback to be called that many times", () { | 229 test("will allow the callback to be called that many times", () { |
| 230 var callback = expectAsync(() {}, max: 3); | 230 var callback = expectAsync(() {}, max: 3); |
| 231 callback(); | 231 callback(); |
| 232 callback(); | 232 callback(); |
| 233 callback(); | 233 callback(); |
| 234 }); | 234 }); |
| 235 | 235 |
| 236 test("will allow the callback to be called fewer than that many times", () { | 236 test("will allow the callback to be called fewer than that many times", () { |
| 237 var callback = expectAsync(() {}, max: 3); | 237 var callback = expectAsync(() {}, max: 3); |
| 238 callback(); | 238 callback(); |
| 239 }); | 239 }); |
| 240 | 240 |
| 241 test("will throw an error if it's called more than that many times", () { | 241 test("will throw an error if it's called more than that many times", () { |
| 242 return runTest(() { | 242 return runTestBody(() { |
| 243 var callback = expectAsync(() {}, max: 3); | 243 var callback = expectAsync(() {}, max: 3); |
| 244 callback(); | 244 callback(); |
| 245 callback(); | 245 callback(); |
| 246 callback(); | 246 callback(); |
| 247 callback(); | 247 callback(); |
| 248 }).then((liveTest) { | 248 }).then((liveTest) { |
| 249 expectTestFailed( | 249 expectTestFailed( |
| 250 liveTest, "Callback called more times than expected (3)."); | 250 liveTest, "Callback called more times than expected (3)."); |
| 251 }); | 251 }); |
| 252 }); | 252 }); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 var callbackRun = false; | 295 var callbackRun = false; |
| 296 expectAsyncUntil(() => callbackRun = true, () { | 296 expectAsyncUntil(() => callbackRun = true, () { |
| 297 expect(callbackRun, isTrue); | 297 expect(callbackRun, isTrue); |
| 298 return true; | 298 return true; |
| 299 })(); | 299 })(); |
| 300 }); | 300 }); |
| 301 }); | 301 }); |
| 302 | 302 |
| 303 group("with errors", () { | 303 group("with errors", () { |
| 304 test("reports them to the current test", () { | 304 test("reports them to the current test", () { |
| 305 return runTest(() { | 305 return runTestBody(() { |
| 306 expectAsync(() => throw new TestFailure('oh no'))(); | 306 expectAsync(() => throw new TestFailure('oh no'))(); |
| 307 }).then((liveTest) { | 307 }).then((liveTest) { |
| 308 expectTestFailed(liveTest, 'oh no'); | 308 expectTestFailed(liveTest, 'oh no'); |
| 309 }); | 309 }); |
| 310 }); | 310 }); |
| 311 | 311 |
| 312 test("swallows them and returns null", () { | 312 test("swallows them and returns null", () { |
| 313 var returnValue; | 313 var returnValue; |
| 314 var caughtError = false; | 314 var caughtError = false; |
| 315 return runTest(() { | 315 return runTestBody(() { |
| 316 try { | 316 try { |
| 317 returnValue = expectAsync(() => throw new TestFailure('oh no'))(); | 317 returnValue = expectAsync(() => throw new TestFailure('oh no'))(); |
| 318 } on TestFailure catch (_) { | 318 } on TestFailure catch (_) { |
| 319 caughtError = true; | 319 caughtError = true; |
| 320 } | 320 } |
| 321 }).then((liveTest) { | 321 }).then((liveTest) { |
| 322 expectTestFailed(liveTest, 'oh no'); | 322 expectTestFailed(liveTest, 'oh no'); |
| 323 expect(returnValue, isNull); | 323 expect(returnValue, isNull); |
| 324 expect(caughtError, isFalse); | 324 expect(caughtError, isFalse); |
| 325 }); | 325 }); |
| 326 }); | 326 }); |
| 327 }); | 327 }); |
| 328 } | 328 } |
| OLD | NEW |