Unverified Commit ae143ad8 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Hide debug logs from a MemoryAllocations test that intentionally throws an exception (#113786)

parent 92d8b04b
...@@ -7,9 +7,29 @@ import 'dart:ui'; ...@@ -7,9 +7,29 @@ import 'dart:ui';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class PrintOverrideTestBinding extends AutomatedTestWidgetsFlutterBinding {
@override
DebugPrintCallback get debugPrintOverride => _enablePrint ? debugPrint : _emptyPrint;
static void _emptyPrint(String? message, { int? wrapWidth }) {}
static bool _enablePrint = true;
static void runWithDebugPrintDisabled(void Function() f) {
try {
_enablePrint = false;
f();
} finally {
_enablePrint = true;
}
}
}
void main() { void main() {
final MemoryAllocations ma = MemoryAllocations.instance; final MemoryAllocations ma = MemoryAllocations.instance;
PrintOverrideTestBinding();
setUp(() { setUp(() {
assert(!ma.hasListeners); assert(!ma.hasListeners);
_checkSdkHandlersNotSet(); _checkSdkHandlersNotSet();
...@@ -56,7 +76,9 @@ void main() { ...@@ -56,7 +76,9 @@ void main() {
ma.addListener(badListener2); ma.addListener(badListener2);
ma.addListener(listener2); ma.addListener(listener2);
ma.dispatchObjectEvent(event); PrintOverrideTestBinding.runWithDebugPrintDisabled(
() => ma.dispatchObjectEvent(event)
);
expect(log, <String>['badListener1', 'listener1', 'badListener2','listener2']); expect(log, <String>['badListener1', 'listener1', 'badListener2','listener2']);
expect(tester.takeException(), contains('Multiple exceptions (2)')); expect(tester.takeException(), contains('Multiple exceptions (2)'));
......
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