Skip to content

Commit b56051a

Browse files
committed
Update language_2/async_await_test to not use unittest.
Change-Id: I239e844d90a79afeb54204c3bdfd41b4daabb03c Reviewed-on: https://dart-review.googlesource.com/26600 Reviewed-by: Bob Nystrom <[email protected]>
1 parent 1ed4096 commit b56051a

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

tests/language_2/async_await_test.dart

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
library async_await_test;
66

7-
import "package:unittest/unittest.dart";
7+
import "package:expect/expect.dart";
8+
import "package:async_helper/async_helper.dart";
89
import "dart:async";
910

1011
main() {
11-
bool assertionsEnabled = false;
12-
assert((assertionsEnabled = true));
13-
12+
asyncStart();
1413
group("basic", () {
1514
test("async w/o await", () {
1615
f() async {
@@ -131,7 +130,7 @@ main() {
131130
return throwsErr(f());
132131
});
133132

134-
if (assertionsEnabled) {
133+
if (assertStatementsEnabled) {
135134
test("assert before await", () {
136135
f(v) async {
137136
assert(v == 87);
@@ -232,7 +231,7 @@ main() {
232231
});
233232
});
234233

235-
if (assertionsEnabled) {
234+
if (assertStatementsEnabled) {
236235
test("await for w/ await, asseert", () {
237236
f(Stream<int> s) async {
238237
int i = 0;
@@ -1695,9 +1694,7 @@ main() {
16951694
return expect42(asyncInSync(f42));
16961695
});
16971696

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", () {
17011698
expect(async.instanceMethod, equals(async.instanceMethod));
17021699
expect(Async.staticMethod, same(Async.staticMethod));
17031700
expect(topMethod, same(topMethod));
@@ -1794,8 +1791,7 @@ main() {
17941791
return expect42(f());
17951792
});
17961793

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", () {
17991795
f() async {
18001796
var v = [41];
18011797
return await ++v[0];
@@ -1913,7 +1909,7 @@ main() {
19131909
return expect42(f());
19141910
});
19151911

1916-
if (!assertionsEnabled) return;
1912+
if (!assertStatementsEnabled) return;
19171913

19181914
test("inside assert, true", () { // //# 03: ok
19191915
f() async { // //# 03: continued
@@ -1967,8 +1963,57 @@ main() {
19671963
expect(yield, equals(42));
19681964
});
19691965
});
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;
19701987
}
19711988

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+
19722017
// Attempt to obfuscates value to avoid too much constant folding.
19732018
id(v) {
19742019
try {

tests/language_2/language_2_kernel.status

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ assert_initializer_test/48: MissingCompileTimeError # KernelVM bug: Constant eva
7878
assert_initializer_test/none: RuntimeError # KernelVM bug: Constant evaluation.
7979
assertion_initializer_const_function_test/01: RuntimeError
8080
assign_static_type_test/02: MissingCompileTimeError
81-
async_await_test/02: RuntimeError
82-
async_await_test/03: RuntimeError
83-
async_await_test/none: RuntimeError
8481
async_return_types_test/nestedFuture: Fail
8582
async_return_types_test/wrongTypeParameter: Fail
8683
async_star_regression_2238_test: RuntimeError
@@ -1407,9 +1404,6 @@ assign_top_method_test: MissingCompileTimeError
14071404
async_await_syntax_test/c10a: MissingCompileTimeError
14081405
async_await_syntax_test/d08b: MissingCompileTimeError
14091406
async_await_syntax_test/d10a: MissingCompileTimeError
1410-
async_await_test/02: CompileTimeError # Issue 31402 (Invocation arguments)
1411-
async_await_test/03: CompileTimeError # Issue 31402 (Invocation arguments)
1412-
async_await_test/none: CompileTimeError # Issue 31402 (Invocation arguments)
14131407
async_or_generator_return_type_stacktrace_test/01: MissingCompileTimeError
14141408
async_or_generator_return_type_stacktrace_test/02: MissingCompileTimeError
14151409
async_or_generator_return_type_stacktrace_test/03: MissingCompileTimeError

0 commit comments

Comments
 (0)