* Add structured errors in Animations, TabView, ChangeNotifier * Add structured error on MaterialPageRoute, BoxBorder, DecorationImagePainter, TextSpan * Add structured errors in Debug * Fix test errors * Add structured errors in Scaffold and Stepper * Add structured errors in part of Rendering Layer * Fix failing test due to FloatingPoint precision * Fix failing tests due to precision error and not using final * Fix failing test due to floating precision error with RegEx instead * Add structured error in CustomLayout and increase test coverage * Add structured error & its test in ListBody * Add structured error in ProxyBox and increase test coverage * Add structured error message in Viewport * Fix styles and add more assertions on ErrorHint and DiagnosticProperty * Add structured error in scheduler/binding and scheduler/ticker Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Add structured error in AssetBundle and TextInput Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Add structured errors in several widgets #1 Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Remove unused import Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Add assertions on hint messages Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Fix catch spacing Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Add structured error in several widgets part 2 and increase code coverage Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Add structured error in flutter_test/widget_tester * Fix floating precision accuracy by using RegExp Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Remove todo to add tests in Scaffold showBottomSheet Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Fix reviews by indenting lines and fixing the assertion orders Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Fix failing tests due to renaming class Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Try skipping the NetworkBundleTest Signed-off-by: Albertus Angga Raharja <albertusangga@google.com> * Remove leading space in material/debug error hint Signed-off-by: Albertus Angga Raharja <albertusangga@google.com>
This commit is contained in:
committed by
GitHub
parent
734ddd3103
commit
b31ca1aaca
@@ -636,13 +636,16 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
if (_tickers != null) {
|
||||
for (Ticker ticker in _tickers) {
|
||||
if (ticker.isActive) {
|
||||
throw FlutterError(
|
||||
'A Ticker was active $when.\n'
|
||||
'All Tickers must be disposed. Tickers used by AnimationControllers '
|
||||
'should be disposed by calling dispose() on the AnimationController itself. '
|
||||
'Otherwise, the ticker will leak.\n'
|
||||
'The offending ticker was: ${ticker.toString(debugIncludeStack: true)}'
|
||||
);
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('A Ticker was active $when.'),
|
||||
ErrorDescription('All Tickers must be disposed.'),
|
||||
ErrorHint(
|
||||
'Tickers used by AnimationControllers '
|
||||
'should be disposed by calling dispose() on the AnimationController itself. '
|
||||
'Otherwise, the ticker will leak.'
|
||||
),
|
||||
ticker.describeForError('The offending ticker was')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -656,13 +659,20 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
void _verifySemanticsHandlesWereDisposed() {
|
||||
assert(_lastRecordedSemanticsHandles != null);
|
||||
if (binding.pipelineOwner.debugOutstandingSemanticsHandles > _lastRecordedSemanticsHandles) {
|
||||
throw FlutterError(
|
||||
'A SemanticsHandle was active at the end of the test.\n'
|
||||
'All SemanticsHandle instances must be disposed by calling dispose() on '
|
||||
'the SemanticsHandle. If your test uses SemanticsTester, it is '
|
||||
'sufficient to call dispose() on SemanticsTester. Otherwise, the '
|
||||
'existing handle will leak into another test and alter its behavior.'
|
||||
);
|
||||
// TODO(jacobr): The hint for this one causes a change in line breaks but
|
||||
// I think it is for the best.
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('A SemanticsHandle was active at the end of the test.'),
|
||||
ErrorDescription(
|
||||
'All SemanticsHandle instances must be disposed by calling dispose() on '
|
||||
'the SemanticsHandle.'
|
||||
),
|
||||
ErrorHint(
|
||||
'If your test uses SemanticsTester, it is '
|
||||
'sufficient to call dispose() on SemanticsTester. Otherwise, the '
|
||||
'existing handle will leak into another test and alter its behavior.'
|
||||
)
|
||||
]);
|
||||
}
|
||||
_lastRecordedSemanticsHandles = null;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'dart:ui';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:test_api/test_api.dart' as test_package;
|
||||
import 'package:test_api/src/frontend/async_matcher.dart' show AsyncMatcher;
|
||||
@@ -662,6 +663,41 @@ void main() {
|
||||
expect(find.text('Item 15', skipOffstage: true), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('verifyTickersWereDisposed control test', (WidgetTester tester) async {
|
||||
FlutterError error;
|
||||
final Ticker ticker = tester.createTicker((Duration duration) {});
|
||||
ticker.start();
|
||||
try {
|
||||
tester.verifyTickersWereDisposed('');
|
||||
} on FlutterError catch (e) {
|
||||
error = e;
|
||||
} finally {
|
||||
expect(error, isNotNull);
|
||||
expect(error.diagnostics.length, 4);
|
||||
expect(error.diagnostics[2].level, DiagnosticLevel.hint);
|
||||
expect(
|
||||
error.diagnostics[2].toStringDeep(),
|
||||
'Tickers used by AnimationControllers should be disposed by\n'
|
||||
'calling dispose() on the AnimationController itself. Otherwise,\n'
|
||||
'the ticker will leak.\n',
|
||||
);
|
||||
expect(error.diagnostics.last, isInstanceOf<DiagnosticsProperty<Ticker>>());
|
||||
expect(error.diagnostics.last.value, ticker);
|
||||
expect(error.toStringDeep(), startsWith(
|
||||
'FlutterError\n'
|
||||
' A Ticker was active .\n'
|
||||
' All Tickers must be disposed.\n'
|
||||
' Tickers used by AnimationControllers should be disposed by\n'
|
||||
' calling dispose() on the AnimationController itself. Otherwise,\n'
|
||||
' the ticker will leak.\n'
|
||||
' The offending ticker was:\n'
|
||||
' _TestTicker()\n',
|
||||
));
|
||||
}
|
||||
ticker.stop();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
class FakeMatcher extends AsyncMatcher {
|
||||
@@ -679,3 +715,28 @@ class FakeMatcher extends AsyncMatcher {
|
||||
@override
|
||||
Description describe(Description description) => description.add('--fake--');
|
||||
}
|
||||
|
||||
class _SingleTickerTest extends StatefulWidget {
|
||||
const _SingleTickerTest({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SingleTickerTestState createState() => _SingleTickerTestState();
|
||||
}
|
||||
|
||||
class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerProviderStateMixin {
|
||||
AnimationController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 100),
|
||||
) ;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user