mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Migrate the tests of flutter_test to null-safety (#67058)
This commit is contained in:
parent
b63970c681
commit
cba170fbb2
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
@ -181,7 +179,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('custom minimum contrast guideline', () {
|
group('custom minimum contrast guideline', () {
|
||||||
Widget _icon ({IconData icon = Icons.search, Color color, Color background}) {
|
Widget _icon({IconData icon = Icons.search, required Color color, required Color background}) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
color: background,
|
color: background,
|
||||||
@ -189,7 +187,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _text ({String text = 'Text', Color color, Color background}) {
|
Widget _text({String text = 'Text', required Color color, required Color background}) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
color: background,
|
color: background,
|
||||||
@ -252,10 +250,10 @@ void main() {
|
|||||||
|
|
||||||
testWidgets('White on different colors, passing', (WidgetTester tester) async {
|
testWidgets('White on different colors, passing', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(_row(<Widget>[
|
await tester.pumpWidget(_row(<Widget>[
|
||||||
_icon (color: Colors.white, background: Colors.red[800], icon: Icons.more_horiz),
|
_icon(color: Colors.white, background: Colors.red[800]!, icon: Icons.more_horiz),
|
||||||
_icon (color: Colors.white, background: Colors.green[800], icon: Icons.description),
|
_icon(color: Colors.white, background: Colors.green[800]!, icon: Icons.description),
|
||||||
_icon (color: Colors.white, background: Colors.blue[800], icon: Icons.image),
|
_icon(color: Colors.white, background: Colors.blue[800]!, icon: Icons.image),
|
||||||
_icon (color: Colors.white, background: Colors.purple[800], icon: Icons.beach_access),
|
_icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||||
@ -263,10 +261,10 @@ void main() {
|
|||||||
|
|
||||||
testWidgets('White on different colors, failing', (WidgetTester tester) async {
|
testWidgets('White on different colors, failing', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(_row(<Widget>[
|
await tester.pumpWidget(_row(<Widget>[
|
||||||
_icon (color: Colors.white, background: Colors.red[200], icon: Icons.more_horiz),
|
_icon(color: Colors.white, background: Colors.red[200]!, icon: Icons.more_horiz),
|
||||||
_icon (color: Colors.white, background: Colors.green[400], icon: Icons.description),
|
_icon(color: Colors.white, background: Colors.green[400]!, icon: Icons.description),
|
||||||
_icon (color: Colors.white, background: Colors.blue[600], icon: Icons.image),
|
_icon(color: Colors.white, background: Colors.blue[600]!, icon: Icons.image),
|
||||||
_icon (color: Colors.white, background: Colors.purple[800], icon: Icons.beach_access),
|
_icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
test('$WidgetsBinding initializes with $AutomatedTestWidgetsFlutterBinding when FLUTTER_TEST is defined but null', () {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{'FLUTTER_TEST': null});
|
|
||||||
expect(WidgetsBinding.instance, isA<AutomatedTestWidgetsFlutterBinding>());
|
|
||||||
});
|
|
||||||
}
|
|
@ -2,9 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
@ -2,11 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/semantics.dart';
|
import 'package:flutter/semantics.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'flutter_test_config.dart' as real_test;
|
import 'flutter_test_config.dart' as real_test;
|
||||||
|
|
||||||
void main() => real_test.runTest();
|
void main() => real_test.runTest();
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -38,7 +36,7 @@ Future<void> main() async {
|
|||||||
await binding.runTest(() async {
|
await binding.runTest(() async {
|
||||||
final DebugPrintCallback oldDebugPrint = debugPrint;
|
final DebugPrintCallback oldDebugPrint = debugPrint;
|
||||||
try {
|
try {
|
||||||
debugPrint = (String message, {int wrapWidth}) {};
|
debugPrint = (String? message, {int? wrapWidth}) {};
|
||||||
debugPrintStack(
|
debugPrintStack(
|
||||||
stackTrace: await getMangledStack(),
|
stackTrace: await getMangledStack(),
|
||||||
);
|
);
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io' as io;
|
import 'dart:io' as io;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
@ -35,7 +33,7 @@ const List<int> _kSizeFailurePngBytes =
|
|||||||
0, 0, 73, 69, 78, 68, 174, 66, 96, 130];
|
0, 0, 73, 69, 78, 68, 174, 66, 96, 130];
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
MemoryFileSystem fs;
|
late MemoryFileSystem fs;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
final FileSystemStyle style = io.Platform.isWindows
|
final FileSystemStyle style = io.Platform.isWindows
|
||||||
@ -86,7 +84,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('LocalFileComparator', () {
|
group('LocalFileComparator', () {
|
||||||
LocalFileComparator comparator;
|
late LocalFileComparator comparator;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
comparator = LocalFileComparator(fs.file(fix('/golden_test.dart')).uri, pathStyle: fs.path.style);
|
comparator = LocalFileComparator(fs.file(fix('/golden_test.dart')).uri, pathStyle: fs.path.style);
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -24,7 +22,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Input PointerHoverEvent', (WidgetTester tester) async {
|
testWidgets('Input PointerHoverEvent', (WidgetTester tester) async {
|
||||||
PointerHoverEvent hoverEvent;
|
PointerHoverEvent? hoverEvent;
|
||||||
await tester.pumpWidget(MaterialApp(home: MouseRegion(
|
await tester.pumpWidget(MaterialApp(home: MouseRegion(
|
||||||
child: const Text('Test'),
|
child: const Text('Test'),
|
||||||
onHover: (PointerHoverEvent event){
|
onHover: (PointerHoverEvent event){
|
||||||
@ -37,7 +35,7 @@ void main() {
|
|||||||
// for mouse input without a down event, moveTo generates a hover event
|
// for mouse input without a down event, moveTo generates a hover event
|
||||||
await gesture.moveTo(location);
|
await gesture.moveTo(location);
|
||||||
expect(hoverEvent, isNotNull);
|
expect(hoverEvent, isNotNull);
|
||||||
expect(hoverEvent.position, location);
|
expect(hoverEvent!.position, location);
|
||||||
await gesture.removePointer();
|
await gesture.removePointer();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -38,7 +36,7 @@ class AnimateSample extends StatefulWidget {
|
|||||||
|
|
||||||
class _AnimateSampleState extends State<AnimateSample>
|
class _AnimateSampleState extends State<AnimateSample>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
AnimationController _controller;
|
late AnimationController _controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -68,9 +66,9 @@ void main() {
|
|||||||
test('Test pump on LiveWidgetController', () async {
|
test('Test pump on LiveWidgetController', () async {
|
||||||
runApp(MaterialApp(home: Center(child: CountButton())));
|
runApp(MaterialApp(home: Center(child: CountButton())));
|
||||||
|
|
||||||
await SchedulerBinding.instance.endOfFrame;
|
await SchedulerBinding.instance!.endOfFrame;
|
||||||
final WidgetController controller =
|
final WidgetController controller =
|
||||||
LiveWidgetController(WidgetsBinding.instance);
|
LiveWidgetController(WidgetsBinding.instance!);
|
||||||
await controller.tap(find.text('Counter 0'));
|
await controller.tap(find.text('Counter 0'));
|
||||||
expect(find.text('Counter 0'), findsOneWidget);
|
expect(find.text('Counter 0'), findsOneWidget);
|
||||||
expect(find.text('Counter 1'), findsNothing);
|
expect(find.text('Counter 1'), findsNothing);
|
||||||
@ -81,9 +79,9 @@ void main() {
|
|||||||
|
|
||||||
test('Test pumpAndSettle on LiveWidgetController', () async {
|
test('Test pumpAndSettle on LiveWidgetController', () async {
|
||||||
runApp(MaterialApp(home: Center(child: AnimateSample())));
|
runApp(MaterialApp(home: Center(child: AnimateSample())));
|
||||||
await SchedulerBinding.instance.endOfFrame;
|
await SchedulerBinding.instance!.endOfFrame;
|
||||||
final WidgetController controller =
|
final WidgetController controller =
|
||||||
LiveWidgetController(WidgetsBinding.instance);
|
LiveWidgetController(WidgetsBinding.instance!);
|
||||||
expect(find.text('Value: 1.0'), findsNothing);
|
expect(find.text('Value: 1.0'), findsNothing);
|
||||||
await controller.pumpAndSettle();
|
await controller.pumpAndSettle();
|
||||||
expect(find.text('Value: 1.0'), findsOneWidget);
|
expect(find.text('Value: 1.0'), findsOneWidget);
|
||||||
@ -101,9 +99,9 @@ void main() {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await SchedulerBinding.instance.endOfFrame;
|
await SchedulerBinding.instance!.endOfFrame;
|
||||||
final WidgetController controller =
|
final WidgetController controller =
|
||||||
LiveWidgetController(WidgetsBinding.instance);
|
LiveWidgetController(WidgetsBinding.instance!);
|
||||||
|
|
||||||
final Offset location = controller.getCenter(find.text('test'));
|
final Offset location = controller.getCenter(find.text('test'));
|
||||||
final List<PointerEventRecord> records = <PointerEventRecord>[
|
final List<PointerEventRecord> records = <PointerEventRecord>[
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
@ -13,9 +11,8 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
|
|
||||||
/// Class that makes it easy to mock common toStringDeep behavior.
|
/// Class that makes it easy to mock common toStringDeep behavior.
|
||||||
class _MockToStringDeep {
|
class _MockToStringDeep {
|
||||||
_MockToStringDeep(String str) {
|
_MockToStringDeep(String str) : _lines = <String>[] {
|
||||||
final List<String> lines = str.split('\n');
|
final List<String> lines = str.split('\n');
|
||||||
_lines = <String>[];
|
|
||||||
for (int i = 0; i < lines.length - 1; ++i)
|
for (int i = 0; i < lines.length - 1; ++i)
|
||||||
_lines.add('${lines[i]}\n');
|
_lines.add('${lines[i]}\n');
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ class _MockToStringDeep {
|
|||||||
/// Lines in the message to display when [toStringDeep] is called.
|
/// Lines in the message to display when [toStringDeep] is called.
|
||||||
/// For correct toStringDeep behavior, each line should be terminated with a
|
/// For correct toStringDeep behavior, each line should be terminated with a
|
||||||
/// line break.
|
/// line break.
|
||||||
List<String> _lines;
|
final List<String> _lines;
|
||||||
|
|
||||||
String toStringDeep({ String prefixLineOne = '', String prefixOtherLines = '' }) {
|
String toStringDeep({ String prefixLineOne = '', String prefixOtherLines = '' }) {
|
||||||
final StringBuffer sb = StringBuffer();
|
final StringBuffer sb = StringBuffer();
|
||||||
@ -340,7 +337,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('matchesGoldenFile', () {
|
group('matchesGoldenFile', () {
|
||||||
_FakeComparator comparator;
|
late _FakeComparator comparator;
|
||||||
|
|
||||||
Widget boilerplate(Widget child) {
|
Widget boilerplate(Widget child) {
|
||||||
return Directionality(
|
return Directionality(
|
||||||
@ -561,8 +558,7 @@ void main() {
|
|||||||
currentValueLength: 10,
|
currentValueLength: 10,
|
||||||
maxValueLength: 15,
|
maxValueLength: 15,
|
||||||
);
|
);
|
||||||
final _FakeSemanticsNode node = _FakeSemanticsNode();
|
final _FakeSemanticsNode node = _FakeSemanticsNode(data);
|
||||||
node.data = data;
|
|
||||||
|
|
||||||
expect(node, matchesSemantics(
|
expect(node, matchesSemantics(
|
||||||
rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
|
rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
|
||||||
@ -666,9 +662,9 @@ enum _ComparatorInvocation {
|
|||||||
|
|
||||||
class _FakeComparator implements GoldenFileComparator {
|
class _FakeComparator implements GoldenFileComparator {
|
||||||
_ComparatorBehavior behavior = _ComparatorBehavior.returnTrue;
|
_ComparatorBehavior behavior = _ComparatorBehavior.returnTrue;
|
||||||
_ComparatorInvocation invocation;
|
_ComparatorInvocation? invocation;
|
||||||
Uint8List imageBytes;
|
Uint8List? imageBytes;
|
||||||
Uri golden;
|
Uri? golden;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> compare(Uint8List imageBytes, Uri golden) {
|
Future<bool> compare(Uint8List imageBytes, Uri golden) {
|
||||||
@ -683,7 +679,6 @@ class _FakeComparator implements GoldenFileComparator {
|
|||||||
case _ComparatorBehavior.throwTestFailure:
|
case _ComparatorBehavior.throwTestFailure:
|
||||||
throw TestFailure('fake message');
|
throw TestFailure('fake message');
|
||||||
}
|
}
|
||||||
return Future<bool>.value(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -695,12 +690,14 @@ class _FakeComparator implements GoldenFileComparator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Uri getTestUri(Uri key, int version) {
|
Uri getTestUri(Uri key, int? version) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FakeSemanticsNode extends SemanticsNode {
|
class _FakeSemanticsNode extends SemanticsNode {
|
||||||
|
_FakeSemanticsNode(this.data);
|
||||||
|
|
||||||
SemanticsData data;
|
SemanticsData data;
|
||||||
@override
|
@override
|
||||||
SemanticsData getSemanticsData() => data;
|
SemanticsData getSemanticsData() => data;
|
||||||
@ -709,7 +706,7 @@ class _FakeSemanticsNode extends SemanticsNode {
|
|||||||
@immutable
|
@immutable
|
||||||
class _CustomColor extends Color {
|
class _CustomColor extends Color {
|
||||||
const _CustomColor(int value, {this.isEqual}) : super(value);
|
const _CustomColor(int value, {this.isEqual}) : super(value);
|
||||||
final bool isEqual;
|
final bool? isEqual;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) => isEqual ?? super == other;
|
bool operator ==(Object other) => isEqual ?? super == other;
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@ -75,9 +73,9 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _RestorableWidget extends StatefulWidget {
|
class _RestorableWidget extends StatefulWidget {
|
||||||
const _RestorableWidget({Key key, this.restorationId}) : super(key: key);
|
const _RestorableWidget({Key? key, this.restorationId}) : super(key: key);
|
||||||
|
|
||||||
final String restorationId;
|
final String? restorationId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_RestorableWidget> createState() => _RestorableWidgetState();
|
State<_RestorableWidget> createState() => _RestorableWidgetState();
|
||||||
@ -90,7 +88,7 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
|
|||||||
double doubleValue = 1.0; // Not restorable.
|
double doubleValue = 1.0; // Not restorable.
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void restoreState(RestorationBucket oldBucket, bool initialRestore) {
|
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
|
||||||
registerForRestoration(stringValue, 'string');
|
registerForRestoration(stringValue, 'string');
|
||||||
registerForRestoration(intValue, 'int');
|
registerForRestoration(intValue, 'int');
|
||||||
}
|
}
|
||||||
@ -109,5 +107,5 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get restorationId => widget.restorationId;
|
String? get restorationId => widget.restorationId;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
@ -22,7 +20,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
throw null;
|
throw Object();
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||||
expect(reportExpectCall(stack, information), 0);
|
expect(reportExpectCall(stack, information), 0);
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@ -18,17 +16,17 @@ import 'package:test_api/test_api.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<Object> testGuard1() {
|
Future<Object?> testGuard1() {
|
||||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
return TestAsyncUtils.guard<Object?>(() async { return null; });
|
||||||
}
|
}
|
||||||
Future<Object> testGuard2() {
|
Future<Object?> testGuard2() {
|
||||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
return TestAsyncUtils.guard<Object?>(() async { return null; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestAPISubclass extends TestAPI {
|
class TestAPISubclass extends TestAPI {
|
||||||
Future<Object> testGuard3() {
|
Future<Object?> testGuard3() {
|
||||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
return TestAsyncUtils.guard<Object?>(() async { return null; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ Future<Object> _guardedThrower() {
|
|||||||
void main() {
|
void main() {
|
||||||
test('TestAsyncUtils - one class', () async {
|
test('TestAsyncUtils - one class', () async {
|
||||||
final TestAPI testAPI = TestAPI();
|
final TestAPI testAPI = TestAPI();
|
||||||
Future<Object> f1, f2;
|
Future<Object?>? f1, f2;
|
||||||
f1 = testAPI.testGuard1();
|
f1 = testAPI.testGuard1();
|
||||||
try {
|
try {
|
||||||
f2 = testAPI.testGuard2();
|
f2 = testAPI.testGuard2();
|
||||||
@ -63,7 +61,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<Object> f1, f2;
|
Future<Object?>? f1, f2;
|
||||||
f1 = testAPI.testGuard1();
|
f1 = testAPI.testGuard1();
|
||||||
try {
|
try {
|
||||||
f2 = testAPI.testGuard2();
|
f2 = testAPI.testGuard2();
|
||||||
@ -85,7 +83,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<Object> f1, f2;
|
Future<Object?>? f1, f2;
|
||||||
f1 = testAPI.testGuard1();
|
f1 = testAPI.testGuard1();
|
||||||
try {
|
try {
|
||||||
f2 = testAPI.testGuard3();
|
f2 = testAPI.testGuard3();
|
||||||
@ -107,7 +105,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<Object> f1;
|
Future<Object?>? f1;
|
||||||
f1 = testAPI.testGuard1();
|
f1 = testAPI.testGuard1();
|
||||||
try {
|
try {
|
||||||
flutter_test.expect(0, 0);
|
flutter_test.expect(0, 0);
|
||||||
@ -128,7 +126,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||||
Future<Object> f1, f2;
|
Future<Object?>? f1, f2;
|
||||||
try {
|
try {
|
||||||
f1 = tester.pump();
|
f1 = tester.pump();
|
||||||
f2 = tester.pump();
|
f2 = tester.pump();
|
||||||
@ -170,7 +168,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||||
Future<Object> f1;
|
Future<Object?>? f1;
|
||||||
try {
|
try {
|
||||||
f1 = tester.pump();
|
f1 = tester.pump();
|
||||||
TestAsyncUtils.verifyAllScopesClosed();
|
TestAsyncUtils.verifyAllScopesClosed();
|
||||||
@ -195,7 +193,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||||
Future<Object> f1;
|
Future<Object?>? f1;
|
||||||
try {
|
try {
|
||||||
f1 = tester.pump();
|
f1 = tester.pump();
|
||||||
TestAsyncUtils.verifyAllScopesClosed();
|
TestAsyncUtils.verifyAllScopesClosed();
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import '../config_test_utils.dart';
|
import '../config_test_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import '../../config_test_utils.dart';
|
import '../../config_test_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'config_test_utils.dart';
|
import 'config_test_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void testConfig(
|
void testConfig(
|
||||||
String description,
|
String description,
|
||||||
String expectedStringValue, {
|
String? expectedStringValue, {
|
||||||
Map<Type, dynamic> otherExpectedValues = const <Type, dynamic>{int: isNull},
|
Map<Type, dynamic> otherExpectedValues = const <Type, dynamic>{int: isNull},
|
||||||
}) {
|
}) {
|
||||||
final String actualStringValue = Zone.current[String] as String;
|
final String actualStringValue = Zone.current[String] as String;
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
Future<void> main(FutureOr<void> testMain()) async {
|
Future<void> main(FutureOr<void> testMain()) async {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import '../config_test_utils.dart';
|
import '../config_test_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
Future<void> main(FutureOr<void> testMain()) async {
|
Future<void> main(FutureOr<void> testMain()) async {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import '../config_test_utils.dart';
|
import '../config_test_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
@ -30,7 +28,7 @@ void main() {
|
|||||||
testWidgets('completes when matcher completes', (WidgetTester tester) async {
|
testWidgets('completes when matcher completes', (WidgetTester tester) async {
|
||||||
final Completer<void> completer = Completer<void>();
|
final Completer<void> completer = Completer<void>();
|
||||||
final Future<void> future = expectLater(null, FakeMatcher(completer));
|
final Future<void> future = expectLater(null, FakeMatcher(completer));
|
||||||
String result;
|
String? result;
|
||||||
future.then<void>((void value) {
|
future.then<void>((void value) {
|
||||||
result = '123';
|
result = '123';
|
||||||
});
|
});
|
||||||
@ -62,7 +60,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('fails with a descriptive message', (WidgetTester tester) async {
|
testWidgets('fails with a descriptive message', (WidgetTester tester) async {
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.text('foo', skipOffstage: false), findsOneWidget);
|
expect(find.text('foo', skipOffstage: false), findsOneWidget);
|
||||||
} on TestFailure catch (e) {
|
} on TestFailure catch (e) {
|
||||||
@ -85,7 +83,7 @@ void main() {
|
|||||||
testWidgets('fails with a descriptive message', (WidgetTester tester) async {
|
testWidgets('fails with a descriptive message', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||||
|
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.text('foo', skipOffstage: false), findsNothing);
|
expect(find.text('foo', skipOffstage: false), findsNothing);
|
||||||
} on TestFailure catch (e) {
|
} on TestFailure catch (e) {
|
||||||
@ -103,7 +101,7 @@ void main() {
|
|||||||
testWidgets('fails with a descriptive message when skipping', (WidgetTester tester) async {
|
testWidgets('fails with a descriptive message when skipping', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||||
|
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.text('foo'), findsNothing);
|
expect(find.text('foo'), findsNothing);
|
||||||
} on TestFailure catch (e) {
|
} on TestFailure catch (e) {
|
||||||
@ -156,13 +154,13 @@ void main() {
|
|||||||
|
|
||||||
testWidgets('pumpFrames', (WidgetTester tester) async {
|
testWidgets('pumpFrames', (WidgetTester tester) async {
|
||||||
final List<int> logPaints = <int>[];
|
final List<int> logPaints = <int>[];
|
||||||
int initial;
|
int? initial;
|
||||||
|
|
||||||
final Widget target = _AlwaysAnimating(
|
final Widget target = _AlwaysAnimating(
|
||||||
onPaint: () {
|
onPaint: () {
|
||||||
final int current = SchedulerBinding.instance.currentFrameTimeStamp.inMicroseconds;
|
final int current = SchedulerBinding.instance!.currentFrameTimeStamp.inMicroseconds;
|
||||||
initial ??= current;
|
initial ??= current;
|
||||||
logPaints.add(current - initial);
|
logPaints.add(current - initial!);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -182,7 +180,7 @@ void main() {
|
|||||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||||
|
|
||||||
const String customDescription = 'custom description';
|
const String customDescription = 'custom description';
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.byElementPredicate((_) => false, description: customDescription), findsOneWidget);
|
expect(find.byElementPredicate((_) => false, description: customDescription), findsOneWidget);
|
||||||
} on TestFailure catch (e) {
|
} on TestFailure catch (e) {
|
||||||
@ -199,7 +197,7 @@ void main() {
|
|||||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||||
|
|
||||||
const String customDescription = 'custom description';
|
const String customDescription = 'custom description';
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.byWidgetPredicate((_) => false, description: customDescription), findsOneWidget);
|
expect(find.byWidgetPredicate((_) => false, description: customDescription), findsOneWidget);
|
||||||
} on TestFailure catch (e) {
|
} on TestFailure catch (e) {
|
||||||
@ -250,7 +248,7 @@ void main() {
|
|||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.descendant(
|
expect(find.descendant(
|
||||||
of: find.widgetWithText(Column, 'foo'),
|
of: find.widgetWithText(Column, 'foo'),
|
||||||
@ -312,7 +310,7 @@ void main() {
|
|||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
TestFailure failure;
|
late TestFailure failure;
|
||||||
try {
|
try {
|
||||||
expect(find.ancestor(
|
expect(find.ancestor(
|
||||||
of: find.text('bar'),
|
of: find.text('bar'),
|
||||||
@ -554,7 +552,7 @@ void main() {
|
|||||||
|
|
||||||
group('runAsync', () {
|
group('runAsync', () {
|
||||||
testWidgets('works with no async calls', (WidgetTester tester) async {
|
testWidgets('works with no async calls', (WidgetTester tester) async {
|
||||||
String value;
|
String? value;
|
||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
value = '123';
|
value = '123';
|
||||||
});
|
});
|
||||||
@ -574,14 +572,14 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('propagates return values', (WidgetTester tester) async {
|
testWidgets('propagates return values', (WidgetTester tester) async {
|
||||||
final String value = await tester.runAsync<String>(() async {
|
final String? value = await tester.runAsync<String>(() async {
|
||||||
return '123';
|
return '123';
|
||||||
});
|
});
|
||||||
expect(value, '123');
|
expect(value, '123');
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('reports errors via framework', (WidgetTester tester) async {
|
testWidgets('reports errors via framework', (WidgetTester tester) async {
|
||||||
final String value = await tester.runAsync<String>(() async {
|
final String? value = await tester.runAsync<String>(() async {
|
||||||
throw ArgumentError();
|
throw ArgumentError();
|
||||||
});
|
});
|
||||||
expect(value, isNull);
|
expect(value, isNull);
|
||||||
@ -630,7 +628,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('verifyTickersWereDisposed control test', (WidgetTester tester) async {
|
testWidgets('verifyTickersWereDisposed control test', (WidgetTester tester) async {
|
||||||
FlutterError error;
|
late FlutterError error;
|
||||||
final Ticker ticker = tester.createTicker((Duration duration) {});
|
final Ticker ticker = tester.createTicker((Duration duration) {});
|
||||||
ticker.start();
|
ticker.start();
|
||||||
try {
|
try {
|
||||||
@ -685,7 +683,7 @@ void main() {
|
|||||||
|
|
||||||
group('TargetPlatformVariant', () {
|
group('TargetPlatformVariant', () {
|
||||||
int numberOfVariationsRun = 0;
|
int numberOfVariationsRun = 0;
|
||||||
TargetPlatform origTargetPlatform;
|
TargetPlatform? origTargetPlatform;
|
||||||
|
|
||||||
setUpAll((){
|
setUpAll((){
|
||||||
origTargetPlatform = debugDefaultTargetPlatformOverride;
|
origTargetPlatform = debugDefaultTargetPlatformOverride;
|
||||||
@ -717,7 +715,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('Pending timer', () {
|
group('Pending timer', () {
|
||||||
TestExceptionReporter currentExceptionReporter;
|
late TestExceptionReporter currentExceptionReporter;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
currentExceptionReporter = reportTestException;
|
currentExceptionReporter = reportTestException;
|
||||||
});
|
});
|
||||||
@ -727,7 +725,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Throws assertion message without code', () async {
|
test('Throws assertion message without code', () async {
|
||||||
FlutterErrorDetails flutterErrorDetails;
|
late FlutterErrorDetails flutterErrorDetails;
|
||||||
reportTestException = (FlutterErrorDetails details, String testDescription) {
|
reportTestException = (FlutterErrorDetails details, String testDescription) {
|
||||||
flutterErrorDetails = details;
|
flutterErrorDetails = details;
|
||||||
};
|
};
|
||||||
@ -738,8 +736,8 @@ void main() {
|
|||||||
expect(timer.isActive, true);
|
expect(timer.isActive, true);
|
||||||
}, () {});
|
}, () {});
|
||||||
|
|
||||||
expect(flutterErrorDetails?.exception, isA<AssertionError>());
|
expect(flutterErrorDetails.exception, isA<AssertionError>());
|
||||||
expect(flutterErrorDetails?.exception?.message, 'A Timer is still pending even after the widget tree was disposed.');
|
expect(flutterErrorDetails.exception!.message, 'A Timer is still pending even after the widget tree was disposed.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -750,8 +748,8 @@ class FakeMatcher extends AsyncMatcher {
|
|||||||
final Completer<void> completer;
|
final Completer<void> completer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String> matchAsync(dynamic object) {
|
Future<String?> matchAsync(dynamic object) {
|
||||||
return completer.future.then<String>((void value) {
|
return completer.future.then<String?>((void value) {
|
||||||
return object?.toString();
|
return object?.toString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -761,14 +759,14 @@ class FakeMatcher extends AsyncMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SingleTickerTest extends StatefulWidget {
|
class _SingleTickerTest extends StatefulWidget {
|
||||||
const _SingleTickerTest({Key key}) : super(key: key);
|
const _SingleTickerTest({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SingleTickerTestState createState() => _SingleTickerTestState();
|
_SingleTickerTestState createState() => _SingleTickerTestState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerProviderStateMixin {
|
class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerProviderStateMixin {
|
||||||
AnimationController controller;
|
late AnimationController controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -788,10 +786,10 @@ class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerP
|
|||||||
class _AlwaysAnimating extends StatefulWidget {
|
class _AlwaysAnimating extends StatefulWidget {
|
||||||
const _AlwaysAnimating({
|
const _AlwaysAnimating({
|
||||||
this.child,
|
this.child,
|
||||||
this.onPaint,
|
required this.onPaint,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Widget child;
|
final Widget? child;
|
||||||
final VoidCallback onPaint;
|
final VoidCallback onPaint;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -799,7 +797,7 @@ class _AlwaysAnimating extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AlwaysAnimatingState extends State<_AlwaysAnimating> with SingleTickerProviderStateMixin {
|
class _AlwaysAnimatingState extends State<_AlwaysAnimating> with SingleTickerProviderStateMixin {
|
||||||
AnimationController _controller;
|
late AnimationController _controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -821,7 +819,7 @@ class _AlwaysAnimatingState extends State<_AlwaysAnimating> with SingleTickerPro
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: _controller.view,
|
animation: _controller.view,
|
||||||
builder: (BuildContext context, Widget child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return CustomPaint(
|
return CustomPaint(
|
||||||
painter: _AlwaysRepaint(widget.onPaint),
|
painter: _AlwaysRepaint(widget.onPaint),
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
|
@ -2,18 +2,15 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.9
|
|
||||||
|
|
||||||
import 'dart:ui' as ui show window;
|
import 'dart:ui' as ui show window;
|
||||||
import 'dart:ui' show Size, Locale, WindowPadding, AccessibilityFeatures, Brightness;
|
import 'dart:ui' show Size, Locale, WindowPadding, AccessibilityFeatures, Brightness;
|
||||||
|
|
||||||
import 'package:flutter/widgets.dart' show WidgetsBinding;
|
import 'package:flutter/widgets.dart' show WidgetsBinding;
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('TestWindow can handle new methods without breaking', () {
|
test('TestWindow can handle new methods without breaking', () {
|
||||||
final dynamic testWindow = TestWindow(window: ui.window);
|
final dynamic testWindow = TestWindow(window: ui.window); // ignore: unnecessary_nullable_for_final_variable_declarations
|
||||||
expect(testWindow.someNewProperty, null);
|
expect(testWindow.someNewProperty, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -23,7 +20,7 @@ void main() {
|
|||||||
realValue: ui.window.devicePixelRatio,
|
realValue: ui.window.devicePixelRatio,
|
||||||
fakeValue: 2.5,
|
fakeValue: 2.5,
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.devicePixelRatio;
|
return WidgetsBinding.instance!.window.devicePixelRatio;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
|
||||||
binding.window.devicePixelRatioTestValue = fakeValue;
|
binding.window.devicePixelRatioTestValue = fakeValue;
|
||||||
@ -37,7 +34,7 @@ void main() {
|
|||||||
realValue: ui.window.physicalSize,
|
realValue: ui.window.physicalSize,
|
||||||
fakeValue: const Size(50, 50),
|
fakeValue: const Size(50, 50),
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.physicalSize;
|
return WidgetsBinding.instance!.window.physicalSize;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, Size fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, Size fakeValue) {
|
||||||
binding.window.physicalSizeTestValue = fakeValue;
|
binding.window.physicalSizeTestValue = fakeValue;
|
||||||
@ -51,7 +48,7 @@ void main() {
|
|||||||
realValue: ui.window.viewInsets,
|
realValue: ui.window.viewInsets,
|
||||||
fakeValue: const FakeWindowPadding(),
|
fakeValue: const FakeWindowPadding(),
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.viewInsets;
|
return WidgetsBinding.instance!.window.viewInsets;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, WindowPadding fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, WindowPadding fakeValue) {
|
||||||
binding.window.viewInsetsTestValue = fakeValue;
|
binding.window.viewInsetsTestValue = fakeValue;
|
||||||
@ -65,7 +62,7 @@ void main() {
|
|||||||
realValue: ui.window.padding,
|
realValue: ui.window.padding,
|
||||||
fakeValue: const FakeWindowPadding(),
|
fakeValue: const FakeWindowPadding(),
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.padding;
|
return WidgetsBinding.instance!.window.padding;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, WindowPadding fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, WindowPadding fakeValue) {
|
||||||
binding.window.paddingTestValue = fakeValue;
|
binding.window.paddingTestValue = fakeValue;
|
||||||
@ -79,7 +76,7 @@ void main() {
|
|||||||
realValue: ui.window.locale,
|
realValue: ui.window.locale,
|
||||||
fakeValue: const Locale('fake_language_code'),
|
fakeValue: const Locale('fake_language_code'),
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.locale;
|
return WidgetsBinding.instance!.window.locale;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, Locale fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, Locale fakeValue) {
|
||||||
binding.window.localeTestValue = fakeValue;
|
binding.window.localeTestValue = fakeValue;
|
||||||
@ -93,7 +90,7 @@ void main() {
|
|||||||
realValue: ui.window.locales,
|
realValue: ui.window.locales,
|
||||||
fakeValue: <Locale>[const Locale('fake_language_code')],
|
fakeValue: <Locale>[const Locale('fake_language_code')],
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.locales;
|
return WidgetsBinding.instance!.window.locales;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, List<Locale> fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, List<Locale> fakeValue) {
|
||||||
binding.window.localesTestValue = fakeValue;
|
binding.window.localesTestValue = fakeValue;
|
||||||
@ -107,7 +104,7 @@ void main() {
|
|||||||
realValue: ui.window.textScaleFactor,
|
realValue: ui.window.textScaleFactor,
|
||||||
fakeValue: 2.5,
|
fakeValue: 2.5,
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.textScaleFactor;
|
return WidgetsBinding.instance!.window.textScaleFactor;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
|
||||||
binding.window.textScaleFactorTestValue = fakeValue;
|
binding.window.textScaleFactorTestValue = fakeValue;
|
||||||
@ -121,7 +118,7 @@ void main() {
|
|||||||
realValue: ui.window.alwaysUse24HourFormat,
|
realValue: ui.window.alwaysUse24HourFormat,
|
||||||
fakeValue: !ui.window.alwaysUse24HourFormat,
|
fakeValue: !ui.window.alwaysUse24HourFormat,
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.alwaysUse24HourFormat;
|
return WidgetsBinding.instance!.window.alwaysUse24HourFormat;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, bool fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, bool fakeValue) {
|
||||||
binding.window.alwaysUse24HourFormatTestValue = fakeValue;
|
binding.window.alwaysUse24HourFormatTestValue = fakeValue;
|
||||||
@ -135,7 +132,7 @@ void main() {
|
|||||||
realValue: ui.window.defaultRouteName,
|
realValue: ui.window.defaultRouteName,
|
||||||
fakeValue: 'fake_route',
|
fakeValue: 'fake_route',
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.defaultRouteName;
|
return WidgetsBinding.instance!.window.defaultRouteName;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, String fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, String fakeValue) {
|
||||||
binding.window.defaultRouteNameTestValue = fakeValue;
|
binding.window.defaultRouteNameTestValue = fakeValue;
|
||||||
@ -149,7 +146,7 @@ void main() {
|
|||||||
realValue: ui.window.accessibilityFeatures,
|
realValue: ui.window.accessibilityFeatures,
|
||||||
fakeValue: const FakeAccessibilityFeatures(),
|
fakeValue: const FakeAccessibilityFeatures(),
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.accessibilityFeatures;
|
return WidgetsBinding.instance!.window.accessibilityFeatures;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, AccessibilityFeatures fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, AccessibilityFeatures fakeValue) {
|
||||||
binding.window.accessibilityFeaturesTestValue = fakeValue;
|
binding.window.accessibilityFeaturesTestValue = fakeValue;
|
||||||
@ -163,7 +160,7 @@ void main() {
|
|||||||
realValue: Brightness.light,
|
realValue: Brightness.light,
|
||||||
fakeValue: Brightness.dark,
|
fakeValue: Brightness.dark,
|
||||||
propertyRetriever: () {
|
propertyRetriever: () {
|
||||||
return WidgetsBinding.instance.window.platformBrightness;
|
return WidgetsBinding.instance!.window.platformBrightness;
|
||||||
},
|
},
|
||||||
propertyFaker: (TestWidgetsFlutterBinding binding, Brightness fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, Brightness fakeValue) {
|
||||||
binding.window.platformBrightnessTestValue = fakeValue;
|
binding.window.platformBrightnessTestValue = fakeValue;
|
||||||
@ -184,20 +181,20 @@ void main() {
|
|||||||
testWindow.clearAllTestValues();
|
testWindow.clearAllTestValues();
|
||||||
|
|
||||||
// Verify that the window once again reports real property values.
|
// Verify that the window once again reports real property values.
|
||||||
expect(WidgetsBinding.instance.window.devicePixelRatio, originalDevicePixelRatio);
|
expect(WidgetsBinding.instance!.window.devicePixelRatio, originalDevicePixelRatio);
|
||||||
expect(WidgetsBinding.instance.window.textScaleFactor, originalTextScaleFactor);
|
expect(WidgetsBinding.instance!.window.textScaleFactor, originalTextScaleFactor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyThatTestWindowCanFakeProperty<WindowPropertyType>({
|
void verifyThatTestWindowCanFakeProperty<WindowPropertyType>({
|
||||||
@required WidgetTester tester,
|
required WidgetTester tester,
|
||||||
@required WindowPropertyType realValue,
|
required WindowPropertyType? realValue,
|
||||||
@required WindowPropertyType fakeValue,
|
required WindowPropertyType fakeValue,
|
||||||
@required WindowPropertyType Function() propertyRetriever,
|
required WindowPropertyType? Function() propertyRetriever,
|
||||||
@required Function(TestWidgetsFlutterBinding, WindowPropertyType fakeValue) propertyFaker,
|
required Function(TestWidgetsFlutterBinding, WindowPropertyType fakeValue) propertyFaker,
|
||||||
}) {
|
}) {
|
||||||
WindowPropertyType propertyBeforeFaking;
|
WindowPropertyType? propertyBeforeFaking;
|
||||||
WindowPropertyType propertyAfterFaking;
|
WindowPropertyType? propertyAfterFaking;
|
||||||
|
|
||||||
propertyBeforeFaking = propertyRetriever();
|
propertyBeforeFaking = propertyRetriever();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user