|
4 | 4 |
|
5 | 5 | library async_await_test;
|
6 | 6 |
|
7 |
| -import "package:unittest/unittest.dart"; |
| 7 | +import "package:expect/expect.dart"; |
| 8 | +import "package:async_helper/async_helper.dart"; |
8 | 9 | import "dart:async";
|
9 | 10 |
|
10 | 11 | main() {
|
11 |
| - bool assertionsEnabled = false; |
12 |
| - assert((assertionsEnabled = true)); |
13 |
| - |
| 12 | + asyncStart(); |
14 | 13 | group("basic", () {
|
15 | 14 | test("async w/o await", () {
|
16 | 15 | f() async {
|
@@ -131,7 +130,7 @@ main() {
|
131 | 130 | return throwsErr(f());
|
132 | 131 | });
|
133 | 132 |
|
134 |
| - if (assertionsEnabled) { |
| 133 | + if (assertStatementsEnabled) { |
135 | 134 | test("assert before await", () {
|
136 | 135 | f(v) async {
|
137 | 136 | assert(v == 87);
|
@@ -232,7 +231,7 @@ main() {
|
232 | 231 | });
|
233 | 232 | });
|
234 | 233 |
|
235 |
| - if (assertionsEnabled) { |
| 234 | + if (assertStatementsEnabled) { |
236 | 235 | test("await for w/ await, asseert", () {
|
237 | 236 | f(Stream<int> s) async {
|
238 | 237 | int i = 0;
|
@@ -1695,9 +1694,7 @@ main() {
|
1695 | 1694 | return expect42(asyncInSync(f42));
|
1696 | 1695 | });
|
1697 | 1696 |
|
1698 |
| - // Equality and identity. |
1699 |
| - // TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/265 |
1700 |
| - skip_test("Identical and equals", () { |
| 1697 | + test("Identical and equals", () { |
1701 | 1698 | expect(async.instanceMethod, equals(async.instanceMethod));
|
1702 | 1699 | expect(Async.staticMethod, same(Async.staticMethod));
|
1703 | 1700 | expect(topMethod, same(topMethod));
|
@@ -1794,8 +1791,7 @@ main() {
|
1794 | 1791 | return expect42(f());
|
1795 | 1792 | });
|
1796 | 1793 |
|
1797 |
| - // TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/265 |
1798 |
| - skip_test("suffix operator + pre-increment", () { |
| 1794 | + test("suffix operator + pre-increment", () { |
1799 | 1795 | f() async {
|
1800 | 1796 | var v = [41];
|
1801 | 1797 | return await ++v[0];
|
@@ -1913,7 +1909,7 @@ main() {
|
1913 | 1909 | return expect42(f());
|
1914 | 1910 | });
|
1915 | 1911 |
|
1916 |
| - if (!assertionsEnabled) return; |
| 1912 | + if (!assertStatementsEnabled) return; |
1917 | 1913 |
|
1918 | 1914 | test("inside assert, true", () { // //# 03: ok
|
1919 | 1915 | f() async { // //# 03: continued
|
@@ -1967,8 +1963,57 @@ main() {
|
1967 | 1963 | expect(yield, equals(42));
|
1968 | 1964 | });
|
1969 | 1965 | });
|
| 1966 | + asyncEnd(); |
| 1967 | +} |
| 1968 | + |
| 1969 | +// Mock test framework sufficient to run tests. |
| 1970 | + |
| 1971 | +String _currentName = ""; |
| 1972 | + |
| 1973 | +test(name, action()) { |
| 1974 | + var oldName = _currentName; |
| 1975 | + _currentName = [oldName, name].join(" "); |
| 1976 | + runZoned(() { |
| 1977 | + asyncTest(() => new Future.sync(action)); |
| 1978 | + }, zoneValues: {#testName: _currentName}); |
| 1979 | + _currentName = oldName; |
| 1980 | +} |
| 1981 | + |
| 1982 | +group(name, entries()) { |
| 1983 | + var oldName = _currentName; |
| 1984 | + _currentName = [oldName, name].join(" "); |
| 1985 | + entries(); |
| 1986 | + _currentName = oldName; |
1970 | 1987 | }
|
1971 | 1988 |
|
| 1989 | +expect(value, expectation) { |
| 1990 | + var name = Zone.current[#testName]; |
| 1991 | + if (expectation is bool) { |
| 1992 | + // Just for better error message. |
| 1993 | + (expectation ? Expect.isTrue : Expect.isFalse)(value, name); |
| 1994 | + return; |
| 1995 | + } |
| 1996 | + if (expectation is List) { |
| 1997 | + Expect.listEquals(expectation, value, name); |
| 1998 | + return; |
| 1999 | + } |
| 2000 | + if (expectation is Function(Object, String)) { |
| 2001 | + expectation(value, name); |
| 2002 | + return; |
| 2003 | + } |
| 2004 | + Expect.equals(expectation, value, name); |
| 2005 | +} |
| 2006 | + |
| 2007 | +equals(x) => x; |
| 2008 | +final isTrue = true; |
| 2009 | +same(v) => (Object o, String name) => Expect.identical(v, o, name); |
| 2010 | +fail(message) { |
| 2011 | + var name = Zone.current[#testName]; |
| 2012 | + Expect.fail("$name: $message"); |
| 2013 | +} |
| 2014 | + |
| 2015 | +// End mock. |
| 2016 | + |
1972 | 2017 | // Attempt to obfuscates value to avoid too much constant folding.
|
1973 | 2018 | id(v) {
|
1974 | 2019 | try {
|
|
0 commit comments