OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 library dunit; | 6 library dunit; |
7 | 7 |
8 typedef void Test(); | 8 typedef void Test(); |
9 typedef TestResult SynchTest(); | 9 typedef TestResult SynchTest(); |
10 typedef Future<TestResult> AsynchTest(); | 10 typedef Future<TestResult> AsynchTest(); |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 List<TestResult> runTests() { | 27 List<TestResult> runTests() { |
28 List<TestResult> results = <TestResult>[]; | 28 List<TestResult> results = <TestResult>[]; |
29 for(Function test in _tests) { | 29 for(Function test in _tests) { |
30 results.add(test()); | 30 results.add(test()); |
31 } | 31 } |
32 return results; | 32 return results; |
33 } | 33 } |
34 | 34 |
35 void reportResults(List<TestResult> results) { | 35 void reportResults(List<TestResult> results) { |
36 if(results.every(bool _(TestResult r) => r is PassedTest)) { | 36 if(results.every((TestResult r) => r is PassedTest)) { |
37 print("OK -- ALL TESTS PASS (${results.length} run)"); | 37 print("OK -- ALL TESTS PASS (${results.length} run)"); |
38 } else { | 38 } else { |
39 for(TestResult r in | 39 for(TestResult r in |
40 results.where(bool _(TestResult r) => !(r is PassedTest))) { | 40 results.where((TestResult r) => !(r is PassedTest))) { |
41 print(r); | 41 print(r); |
42 } | 42 } |
43 int passedTests = | 43 int passedTests = |
44 results.where(bool _(TestResult r) => r is PassedTest).length; | 44 results.where((TestResult r) => r is PassedTest).length; |
45 int failures = | 45 int failures = |
46 results.where(bool _(TestResult r) => r is FailedTest).length; | 46 results.where((TestResult r) => r is FailedTest).length; |
47 int errors = | 47 int errors = |
48 results.where(bool _(TestResult r) => r is TestError).length; | 48 results.where((TestResult r) => r is TestError).length; |
49 print("FAIL -- TESTS RUN: ${results.length}"); | 49 print("FAIL -- TESTS RUN: ${results.length}"); |
50 print(" PASSED: ${passedTests}"); | 50 print(" PASSED: ${passedTests}"); |
51 print(" FAILED: ${failures}"); | 51 print(" FAILED: ${failures}"); |
52 print(" ERRORS: ${errors}"); | 52 print(" ERRORS: ${errors}"); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 List<SynchTest> _tests; | 56 List<SynchTest> _tests; |
57 } | 57 } |
58 | 58 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 super(testDescription, exception); | 90 super(testDescription, exception); |
91 | 91 |
92 String toString() => ">>> Test error caught in " + | 92 String toString() => ">>> Test error caught in " + |
93 "${_testDescription} with:\n${exception}\n$stacktrace\n"; | 93 "${_testDescription} with:\n${exception}\n$stacktrace\n"; |
94 | 94 |
95 var stacktrace; | 95 var stacktrace; |
96 } | 96 } |
97 | 97 |
98 class TestClass { | 98 class TestClass { |
99 void register(String description, Function test, TestSuite suite) { | 99 void register(String description, Function test, TestSuite suite) { |
100 suite._registerTest(TestResult _() { | 100 suite._registerTest(() { |
101 setUp(); | 101 setUp(); |
102 try { | 102 try { |
103 test(); | 103 test(); |
104 tearDown(); | 104 tearDown(); |
105 return new PassedTest(description); | 105 return new PassedTest(description); |
106 } on ExpectException catch (x) { | 106 } on ExpectException catch (x) { |
107 tearDown(); | 107 tearDown(); |
108 return new FailedTest(description, x); | 108 return new FailedTest(description, x); |
109 } catch (x, stacktrace) { | 109 } catch (x, stacktrace) { |
110 tearDown(); | 110 tearDown(); |
111 return new TestError(description, x, stacktrace); | 111 return new TestError(description, x, stacktrace); |
112 } | 112 } |
113 }); | 113 }); |
114 } | 114 } |
115 | 115 |
116 abstract void registerTests(TestSuite suite); | 116 void registerTests(TestSuite suite); |
117 void setUp() {} | 117 void setUp() {} |
118 void tearDown() {} | 118 void tearDown() {} |
119 } | 119 } |
OLD | NEW |