| 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 // TODO(jmesserly): replace this with the real package:test. | 5 // TODO(jmesserly): replace this with the real package:test. |
| 6 // Not possible yet due to various bugs we still have. | 6 // Not possible yet due to various bugs we still have. |
| 7 library minitest; | 7 library minitest; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'package:dom/dom.dart'; | 10 import 'dart:js'; |
| 11 import 'package:matcher/matcher.dart'; | 11 import 'package:matcher/matcher.dart'; |
| 12 export 'package:matcher/matcher.dart'; | 12 export 'package:matcher/matcher.dart'; |
| 13 | 13 |
| 14 void group(String name, void body()) => (window as dynamic).suite(name, body); | 14 void group(String name, void body()) => context.callMethod('suite', [name, body]
); |
| 15 | 15 |
| 16 void test(String name, body(), {String skip}) { | 16 void test(String name, body(), {String skip}) { |
| 17 if (skip != null) { | 17 if (skip != null) { |
| 18 print('SKIP $name: $skip'); | 18 print('SKIP $name: $skip'); |
| 19 return; | 19 return; |
| 20 } | 20 } |
| 21 (window as dynamic).test(name, (done) { | 21 JsObject result = context.callMethod('test', [name, (JsFunction done) { |
| 22 _finishTest(f) { | 22 _finishTest(f) { |
| 23 if (f is Future) { | 23 if (f is Future) { |
| 24 f.then(_finishTest); | 24 f.then(_finishTest); |
| 25 } else { | 25 } else { |
| 26 done(); | 26 done.apply([]); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 _finishTest(body()); | 29 _finishTest(body()); |
| 30 }); | 30 }]); |
| 31 result['async'] = 1; |
| 31 } | 32 } |
| 32 | 33 |
| 33 | 34 |
| 34 // TODO(jmesserly): everything below this was stolen from | 35 // TODO(jmesserly): everything below this was stolen from |
| 35 // package:test/src/frontend/expect.dart | 36 // package:test/src/frontend/expect.dart |
| 36 | 37 |
| 37 /// An exception thrown when a test assertion fails. | 38 /// An exception thrown when a test assertion fails. |
| 38 class TestFailure { | 39 class TestFailure { |
| 39 final String message; | 40 final String message; |
| 40 | 41 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 92 |
| 92 var mismatchDescription = new StringDescription(); | 93 var mismatchDescription = new StringDescription(); |
| 93 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); | 94 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); |
| 94 | 95 |
| 95 if (mismatchDescription.length > 0) { | 96 if (mismatchDescription.length > 0) { |
| 96 description.add(' Which: ${mismatchDescription}\n'); | 97 description.add(' Which: ${mismatchDescription}\n'); |
| 97 } | 98 } |
| 98 if (reason != null) description.add(reason).add('\n'); | 99 if (reason != null) description.add(reason).add('\n'); |
| 99 return description.toString(); | 100 return description.toString(); |
| 100 } | 101 } |
| OLD | NEW |