Hide debug logs from a MemoryAllocations test that intentionally throws an exception (#113786)
This commit is contained in:
parent
92d8b04bac
commit
ae143ad8d1
@ -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() {
|
|||||||
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)'));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user