| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // TODO(gram): | 5 // TODO(gram): |
| 6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. | 6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. |
| 7 // insufficient callbacks, because the timeout is controlled externally | 7 // insufficient callbacks, because the timeout is controlled externally |
| 8 // (test.dart?), and we would need to use a shorter timeout for the inner tests | 8 // (test.dart?), and we would need to use a shorter timeout for the inner tests |
| 9 // so the outer timeout doesn't fire. So I removed all such tests. | 9 // so the outer timeout doesn't fire. So I removed all such tests. |
| 10 // I'd like to revisit this at some point. | 10 // I'd like to revisit this at some point. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 runTest() { | 90 runTest() { |
| 91 port.receive((testName, sendport) { | 91 port.receive((testName, sendport) { |
| 92 configure(_testconfig = new TestConfiguration(sendport)); | 92 configure(_testconfig = new TestConfiguration(sendport)); |
| 93 if (testName == 'single correct test') { | 93 if (testName == 'single correct test') { |
| 94 test(testName, () => expect(2 + 3, equals(5))); | 94 test(testName, () => expect(2 + 3, equals(5))); |
| 95 } else if (testName == 'single failing test') { | 95 } else if (testName == 'single failing test') { |
| 96 test(testName, () => expect(2 + 2, equals(5))); | 96 test(testName, () => expect(2 + 2, equals(5))); |
| 97 } else if (testName == 'exception test') { | 97 } else if (testName == 'exception test') { |
| 98 test(testName, () { throw new Exception('fail'); }); | 98 test(testName, () { throw new Exception('Fail.'); }); |
| 99 } else if (testName == 'group name test') { | 99 } else if (testName == 'group name test') { |
| 100 group('a', () { | 100 group('a', () { |
| 101 test('a', () {}); | 101 test('a', () {}); |
| 102 group('b', () { | 102 group('b', () { |
| 103 test('b', () {}); | 103 test('b', () {}); |
| 104 }); | 104 }); |
| 105 }); | 105 }); |
| 106 } else if (testName == 'setup test') { | 106 } else if (testName == 'setup test') { |
| 107 group('a', () { | 107 group('a', () { |
| 108 setUp(() { _testconfig.setup = 'setup'; }); | 108 setUp(() { _testconfig.setup = 'setup'; }); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 m.getLogs(callsTo(null, 1)).verify(happenedExactly(2)); | 251 m.getLogs(callsTo(null, 1)).verify(happenedExactly(2)); |
| 252 m.getLogs(callsTo(null, 2)).verify(happenedExactly(2)); | 252 m.getLogs(callsTo(null, 2)).verify(happenedExactly(2)); |
| 253 m.getLogs(null, returning(1)).verify(neverHappened); | 253 m.getLogs(null, returning(1)).verify(neverHappened); |
| 254 m.getLogs(null, returning(2)).verify(happenedExactly(2)); | 254 m.getLogs(null, returning(2)).verify(happenedExactly(2)); |
| 255 m.getLogs(null, returning(4)).verify(happenedExactly(2)); | 255 m.getLogs(null, returning(4)).verify(happenedExactly(2)); |
| 256 }); | 256 }); |
| 257 } else if (testName.startsWith('mock test 10 ')) { | 257 } else if (testName.startsWith('mock test 10 ')) { |
| 258 test(testName, () { | 258 test(testName, () { |
| 259 var m = new Mock(); | 259 var m = new Mock(); |
| 260 m.when(callsTo(matches('^[A-Z]'))). | 260 m.when(callsTo(matches('^[A-Z]'))). |
| 261 alwaysThrow('Method names must start with lower case'); | 261 alwaysThrow('Method names must start with lower case.'); |
| 262 m.test(); | 262 m.test(); |
| 263 }); | 263 }); |
| 264 } else if (testName.startsWith('mock test 11 ')) { | 264 } else if (testName.startsWith('mock test 11 ')) { |
| 265 test(testName, () { | 265 test(testName, () { |
| 266 var m = new Mock(); | 266 var m = new Mock(); |
| 267 m.when(callsTo(matches('^[A-Z]'))). | 267 m.when(callsTo(matches('^[A-Z]'))). |
| 268 alwaysThrow('Method names must start with lower case'); | 268 alwaysThrow('Method names must start with lower case.'); |
| 269 m.Test(); | 269 m.Test(); |
| 270 }); | 270 }); |
| 271 } else if (testName.startsWith('mock test 12 ')) { |
| 272 test(testName, () { |
| 273 var m = new Mock.custom(enableLogging:false); |
| 274 m.Test(); |
| 275 print(m.getLogs(callsTo('Test')).toString()); |
| 276 }); |
| 271 } | 277 } |
| 272 }); | 278 }); |
| 273 } | 279 } |
| 274 | 280 |
| 275 void nextTest(int testNum) { | 281 void nextTest(int testNum) { |
| 276 SendPort sport = spawnFunction(runTest); | 282 SendPort sport = spawnFunction(runTest); |
| 277 sport.call(tests[testNum]).then((msg) { | 283 sport.call(tests[testNum]).then((msg) { |
| 278 actual.add(msg); | 284 actual.add(msg); |
| 279 if (actual.length == expected.length) { | 285 if (actual.length == expected.length) { |
| 280 for (var i = 0; i < tests.length; i++) { | 286 for (var i = 0; i < tests.length; i++) { |
| 281 test(tests[i], () => expect(actual[i], equals(expected[i]))); | 287 test(tests[i], () => expect(actual[i].trim(), equals(expected[i]))); |
| 282 } | 288 } |
| 283 } else { | 289 } else { |
| 284 nextTest(testNum+1); | 290 nextTest(testNum+1); |
| 285 } | 291 } |
| 286 }); | 292 }); |
| 287 } | 293 } |
| 288 | 294 |
| 289 main() { | 295 main() { |
| 290 tests = [ | 296 tests = [ |
| 291 'single correct test', | 297 'single correct test', |
| 292 'single failing test', | 298 'single failing test', |
| 293 'exception test', | 299 'exception test', |
| 294 'group name test', | 300 'group name test', |
| 295 'setup test', | 301 'setup test', |
| 296 'teardown test', | 302 'teardown test', |
| 297 'setup and teardown test', | 303 'setup and teardown test', |
| 298 'correct callback test', | 304 'correct callback test', |
| 299 'excess callback test', | 305 'excess callback test', |
| 300 'completion test', | 306 'completion test', |
| 301 'mock test 1 (Mock)', | 307 'mock test 1 (Mock)', |
| 302 'mock test 2 (MockList)', | 308 'mock test 2 (MockList)', |
| 303 'mock test 3 (Spy)', | 309 'mock test 3 (Spy)', |
| 304 'mock test 4 (Excess calls)', | 310 'mock test 4 (Excess calls)', |
| 305 'mock test 5 (No action)', | 311 'mock test 5 (No action)', |
| 306 'mock test 6 (No matching return)', | 312 'mock test 6 (No matching return)', |
| 307 'mock test 7 (No behavior)', | 313 'mock test 7 (No behavior)', |
| 308 'mock test 8 (Shared log)', | 314 'mock test 8 (Shared log)', |
| 309 'mock test 9 (Null CallMatcher)', | 315 'mock test 9 (Null CallMatcher)', |
| 310 'mock test 10 (RegExp CallMatcher Good)', | 316 'mock test 10 (RegExp CallMatcher Good)', |
| 311 'mock test 11 (RegExp CallMatcher Bad)' | 317 'mock test 11 (RegExp CallMatcher Bad)', |
| 318 'mock test 12 (No logging)' |
| 312 ]; | 319 ]; |
| 313 | 320 |
| 314 expected = [ | 321 expected = [ |
| 315 buildStatusString(1, 0, 0, tests[0]), | 322 buildStatusString(1, 0, 0, tests[0]), |
| 316 buildStatusString(0, 1, 0, tests[1], message: 'Expected: <5> but: was <4>'), | 323 buildStatusString(0, 1, 0, tests[1], |
| 317 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: fail'), | 324 message: 'Expected: <5> but: was <4>.'), |
| 325 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'), |
| 318 buildStatusString(2, 0, 0, 'a a::a b b'), | 326 buildStatusString(2, 0, 0, 'a a::a b b'), |
| 319 buildStatusString(1, 0, 0, 'a ${tests[4]}', 0, 'setup'), | 327 buildStatusString(1, 0, 0, 'a ${tests[4]}', 0, 'setup'), |
| 320 buildStatusString(1, 0, 0, 'a ${tests[5]}', 0, '', 'teardown'), | 328 buildStatusString(1, 0, 0, 'a ${tests[5]}', 0, '', 'teardown'), |
| 321 buildStatusString(1, 0, 0, 'a ${tests[6]}', 0, | 329 buildStatusString(1, 0, 0, 'a ${tests[6]}', 0, |
| 322 'setup', 'teardown'), | 330 'setup', 'teardown'), |
| 323 buildStatusString(1, 0, 0, tests[7], 1), | 331 buildStatusString(1, 0, 0, tests[7], 1), |
| 324 buildStatusString(0, 0, 1, tests[8], 1, | 332 buildStatusString(0, 0, 1, tests[8], 1, |
| 325 message: 'Callback called more times than expected (2 > 1)'), | 333 message: 'Callback called more times than expected (2 > 1).'), |
| 326 buildStatusString(1, 0, 0, tests[9], 10), | 334 buildStatusString(1, 0, 0, tests[9], 10), |
| 327 buildStatusString(1, 0, 0, tests[10]), | 335 buildStatusString(1, 0, 0, tests[10]), |
| 328 buildStatusString(1, 0, 0, tests[11]), | 336 buildStatusString(1, 0, 0, tests[11]), |
| 329 buildStatusString(1, 0, 0, tests[12]), | 337 buildStatusString(1, 0, 0, tests[12]), |
| 330 buildStatusString(0, 1, 0, tests[13], | 338 buildStatusString(0, 1, 0, tests[13], |
| 331 message: "Expected <null>.'foo'() to be called 1 times but:" | 339 message: "Expected <null>.'foo'() to be called 1 times but:" |
| 332 " was called 2 times"), | 340 " was called 2 times."), |
| 333 buildStatusString(0, 1, 0, tests[14], | 341 buildStatusString(0, 1, 0, tests[14], |
| 334 message: 'Caught Exception: No more actions for method foo'), | 342 message: 'Caught Exception: No more actions for method foo.'), |
| 335 buildStatusString(0, 1, 0, tests[15], message: | 343 buildStatusString(0, 1, 0, tests[15], message: |
| 336 "Expected <null>.'sum'() to sometimes return <0> but: never did"), | 344 "Expected <null>.'sum'() to sometimes return <0> but: never did."), |
| 337 buildStatusString(0, 1, 0, tests[16], | 345 buildStatusString(0, 1, 0, tests[16], |
| 338 message: 'Caught Exception: No behavior specified for method bar'), | 346 message: 'Caught Exception: No behavior specified for method bar.'), |
| 339 buildStatusString(1, 0, 0, tests[17]), | 347 buildStatusString(1, 0, 0, tests[17]), |
| 340 buildStatusString(1, 0, 0, tests[18]), | 348 buildStatusString(1, 0, 0, tests[18]), |
| 341 buildStatusString(1, 0, 0, tests[19]), | 349 buildStatusString(1, 0, 0, tests[19]), |
| 342 buildStatusString(0, 1, 0, tests[20], | 350 buildStatusString(0, 1, 0, tests[20], |
| 343 message:'Caught Method names must start with lower case') | 351 message:'Caught Method names must start with lower case.'), |
| 352 buildStatusString(0, 1, 0, tests[21], message: |
| 353 "Caught Exception: Can't retrieve logs when logging was never enabled."), |
| 344 ]; | 354 ]; |
| 345 | 355 |
| 346 actual = []; | 356 actual = []; |
| 347 | 357 |
| 348 nextTest(0); | 358 nextTest(0); |
| 349 } | 359 } |
| 350 | 360 |
| OLD | NEW |