Skip to content

Commit

Permalink
#2398. Make asyncStart/End() safe in LibTest/async (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Dec 6, 2023
1 parent af60144 commit dc603a5
Show file tree
Hide file tree
Showing 69 changed files with 150 additions and 154 deletions.
7 changes: 5 additions & 2 deletions LibTest/async/Completer/completeError_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ check(value) {
}

main() {
asyncStart();
check(0);
check(-5);
//check(null); // null is disallowed as an argument to completeError()
check('string');
check(true);
check(const {'k1': 1, 'k2': 2});
Future.wait(futures).whenComplete(() => Expect.equals(5, count));
Future.wait(futures).whenComplete(() {
Expect.equals(5, count);
asyncEnd();
});
}
18 changes: 6 additions & 12 deletions LibTest/async/Completer/completeError_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@ import "dart:async";
main() {
var completer = new Completer();
var future = completer.future;

var error = new Error();
var stackTrace;

asyncStart();

try {
throw error;
} catch(e, st) {
} catch (e, st) {
stackTrace = st;
completer.completeError(e, st);
}

future.then(
(fValue) => Expect.fail('should not get here'),
onError:(e, st) {
Expect.identical(error, e);
Expect.identical(stackTrace, st);
asyncEnd();
}
);
future.then((fValue) => Expect.fail('should not get here'), onError: (e, st) {
Expect.identical(error, e);
Expect.identical(stackTrace, st);
asyncEnd();
});
}

15 changes: 5 additions & 10 deletions LibTest/async/Completer/completeError_A01_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@ import "dart:async";
main() {
var completer = new Completer();
var future = completer.future;

var v = [1,2,3];
var v = [1, 2, 3];

asyncStart(2);

var f = new Future.value(v).then((x) {
asyncEnd();
return x;
});

future
.catchError((e) {
Expect.identical(f, e);
asyncEnd();
});

future.catchError((e) {
Expect.identical(f, e);
asyncEnd();
});
completer.completeError(f);
}
13 changes: 4 additions & 9 deletions LibTest/async/Completer/completeError_A01_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@ import "dart:async";
main() {
var completer = new Completer();
var future = completer.future;

var e = new Error();

asyncStart(2);

var f = new Future.error(e).catchError((x) {
asyncEnd();
return x;
});

future
.catchError((e) {
Expect.identical(f, e);
asyncEnd();
});

future.catchError((e) {
Expect.identical(f, e);
asyncEnd();
});
completer.completeError(f);
}
18 changes: 0 additions & 18 deletions LibTest/async/Completer/completeError_A02_t01.dart

This file was deleted.

2 changes: 2 additions & 0 deletions LibTest/async/Completer/complete_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ check(value) {
}

