| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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(rnystrom): This code is gradually moving from a Java/JUnit style to | 5 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to |
| 6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go | 6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go |
| 7 // away completely (or become private to this library) and the only exposed API | 7 // away completely (or become private to this library) and the only exposed API |
| 8 // will be group()/test()/expect(). Until then, both ways are supported, which | 8 // will be group()/test()/expect(). Until then, both ways are supported, which |
| 9 // is why things look a bit weird in here. | 9 // is why things look a bit weird in here. |
| 10 | 10 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 document.body.innerHTML = newBody.toString(); | 253 document.body.innerHTML = newBody.toString(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 window.dynamic/*TODO(5389254)*/.postMessage('unittest-suite-done', '*'); | 256 window.dynamic/*TODO(5389254)*/.postMessage('unittest-suite-done', '*'); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 /** Creates an expectation for the given value. */ | 260 /** Creates an expectation for the given value. */ |
| 261 Expectation expect(value) => new Expectation(value); | 261 Expectation expect(value) => new Expectation(value); |
| 262 | 262 |
| 263 /** Evaluates the given function and validates that it throws an exception. */ |
| 264 void expectThrow(function) { |
| 265 bool threw = false; |
| 266 try { |
| 267 function(); |
| 268 } catch (var e) { |
| 269 threw = true; |
| 270 } |
| 271 Expect.equals(true, threw, 'Expected exception but none was thrown.'); |
| 272 } |
| 273 |
| 263 /** | 274 /** |
| 264 * Creates a new test case with the given description and body. The | 275 * Creates a new test case with the given description and body. The |
| 265 * description will include the descriptions of any surrounding group() | 276 * description will include the descriptions of any surrounding group() |
| 266 * calls. | 277 * calls. |
| 267 */ | 278 */ |
| 268 void test(String spec, TestFunction body) { | 279 void test(String spec, TestFunction body) { |
| 269 _ensureActiveSuite(); | 280 _ensureActiveSuite(); |
| 270 | 281 |
| 271 _currentSuite._tests.add(new TestCase( | 282 _currentSuite._tests.add(new TestCase( |
| 272 _currentSuite._tests.length + 1, _fullSpec(spec), body, 0)); | 283 _currentSuite._tests.length + 1, _fullSpec(spec), body, 0)); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 </tr>"""; | 487 </tr>"""; |
| 477 if (stackTrace != null) { | 488 if (stackTrace != null) { |
| 478 message += | 489 message += |
| 479 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; | 490 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; |
| 480 } | 491 } |
| 481 fail = true; | 492 fail = true; |
| 482 } | 493 } |
| 483 } | 494 } |
| 484 | 495 |
| 485 typedef void TestFunction(); | 496 typedef void TestFunction(); |
| OLD | NEW |