| 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 /** | 5 /** |
| 6 * Support for writing Dart unit tests. | 6 * Support for writing Dart unit tests. |
| 7 * | 7 * |
| 8 * For information on installing and importing this library, see the | 8 * For information on installing and importing this library, see the |
| 9 * [unittest package on pub.dartlang.org] | 9 * [unittest package on pub.dartlang.org] |
| 10 * (http://pub.dartlang.org/packages/unittest). | 10 * (http://pub.dartlang.org/packages/unittest). |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 /** Test case result strings. */ | 298 /** Test case result strings. */ |
| 299 // TODO(gram) we should change these constants to use a different string | 299 // TODO(gram) we should change these constants to use a different string |
| 300 // (so that writing 'FAIL' in the middle of a test doesn't | 300 // (so that writing 'FAIL' in the middle of a test doesn't |
| 301 // imply that the test fails). We can't do it without also changing | 301 // imply that the test fails). We can't do it without also changing |
| 302 // the testrunner and test.dart though. | 302 // the testrunner and test.dart though. |
| 303 const PASS = 'pass'; | 303 const PASS = 'pass'; |
| 304 const FAIL = 'fail'; | 304 const FAIL = 'fail'; |
| 305 const ERROR = 'error'; | 305 const ERROR = 'error'; |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * A map that can be used to communicate state between a test driver | |
| 309 * or main() function and the tests, particularly when these two | |
| 310 * are otherwise independent. For example, a test driver that starts | |
| 311 * an HTTP server and then runs tests that access that server could use | |
| 312 * this as a way of communicating the server port to the tests. | |
| 313 */ | |
| 314 Map testState = {}; | |
| 315 | |
| 316 /** | |
| 317 * Creates a new test case with the given description and body. The | 308 * Creates a new test case with the given description and body. The |
| 318 * description will include the descriptions of any surrounding group() | 309 * description will include the descriptions of any surrounding group() |
| 319 * calls. | 310 * calls. |
| 320 */ | 311 */ |
| 321 void test(String spec, TestFunction body) { | 312 void test(String spec, TestFunction body) { |
| 322 ensureInitialized(); | 313 ensureInitialized(); |
| 323 if (!_soloTestSeen || _soloNestingLevel > 0) { | 314 if (!_soloTestSeen || _soloNestingLevel > 0) { |
| 324 var testcase = new TestCase._internal(testCases.length + 1, _fullSpec(spec), | 315 var testcase = new TestCase._internal(testCases.length + 1, _fullSpec(spec), |
| 325 body); | 316 body); |
| 326 _testCases.add(testcase); | 317 _testCases.add(testcase); |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 872 |
| 882 if (!filterStacks) return trace; | 873 if (!filterStacks) return trace; |
| 883 | 874 |
| 884 // Format the stack trace by removing everything above TestCase._runTest, | 875 // Format the stack trace by removing everything above TestCase._runTest, |
| 885 // which is usually going to be irrelevant. Also fold together unittest and | 876 // which is usually going to be irrelevant. Also fold together unittest and |
| 886 // core library calls so only the function the user called is visible. | 877 // core library calls so only the function the user called is visible. |
| 887 return new Trace(trace.frames.takeWhile((frame) { | 878 return new Trace(trace.frames.takeWhile((frame) { |
| 888 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 879 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
| 889 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 880 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
| 890 } | 881 } |
| OLD | NEW |