main() {
asyncStart();
check(0);
check(-5);
check(null);
check('string');
check(true);
check(const {'k1': 1, 'k2': 2});
asyncEnd();
}
7 changes: 5 additions & 2 deletions LibTest/async/Completer/complete_A01_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ main() {
var completer = new Completer();
var future = completer.future;

asyncStart();
for (int k = 0; k < N; k++) {
asyncStart();
futures.add(future.then((fValue) {
Expand All @@ -32,7 +33,9 @@ main() {
asyncEnd();
}));
}
Future.wait(futures).whenComplete(() => Expect.equals(N, count));

Future.wait(futures).whenComplete(() {
Expect.equals(N, count);
asyncEnd();
});
completer.complete(v);
}
3 changes: 0 additions & 3 deletions LibTest/async/Completer/complete_A01_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ import "../../../Utils/expect.dart";
main() {
var completer = new Completer();
var future = completer.future;

var value = [1, 2, 3];

asyncStart();

future.then((x) {
Expect.identical(value, x);
asyncEnd();
});

completer.complete(new Future.value(value));
}
3 changes: 0 additions & 3 deletions LibTest/async/Completer/complete_A01_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ import "../../../Utils/expect.dart";
main() {
var completer = new Completer();
var future = completer.future;

var error = new Error();

asyncStart();

future.catchError((x) {
Expect.identical(error, x);
asyncEnd();
});

completer.complete(new Future.error(error));
}
4 changes: 1 addition & 3 deletions LibTest/async/DeferredLibrary/DeferredLibrary_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
/// @author kaigorodov
/// @todo move from LibTest to Language

import "../../../Utils/expect.dart";

import 'DeferredLibrary_A01_t01.lib.dart' deferred as lazy;

void main() {
try {
lazy.method(); // foo is not loaded yet.
// Expect.fail("NoSuchMethodError expected"); -- #11507: do not insist on lazy loading
} on NoSuchMethodError catch(ok) {
} on NoSuchMethodError catch(_) {
}
asyncStart();
lazy.loadLibrary().then(onFooLoaded);
Expand Down
3 changes: 3 additions & 0 deletions LibTest/async/EventSink/all_tests.lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
library all_tests_eventsink;
import "dart:async";

import "../../../Utils/expect.dart";
import "EventSink_A01_t01.test.dart" as EventSink_A01_t01;
import "hashCode_A01_t01.test.dart" as hashCode_A01_t01;
import "runtimeType_A01_t01.test.dart" as runtimeType_A01_t01;
Expand All @@ -22,6 +23,7 @@ import "noSuchMethodError_A01_t01.test.dart" as noSuchMethodError_A01_t01;
import "toString_A01_t01.test.dart" as toString_A01_t01;

test(EventSink create()) {
asyncStart();
EventSink_A01_t01.test(create);
hashCode_A01_t01.test(create);
runtimeType_A01_t01.test(create);
Expand All @@ -31,4 +33,5 @@ test(EventSink create()) {
close_A01_t01.test(create);
noSuchMethodError_A01_t01.test(create);
toString_A01_t01.test(create);
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.delayed_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void check(delay, value) {
}

main() {
asyncStart();
check(0, 0);
check(10, 1);
check(0, -5);
Expand All @@ -33,4 +34,5 @@ main() {
check(0, true);
check(10, const []);
check(0, const {'k1': 1, 'k2': 2});
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.delayed_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ check(delayms) {
}

main() {
asyncStart();
check(0);
check(30);
check(50);
check(100);
check(150);
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.delayed_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ check(delay, value) {
}

main() {
asyncStart();
check(100, 3);
check(50, '');
check(0, []);
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.error_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ check(value) {
}

main() {
asyncStart();
check(0);
check(1);
check(-5);
Expand All @@ -35,4 +36,5 @@ main() {
check(true);
check(const []);
check(const {'k1': 1, 'k2': 2});
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.sync_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ check(value) {
}

main() {
asyncStart();
check(0);
check(1);
check(-5);
Expand All @@ -38,4 +39,5 @@ main() {
check(true);
check(const []);
check(const {'k1': 1, 'k2': 2});
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.sync_A01_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ check(value) {
}

main() {
asyncStart();
check(0);
check(1);
check(-5);
Expand All @@ -46,4 +47,5 @@ main() {
check(true);
check(const []);
check(const {'k1': 1, 'k2': 2});
asyncEnd();
}
2 changes: 2 additions & 0 deletions LibTest/async/Future/Future.value_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ check(value) {
}

main() {
asyncStart();
check(0);
check(1);
check(-5);
Expand All @@ -33,4 +34,5 @@ main() {
check(true);
check(const []);
check(const {'k1': 1, 'k2': 2});
asyncEnd();
}
1 change: 0 additions & 1 deletion LibTest/async/Future/any_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ main() {
c.complete(null);
}
}

Future f = Future.any(futures);

asyncStart();
Expand Down
1 change: 0 additions & 1 deletion LibTest/async/Future/any_A01_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ main() {
c.complete(true);
}
}

Future f = Future.any(futures);

asyncStart();
Expand Down
1 change: 0 additions & 1 deletion LibTest/async/Future/any_A01_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ main() {
c.complete(true);
}
}

Future f = Future.any(futures);

asyncStart();
Expand Down
2 changes: 2 additions & 0 deletions LibTest/async/Future/asStream_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ check(var value) {
}

main() {
asyncStart();
check(0);
check(1);
check(-5);
Expand All @@ -34,4 +35,5 @@ main() {
check(true);
check(const []);
check(const {'k1': 1, 'k2': 2});
asyncEnd();
}
18 changes: 8 additions & 10 deletions LibTest/async/Future/catchError_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ check(value) {
Future f = completer.future;

asyncStart();
f.catchError(
(Object error) {
Expect.fail("onError should not be called");
}
).then(
(x) {
Expect.identical(value, x);
asyncEnd();
}
);
f.catchError((Object error) {
Expect.fail("onError should not be called");
}).then((x) {
Expect.identical(value, x);
asyncEnd();
});

completer.complete(value);
}

main() {
asyncStart();
check(0);
check('');
check(false);
check([]);
check(new Object());
check(new Exception());
asyncEnd();
}

0 comments on commit dc603a5

Please sign in to comment.