Unverified Commit 0e76cb4c authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

prefer_void_to_null in flutter_test (#22847)

* prefer_void_to_null in flutter_test

* fix CI
parent dba54316
...@@ -12,7 +12,7 @@ import '../widgets/semantics_tester.dart'; ...@@ -12,7 +12,7 @@ import '../widgets/semantics_tester.dart';
void main() { void main() {
Future<Null> _dragSlider(WidgetTester tester, Key sliderKey) { Future<void> _dragSlider(WidgetTester tester, Key sliderKey) {
final Offset topLeft = tester.getTopLeft(find.byKey(sliderKey)); final Offset topLeft = tester.getTopLeft(find.byKey(sliderKey));
const double unit = CupertinoThumbPainter.radius; const double unit = CupertinoThumbPainter.radius;
const double delta = 3.0 * unit; const double delta = 3.0 * unit;
......
...@@ -545,7 +545,7 @@ void main() { ...@@ -545,7 +545,7 @@ void main() {
testWidgets('Avatar drawer works as expected on RawChip', (WidgetTester tester) async { testWidgets('Avatar drawer works as expected on RawChip', (WidgetTester tester) async {
final GlobalKey labelKey = GlobalKey(); final GlobalKey labelKey = GlobalKey();
Future<Null> pushChip({Widget avatar}) async { Future<void> pushChip({Widget avatar}) async {
return tester.pumpWidget( return tester.pumpWidget(
_wrapForChip( _wrapForChip(
child: Wrap( child: Wrap(
...@@ -659,7 +659,7 @@ void main() { ...@@ -659,7 +659,7 @@ void main() {
final UniqueKey labelKey = UniqueKey(); final UniqueKey labelKey = UniqueKey();
final UniqueKey deleteButtonKey = UniqueKey(); final UniqueKey deleteButtonKey = UniqueKey();
bool wasDeleted = false; bool wasDeleted = false;
Future<Null> pushChip({bool deletable = false}) async { Future<void> pushChip({bool deletable = false}) async {
return tester.pumpWidget( return tester.pumpWidget(
_wrapForChip( _wrapForChip(
child: Wrap( child: Wrap(
...@@ -774,7 +774,7 @@ void main() { ...@@ -774,7 +774,7 @@ void main() {
testWidgets('Selection with avatar works as expected on RawChip', (WidgetTester tester) async { testWidgets('Selection with avatar works as expected on RawChip', (WidgetTester tester) async {
bool selected = false; bool selected = false;
final UniqueKey labelKey = UniqueKey(); final UniqueKey labelKey = UniqueKey();
Future<Null> pushChip({Widget avatar, bool selectable = false}) async { Future<void> pushChip({Widget avatar, bool selectable = false}) async {
return tester.pumpWidget( return tester.pumpWidget(
_wrapForChip( _wrapForChip(
child: Wrap( child: Wrap(
...@@ -857,7 +857,7 @@ void main() { ...@@ -857,7 +857,7 @@ void main() {
testWidgets('Selection without avatar works as expected on RawChip', (WidgetTester tester) async { testWidgets('Selection without avatar works as expected on RawChip', (WidgetTester tester) async {
bool selected = false; bool selected = false;
final UniqueKey labelKey = UniqueKey(); final UniqueKey labelKey = UniqueKey();
Future<Null> pushChip({bool selectable = false}) async { Future<void> pushChip({bool selectable = false}) async {
return tester.pumpWidget( return tester.pumpWidget(
_wrapForChip( _wrapForChip(
child: Wrap( child: Wrap(
...@@ -933,7 +933,7 @@ void main() { ...@@ -933,7 +933,7 @@ void main() {
testWidgets('Activation works as expected on RawChip', (WidgetTester tester) async { testWidgets('Activation works as expected on RawChip', (WidgetTester tester) async {
bool selected = false; bool selected = false;
final UniqueKey labelKey = UniqueKey(); final UniqueKey labelKey = UniqueKey();
Future<Null> pushChip({Widget avatar, bool selectable = false}) async { Future<void> pushChip({Widget avatar, bool selectable = false}) async {
return tester.pumpWidget( return tester.pumpWidget(
_wrapForChip( _wrapForChip(
child: Wrap( child: Wrap(
......
...@@ -353,7 +353,7 @@ void main() { ...@@ -353,7 +353,7 @@ void main() {
group('Nested viewports (same orientation) showOnScreen', () { group('Nested viewports (same orientation) showOnScreen', () {
List<Widget> children; List<Widget> children;
Future<Null> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) { Future<void> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -346,7 +346,7 @@ void main() { ...@@ -346,7 +346,7 @@ void main() {
}); });
testWidgets('AnimatedSwitcher updates widgets without animating if they are isomorphic.', (WidgetTester tester) async { testWidgets('AnimatedSwitcher updates widgets without animating if they are isomorphic.', (WidgetTester tester) async {
Future<Null> pumpChild(Widget child) async { Future<void> pumpChild(Widget child) async {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
......
...@@ -1444,7 +1444,7 @@ void main() { ...@@ -1444,7 +1444,7 @@ void main() {
}); });
group('a11y copy/cut/paste', () { group('a11y copy/cut/paste', () {
Future<Null> _buildApp( Future<void> _buildApp(
MockTextSelectionControls controls, WidgetTester tester) { MockTextSelectionControls controls, WidgetTester tester) {
return tester.pumpWidget(MaterialApp( return tester.pumpWidget(MaterialApp(
home: EditableText( home: EditableText(
......
...@@ -126,7 +126,7 @@ void main() { ...@@ -126,7 +126,7 @@ void main() {
bool didReceivePointerDown; bool didReceivePointerDown;
bool didTap; bool didTap;
Future<Null> pumpWidgetTree(HitTestBehavior behavior) { Future<void> pumpWidgetTree(HitTestBehavior behavior) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -156,7 +156,7 @@ TestImage getTestImage(WidgetTester tester, Key key) { ...@@ -156,7 +156,7 @@ TestImage getTestImage(WidgetTester tester, Key key) {
return tester.renderObject<RenderImage>(find.byKey(key)).image; return tester.renderObject<RenderImage>(find.byKey(key)).image;
} }
Future<Null> pumpTreeToLayout(WidgetTester tester, Widget widget) { Future<void> pumpTreeToLayout(WidgetTester tester, Widget widget) {
const Duration pumpDuration = Duration(milliseconds: 0); const Duration pumpDuration = Duration(milliseconds: 0);
const EnginePhase pumpPhase = EnginePhase.layout; const EnginePhase pumpPhase = EnginePhase.layout;
return tester.pumpWidget(widget, pumpDuration, pumpPhase); return tester.pumpWidget(widget, pumpDuration, pumpPhase);
......
...@@ -697,7 +697,7 @@ void main() { ...@@ -697,7 +697,7 @@ void main() {
group('Nested SingleChildScrollView (same orientation) showOnScreen', () { group('Nested SingleChildScrollView (same orientation) showOnScreen', () {
List<Widget> children; List<Widget> children;
Future<Null> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) { Future<void> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -24,7 +24,7 @@ class _GenerationTextState extends State<GenerationText> { ...@@ -24,7 +24,7 @@ class _GenerationTextState extends State<GenerationText> {
// Creates a SliverList with `keys.length` children and each child having a key from `keys` and a text of `key:generation`. // Creates a SliverList with `keys.length` children and each child having a key from `keys` and a text of `key:generation`.
// The generation is increased with every call to this method. // The generation is increased with every call to this method.
Future<Null> test(WidgetTester tester, double offset, List<int> keys) { Future<void> test(WidgetTester tester, double offset, List<int> keys) {
globalGeneration += 1; globalGeneration += 1;
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
......
...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
Future<Null> test(WidgetTester tester, double offset) { Future<void> test(WidgetTester tester, double offset) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
Future<Null> test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) { Future<void> test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: textDirection, textDirection: textDirection,
......
...@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
Future<Null> test(WidgetTester tester, double offset, { double anchor = 0.0 }) { Future<void> test(WidgetTester tester, double offset, { double anchor = 0.0 }) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
This diff is collapsed.
...@@ -256,16 +256,15 @@ abstract class WidgetController { ...@@ -256,16 +256,15 @@ abstract class WidgetController {
/// ///
/// If the center of the widget is not exposed, this might send events to /// If the center of the widget is not exposed, this might send events to
/// another object. /// another object.
Future<Null> tap(Finder finder, { int pointer }) { Future<void> tap(Finder finder, { int pointer }) {
return tapAt(getCenter(finder), pointer: pointer); return tapAt(getCenter(finder), pointer: pointer);
} }
/// Dispatch a pointer down / pointer up sequence at the given location. /// Dispatch a pointer down / pointer up sequence at the given location.
Future<Null> tapAt(Offset location, { int pointer }) { Future<void> tapAt(Offset location, { int pointer }) {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer); final TestGesture gesture = await startGesture(location, pointer: pointer);
await gesture.up(); await gesture.up();
return null;
}); });
} }
...@@ -286,18 +285,17 @@ abstract class WidgetController { ...@@ -286,18 +285,17 @@ abstract class WidgetController {
/// ///
/// If the center of the widget is not exposed, this might send events to /// If the center of the widget is not exposed, this might send events to
/// another object. /// another object.
Future<Null> longPress(Finder finder, { int pointer }) { Future<void> longPress(Finder finder, { int pointer }) {
return longPressAt(getCenter(finder), pointer: pointer); return longPressAt(getCenter(finder), pointer: pointer);
} }
/// Dispatch a pointer down / pointer up sequence at the given location with /// Dispatch a pointer down / pointer up sequence at the given location with
/// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events. /// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events.
Future<Null> longPressAt(Offset location, { int pointer }) { Future<void> longPressAt(Offset location, { int pointer }) {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer); final TestGesture gesture = await startGesture(location, pointer: pointer);
await pump(kLongPressTimeout + kPressTimeout); await pump(kLongPressTimeout + kPressTimeout);
await gesture.up(); await gesture.up();
return null;
}); });
} }
...@@ -321,7 +319,7 @@ abstract class WidgetController { ...@@ -321,7 +319,7 @@ abstract class WidgetController {
/// opposite direction of the fling (e.g. dragging 200 pixels to the right, /// opposite direction of the fling (e.g. dragging 200 pixels to the right,
/// then fling to the left over 200 pixels, ending at the exact point that the /// then fling to the left over 200 pixels, ending at the exact point that the
/// drag started). /// drag started).
Future<Null> fling(Finder finder, Offset offset, double speed, { Future<void> fling(Finder finder, Offset offset, double speed, {
int pointer, int pointer,
Duration frameInterval = const Duration(milliseconds: 16), Duration frameInterval = const Duration(milliseconds: 16),
Offset initialOffset = Offset.zero, Offset initialOffset = Offset.zero,
...@@ -363,7 +361,7 @@ abstract class WidgetController { ...@@ -363,7 +361,7 @@ abstract class WidgetController {
/// opposite direction of the fling (e.g. dragging 200 pixels to the right, /// opposite direction of the fling (e.g. dragging 200 pixels to the right,
/// then fling to the left over 200 pixels, ending at the exact point that the /// then fling to the left over 200 pixels, ending at the exact point that the
/// drag started). /// drag started).
Future<Null> flingFrom(Offset startLocation, Offset offset, double speed, { Future<void> flingFrom(Offset startLocation, Offset offset, double speed, {
int pointer, int pointer,
Duration frameInterval = const Duration(milliseconds: 16), Duration frameInterval = const Duration(milliseconds: 16),
Offset initialOffset = Offset.zero, Offset initialOffset = Offset.zero,
...@@ -371,7 +369,7 @@ abstract class WidgetController { ...@@ -371,7 +369,7 @@ abstract class WidgetController {
}) { }) {
assert(offset.distance > 0.0); assert(offset.distance > 0.0);
assert(speed > 0.0); // speed is pixels/second assert(speed > 0.0); // speed is pixels/second
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
final TestPointer testPointer = TestPointer(pointer ?? _getNextPointer()); final TestPointer testPointer = TestPointer(pointer ?? _getNextPointer());
final HitTestResult result = hitTestOnBinding(startLocation); final HitTestResult result = hitTestOnBinding(startLocation);
const int kMoveCount = 50; // Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy const int kMoveCount = 50; // Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy
...@@ -394,7 +392,6 @@ abstract class WidgetController { ...@@ -394,7 +392,6 @@ abstract class WidgetController {
} }
} }
await sendEventToBinding(testPointer.up(timeStamp: Duration(milliseconds: timeStamp.round())), result); await sendEventToBinding(testPointer.up(timeStamp: Duration(milliseconds: timeStamp.round())), result);
return null;
}); });
} }
...@@ -407,7 +404,7 @@ abstract class WidgetController { ...@@ -407,7 +404,7 @@ abstract class WidgetController {
/// ///
/// See also [SchedulerBinding.endOfFrame], which returns a future that could /// See also [SchedulerBinding.endOfFrame], which returns a future that could
/// be appropriate to return in the implementation of this method. /// be appropriate to return in the implementation of this method.
Future<Null> pump(Duration duration); Future<void> pump(Duration duration);
/// Attempts to drag the given widget by the given offset, by /// Attempts to drag the given widget by the given offset, by
/// starting a drag in the middle of the widget. /// starting a drag in the middle of the widget.
...@@ -417,7 +414,7 @@ abstract class WidgetController { ...@@ -417,7 +414,7 @@ abstract class WidgetController {
/// ///
/// If you want the drag to end with a speed so that the gesture recognition /// If you want the drag to end with a speed so that the gesture recognition
/// system identifies the gesture as a fling, consider using [fling] instead. /// system identifies the gesture as a fling, consider using [fling] instead.
Future<Null> drag(Finder finder, Offset offset, { int pointer }) { Future<void> drag(Finder finder, Offset offset, { int pointer }) {
return dragFrom(getCenter(finder), offset, pointer: pointer); return dragFrom(getCenter(finder), offset, pointer: pointer);
} }
...@@ -427,13 +424,12 @@ abstract class WidgetController { ...@@ -427,13 +424,12 @@ abstract class WidgetController {
/// If you want the drag to end with a speed so that the gesture recognition /// If you want the drag to end with a speed so that the gesture recognition
/// system identifies the gesture as a fling, consider using [flingFrom] /// system identifies the gesture as a fling, consider using [flingFrom]
/// instead. /// instead.
Future<Null> dragFrom(Offset startLocation, Offset offset, { int pointer }) { Future<void> dragFrom(Offset startLocation, Offset offset, { int pointer }) {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(startLocation, pointer: pointer); final TestGesture gesture = await startGesture(startLocation, pointer: pointer);
assert(gesture != null); assert(gesture != null);
await gesture.moveBy(offset); await gesture.moveBy(offset);
await gesture.up(); await gesture.up();
return null;
}); });
} }
...@@ -468,10 +464,9 @@ abstract class WidgetController { ...@@ -468,10 +464,9 @@ abstract class WidgetController {
} }
/// Forwards the given pointer event to the binding. /// Forwards the given pointer event to the binding.
Future<Null> sendEventToBinding(PointerEvent event, HitTestResult result) { Future<void> sendEventToBinding(PointerEvent event, HitTestResult result) {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
binding.dispatchEvent(event, result); binding.dispatchEvent(event, result);
return null;
}); });
} }
...@@ -538,7 +533,7 @@ class LiveWidgetController extends WidgetController { ...@@ -538,7 +533,7 @@ class LiveWidgetController extends WidgetController {
LiveWidgetController(WidgetsBinding binding) : super(binding); LiveWidgetController(WidgetsBinding binding) : super(binding);
@override @override
Future<Null> pump(Duration duration) async { Future<void> pump(Duration duration) async {
if (duration != null) if (duration != null)
await Future<void>.delayed(duration); await Future<void>.delayed(duration);
binding.scheduleFrame(); binding.scheduleFrame();
......
...@@ -1506,7 +1506,7 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re ...@@ -1506,7 +1506,7 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re
} }
} }
class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, Null> { class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, RenderPhysicalModel> {
const _RendersOnPhysicalShape({ const _RendersOnPhysicalShape({
this.shape, this.shape,
this.elevation, this.elevation,
...@@ -1607,7 +1607,7 @@ class _ClipsWithBoundingRRect extends _MatchRenderObject<RenderClipPath, RenderC ...@@ -1607,7 +1607,7 @@ class _ClipsWithBoundingRRect extends _MatchRenderObject<RenderClipPath, RenderC
description.add('clips with bounding rounded rectangle with borderRadius: $borderRadius'); description.add('clips with bounding rounded rectangle with borderRadius: $borderRadius');
} }
class _ClipsWithShapeBorder extends _MatchRenderObject<RenderClipPath, Null> { class _ClipsWithShapeBorder extends _MatchRenderObject<RenderClipPath, RenderClipRRect> {
const _ClipsWithShapeBorder({@required this.shape}); const _ClipsWithShapeBorder({@required this.shape});
final ShapeBorder shape; final ShapeBorder shape;
......
...@@ -113,7 +113,7 @@ class TestPointer { ...@@ -113,7 +113,7 @@ class TestPointer {
/// Signature for a callback that can dispatch events and returns a future that /// Signature for a callback that can dispatch events and returns a future that
/// completes when the event dispatch is complete. /// completes when the event dispatch is complete.
typedef EventDispatcher = Future<Null> Function(PointerEvent event, HitTestResult result); typedef EventDispatcher = Future<void> Function(PointerEvent event, HitTestResult result);
/// Signature for callbacks that perform hit-testing at a given location. /// Signature for callbacks that perform hit-testing at a given location.
typedef HitTester = HitTestResult Function(Offset location); typedef HitTester = HitTestResult Function(Offset location);
...@@ -142,7 +142,7 @@ class TestGesture { ...@@ -142,7 +142,7 @@ class TestGesture {
assert(hitTester != null); assert(hitTester != null);
assert(dispatcher != null); assert(dispatcher != null);
TestGesture result; TestGesture result;
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
// dispatch down event // dispatch down event
final HitTestResult hitTestResult = hitTester(downLocation); final HitTestResult hitTestResult = hitTester(downLocation);
final TestPointer testPointer = TestPointer(pointer); final TestPointer testPointer = TestPointer(pointer);
...@@ -150,8 +150,7 @@ class TestGesture { ...@@ -150,8 +150,7 @@ class TestGesture {
// create a TestGesture // create a TestGesture
result = TestGesture._(dispatcher, hitTestResult, testPointer); result = TestGesture._(dispatcher, hitTestResult, testPointer);
return null; }).then<TestGesture>((void value) {
}).then<TestGesture>((Null value) {
return result; return result;
}, onError: (dynamic error, StackTrace stack) { }, onError: (dynamic error, StackTrace stack) {
return Future<TestGesture>.error(error, stack); return Future<TestGesture>.error(error, stack);
...@@ -163,14 +162,14 @@ class TestGesture { ...@@ -163,14 +162,14 @@ class TestGesture {
final TestPointer _pointer; final TestPointer _pointer;
/// Send a move event moving the pointer by the given offset. /// Send a move event moving the pointer by the given offset.
Future<Null> moveBy(Offset offset, { Duration timeStamp = Duration.zero }) { Future<void> moveBy(Offset offset, { Duration timeStamp = Duration.zero }) {
assert(_pointer._isDown); assert(_pointer._isDown);
return moveTo(_pointer.location + offset, timeStamp: timeStamp); return moveTo(_pointer.location + offset, timeStamp: timeStamp);
} }
/// Send a move event moving the pointer to the given location. /// Send a move event moving the pointer to the given location.
Future<Null> moveTo(Offset location, { Duration timeStamp = Duration.zero }) { Future<void> moveTo(Offset location, { Duration timeStamp = Duration.zero }) {
return TestAsyncUtils.guard<Null>(() { return TestAsyncUtils.guard<void>(() {
assert(_pointer._isDown); assert(_pointer._isDown);
return _dispatcher(_pointer.move(location, timeStamp: timeStamp), _result); return _dispatcher(_pointer.move(location, timeStamp: timeStamp), _result);
}); });
...@@ -179,12 +178,11 @@ class TestGesture { ...@@ -179,12 +178,11 @@ class TestGesture {
/// End the gesture by releasing the pointer. /// End the gesture by releasing the pointer.
/// ///
/// The object is no longer usable after this method has been called. /// The object is no longer usable after this method has been called.
Future<Null> up() { Future<void> up() {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
assert(_pointer._isDown); assert(_pointer._isDown);
await _dispatcher(_pointer.up(), _result); await _dispatcher(_pointer.up(), _result);
assert(!_pointer._isDown); assert(!_pointer._isDown);
return null;
}); });
} }
...@@ -193,12 +191,11 @@ class TestGesture { ...@@ -193,12 +191,11 @@ class TestGesture {
/// for instance). /// for instance).
/// ///
/// The object is no longer usable after this method has been called. /// The object is no longer usable after this method has been called.
Future<Null> cancel() { Future<void> cancel() {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
assert(_pointer._isDown); assert(_pointer._isDown);
await _dispatcher(_pointer.cancel(), _result); await _dispatcher(_pointer.cancel(), _result);
assert(!_pointer._isDown); assert(!_pointer._isDown);
return null;
}); });
} }
} }
...@@ -127,7 +127,7 @@ class TestTextInput { ...@@ -127,7 +127,7 @@ class TestTextInput {
/// Simulates the user pressing one of the [TextInputAction] buttons. /// Simulates the user pressing one of the [TextInputAction] buttons.
/// Does not check that the [TextInputAction] performed is an acceptable one /// Does not check that the [TextInputAction] performed is an acceptable one
/// based on the `inputAction` [setClientArgs]. /// based on the `inputAction` [setClientArgs].
Future<Null> receiveAction(TextInputAction action) async { Future<void> receiveAction(TextInputAction action) async {
return TestAsyncUtils.guard(() { return TestAsyncUtils.guard(() {
// Not using the `expect` function because in the case of a FlutterDriver // Not using the `expect` function because in the case of a FlutterDriver
// test this code does not run in a package:test test zone. // test this code does not run in a package:test test zone.
...@@ -135,7 +135,7 @@ class TestTextInput { ...@@ -135,7 +135,7 @@ class TestTextInput {
throw TestFailure('Tried to use TestTextInput with no keyboard attached. You must use WidgetTester.showKeyboard() first.'); throw TestFailure('Tried to use TestTextInput with no keyboard attached. You must use WidgetTester.showKeyboard() first.');
} }
final Completer<Null> completer = Completer<Null>(); final Completer<void> completer = Completer<void>();
BinaryMessages.handlePlatformMessage( BinaryMessages.handlePlatformMessage(
SystemChannels.textInput.name, SystemChannels.textInput.name,
......
...@@ -30,7 +30,7 @@ export 'package:test/test.dart' hide ...@@ -30,7 +30,7 @@ export 'package:test/test.dart' hide
isInstanceOf; // we have our own wrapper in matchers.dart isInstanceOf; // we have our own wrapper in matchers.dart
/// Signature for callback to [testWidgets] and [benchmarkWidgets]. /// Signature for callback to [testWidgets] and [benchmarkWidgets].
typedef WidgetTesterCallback = Future<Null> Function(WidgetTester widgetTester); typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
/// Runs the [callback] inside the Flutter test environment. /// Runs the [callback] inside the Flutter test environment.
/// ///
...@@ -114,7 +114,7 @@ void testWidgets(String description, WidgetTesterCallback callback, { ...@@ -114,7 +114,7 @@ void testWidgets(String description, WidgetTesterCallback callback, {
/// }); /// });
/// exit(0); /// exit(0);
/// } /// }
Future<Null> benchmarkWidgets(WidgetTesterCallback callback) { Future<void> benchmarkWidgets(WidgetTesterCallback callback) {
assert(() { assert(() {
print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓'); print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓');
print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇'); print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇');
...@@ -136,7 +136,7 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) { ...@@ -136,7 +136,7 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) {
return binding.runTest( return binding.runTest(
() => callback(tester), () => callback(tester),
tester._endOfTestVerifications, tester._endOfTestVerifications,
) ?? Future<Null>.value(); ) ?? Future<void>.value();
} }
/// Assert that `actual` matches `matcher`. /// Assert that `actual` matches `matcher`.
...@@ -217,11 +217,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -217,11 +217,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// ///
/// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how /// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how
/// this method works when the test is run with `flutter run`. /// this method works when the test is run with `flutter run`.
Future<Null> pumpWidget(Widget widget, [ Future<void> pumpWidget(Widget widget, [
Duration duration, Duration duration,
EnginePhase phase = EnginePhase.sendSemanticsUpdate, EnginePhase phase = EnginePhase.sendSemanticsUpdate,
]) { ]) {
return TestAsyncUtils.guard<Null>(() { return TestAsyncUtils.guard<void>(() {
binding.attachRootWidget(widget); binding.attachRootWidget(widget);
binding.scheduleFrame(); binding.scheduleFrame();
return binding.pump(duration, phase); return binding.pump(duration, phase);
...@@ -240,11 +240,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -240,11 +240,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how /// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how
/// this method works when the test is run with `flutter run`. /// this method works when the test is run with `flutter run`.
@override @override
Future<Null> pump([ Future<void> pump([
Duration duration, Duration duration,
EnginePhase phase = EnginePhase.sendSemanticsUpdate, EnginePhase phase = EnginePhase.sendSemanticsUpdate,
]) { ]) {
return TestAsyncUtils.guard<Null>(() => binding.pump(duration, phase)); return TestAsyncUtils.guard<void>(() => binding.pump(duration, phase));
} }
/// Repeatedly calls [pump] with the given `duration` until there are no /// Repeatedly calls [pump] with the given `duration` until there are no
...@@ -292,7 +292,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -292,7 +292,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
return true; return true;
}()); }());
int count = 0; int count = 0;
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
final DateTime endTime = binding.clock.fromNowBy(timeout); final DateTime endTime = binding.clock.fromNowBy(timeout);
do { do {
if (binding.clock.now().isAfter(endTime)) if (binding.clock.now().isAfter(endTime))
...@@ -300,7 +300,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -300,7 +300,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
await binding.pump(duration, phase); await binding.pump(duration, phase);
count += 1; count += 1;
} while (binding.hasScheduledFrame); } while (binding.hasScheduledFrame);
}).then<int>((Null _) => count); }).then<int>((void _) => count);
} }
/// Runs a [callback] that performs real asynchronous work. /// Runs a [callback] that performs real asynchronous work.
...@@ -350,10 +350,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -350,10 +350,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
} }
@override @override
Future<Null> sendEventToBinding(PointerEvent event, HitTestResult result) { Future<void> sendEventToBinding(PointerEvent event, HitTestResult result) {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
binding.dispatchEvent(event, result, source: TestBindingEventSource.test); binding.dispatchEvent(event, result, source: TestBindingEventSource.test);
return null;
}); });
} }
...@@ -484,8 +483,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -484,8 +483,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// ///
/// Does not run timers. May result in an infinite loop or run out of memory /// Does not run timers. May result in an infinite loop or run out of memory
/// if microtasks continue to recursively schedule new microtasks. /// if microtasks continue to recursively schedule new microtasks.
Future<Null> idle() { Future<void> idle() {
return TestAsyncUtils.guard<Null>(() => binding.idle()); return TestAsyncUtils.guard<void>(() => binding.idle());
} }
Set<Ticker> _tickers; Set<Ticker> _tickers;
...@@ -569,8 +568,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -569,8 +568,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// ///
/// Tests that just need to add text to widgets like [TextField] /// Tests that just need to add text to widgets like [TextField]
/// or [TextFormField] only need to call [enterText]. /// or [TextFormField] only need to call [enterText].
Future<Null> showKeyboard(Finder finder) async { Future<void> showKeyboard(Finder finder) async {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
final EditableTextState editable = state<EditableTextState>( final EditableTextState editable = state<EditableTextState>(
find.descendant( find.descendant(
of: finder, of: finder,
...@@ -592,8 +591,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -592,8 +591,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// ///
/// To just give [finder] the focus without entering any text, /// To just give [finder] the focus without entering any text,
/// see [showKeyboard]. /// see [showKeyboard].
Future<Null> enterText(Finder finder, String text) async { Future<void> enterText(Finder finder, String text) async {
return TestAsyncUtils.guard<Null>(() async { return TestAsyncUtils.guard<void>(() async {
await showKeyboard(finder); await showKeyboard(finder);
testTextInput.enterText(text); testTextInput.enterText(text);
await idle(); await idle();
......
...@@ -13,22 +13,22 @@ import 'package:test/test.dart' as real_test show expect; ...@@ -13,22 +13,22 @@ import 'package:test/test.dart' as real_test show expect;
// of this test is to see how we handle leaking APIs. // of this test is to see how we handle leaking APIs.
class TestAPI { class TestAPI {
Future<Null> testGuard1() { Future<Object> testGuard1() {
return TestAsyncUtils.guard(() async { return null; }); return TestAsyncUtils.guard<Object>(() async { return null; });
} }
Future<Null> testGuard2() { Future<Object> testGuard2() {
return TestAsyncUtils.guard(() async { return null; }); return TestAsyncUtils.guard<Object>(() async { return null; });
} }
} }
class TestAPISubclass extends TestAPI { class TestAPISubclass extends TestAPI {
Future<Null> testGuard3() { Future<Object> testGuard3() {
return TestAsyncUtils.guard(() async { return null; }); return TestAsyncUtils.guard<Object>(() async { return null; });
} }
} }
Future<Null> _guardedThrower() { Future<Object> _guardedThrower() {
return TestAsyncUtils.guard(() async { return TestAsyncUtils.guard<Object>(() async {
throw 'Hello'; throw 'Hello';
}); });
} }
...@@ -36,7 +36,7 @@ Future<Null> _guardedThrower() { ...@@ -36,7 +36,7 @@ Future<Null> _guardedThrower() {
void main() { void main() {
test('TestAsyncUtils - one class', () async { test('TestAsyncUtils - one class', () async {
final TestAPI testAPI = TestAPI(); final TestAPI testAPI = TestAPI();
Future<Null> f1, f2; Future<Object> f1, f2;
f1 = testAPI.testGuard1(); f1 = testAPI.testGuard1();
try { try {
f2 = testAPI.testGuard2(); f2 = testAPI.testGuard2();
...@@ -57,7 +57,7 @@ void main() { ...@@ -57,7 +57,7 @@ void main() {
test('TestAsyncUtils - two classes, all callers in superclass', () async { test('TestAsyncUtils - two classes, all callers in superclass', () async {
final TestAPI testAPI = TestAPISubclass(); final TestAPI testAPI = TestAPISubclass();
Future<Null> f1, f2; Future<Object> f1, f2;
f1 = testAPI.testGuard1(); f1 = testAPI.testGuard1();
try { try {
f2 = testAPI.testGuard2(); f2 = testAPI.testGuard2();
...@@ -78,7 +78,7 @@ void main() { ...@@ -78,7 +78,7 @@ void main() {
test('TestAsyncUtils - two classes, mixed callers', () async { test('TestAsyncUtils - two classes, mixed callers', () async {
final TestAPISubclass testAPI = TestAPISubclass(); final TestAPISubclass testAPI = TestAPISubclass();
Future<Null> f1, f2; Future<Object> f1, f2;
f1 = testAPI.testGuard1(); f1 = testAPI.testGuard1();
try { try {
f2 = testAPI.testGuard3(); f2 = testAPI.testGuard3();
...@@ -99,7 +99,7 @@ void main() { ...@@ -99,7 +99,7 @@ void main() {
test('TestAsyncUtils - expect() catches pending async work', () async { test('TestAsyncUtils - expect() catches pending async work', () async {
final TestAPI testAPI = TestAPISubclass(); final TestAPI testAPI = TestAPISubclass();
Future<Null> f1; Future<Object> f1;
f1 = testAPI.testGuard1(); f1 = testAPI.testGuard1();
try { try {
flutter_test.expect(0, 0); flutter_test.expect(0, 0);
...@@ -119,7 +119,7 @@ void main() { ...@@ -119,7 +119,7 @@ void main() {
}); });
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
Future<Null> f1, f2; Future<Object> f1, f2;
try { try {
f1 = tester.pump(); f1 = tester.pump();
f2 = tester.pump(); f2 = tester.pump();
...@@ -139,7 +139,7 @@ void main() { ...@@ -139,7 +139,7 @@ void main() {
}); });
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
Future<Null> f1; Future<Object> f1;
try { try {
f1 = tester.pump(); f1 = tester.pump();
TestAsyncUtils.verifyAllScopesClosed(); TestAsyncUtils.verifyAllScopesClosed();
...@@ -155,7 +155,7 @@ void main() { ...@@ -155,7 +155,7 @@ void main() {
}); });
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
Future<Null> f1; Future<Object> f1;
try { try {
f1 = tester.pump(); f1 = tester.pump();
TestAsyncUtils.verifyAllScopesClosed(); TestAsyncUtils.verifyAllScopesClosed();
......
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