Commit d709f18c authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Do not swallow exceptions in guarded functions. (#9064)

parent a94e995f
......@@ -88,7 +88,7 @@ void main() {
),
);
await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0);
await tester.fling(find.text('X'), const Offset(0.0, 300.0), 1000.0);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await tester.pump(const Duration(seconds: 1));
......
......@@ -380,6 +380,7 @@ class WidgetController {
Future<Null> dragFrom(Point startLocation, Offset offset, { int pointer }) {
return TestAsyncUtils.guard(() async {
final TestGesture gesture = await startGesture(startLocation, pointer: pointer);
assert(gesture != null);
await gesture.moveBy(offset);
await gesture.up();
return null;
......
......@@ -67,7 +67,7 @@ class TestAsyncUtils {
final _AsyncScope scope = new _AsyncScope(StackTrace.current, zone);
_scopeStack.add(scope);
final Future<Null> result = scope.zone.run(body);
void completionHandler(dynamic error, StackTrace stack) {
Future<Null> completionHandler(dynamic error, StackTrace stack) {
assert(_scopeStack.isNotEmpty);
assert(_scopeStack.contains(scope));
bool leaked = false;
......@@ -101,10 +101,13 @@ class TestAsyncUtils {
}
throw new FlutterError(message.toString().trimRight());
}
if (error != null)
return new Future<Null>.error(error, stack);
return new Future<Null>.value(null);
}
return result.then<Null>(
(Null value) {
completionHandler(null, null);
return completionHandler(null, null);
},
onError: completionHandler
);
......
......@@ -140,9 +140,8 @@ class TestGesture {
}) async {
assert(hitTester != null);
assert(dispatcher != null);
final Completer<TestGesture> completer = new Completer<TestGesture>();
TestGesture result;
TestAsyncUtils.guard(() async {
return TestAsyncUtils.guard(() async {
// dispatch down event
final HitTestResult hitTestResult = hitTester(downLocation);
final TestPointer testPointer = new TestPointer(pointer);
......@@ -151,10 +150,11 @@ class TestGesture {
// create a TestGesture
result = new TestGesture._(dispatcher, hitTestResult, testPointer);
return null;
}).whenComplete(() {
completer.complete(result);
}).then<TestGesture>((Null value) {
return result;
}, onError: (dynamic error, StackTrace stack) {
return new Future<TestGesture>.error(error, stack);
});
return completer.future;
}
final EventDispatcher _dispatcher;
......
......@@ -27,13 +27,9 @@ class TestAPISubclass extends TestAPI {
}
}
Future<Null> helperFunction(WidgetTester tester) async {
await tester.pump();
}
Future<Null> guardedHelper(WidgetTester tester) {
Future<Null> _guardedThrower() {
return TestAsyncUtils.guard(() async {
await tester.pumpWidget(new Text('Hello'));
throw 'Hello';
});
}
......@@ -174,5 +170,14 @@ void main() {
await f1;
});
testWidgets('TestAsyncUtils - guard body can throw', (WidgetTester tester) async {
try {
await _guardedThrower();
expect(false, true); // _guardedThrower should throw and we shouldn't reach here
} on String catch (s) {
expect(s, 'Hello');
}
});
// see also dev/manual_tests/test_data which contains tests run by the flutter_tools tests for 'flutter test'
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment