Skip to content

Commit ae143ad

Browse files
Hide debug logs from a MemoryAllocations test that intentionally throws an exception (#113786)
1 parent 92d8b04 commit ae143ad

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/flutter/test/foundation/memory_allocations_test.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,29 @@ import 'dart:ui';
77
import 'package:flutter/foundation.dart';
88
import 'package:flutter_test/flutter_test.dart';
99

10+
class PrintOverrideTestBinding extends AutomatedTestWidgetsFlutterBinding {
11+
@override
12+
DebugPrintCallback get debugPrintOverride => _enablePrint ? debugPrint : _emptyPrint;
13+
14+
static void _emptyPrint(String? message, { int? wrapWidth }) {}
15+
16+
static bool _enablePrint = true;
17+
18+
static void runWithDebugPrintDisabled(void Function() f) {
19+
try {
20+
_enablePrint = false;
21+
f();
22+
} finally {
23+
_enablePrint = true;
24+
}
25+
}
26+
}
27+
1028
void main() {
1129
final MemoryAllocations ma = MemoryAllocations.instance;
1230

31+
PrintOverrideTestBinding();
32+
1333
setUp(() {
1434
assert(!ma.hasListeners);
1535
_checkSdkHandlersNotSet();
@@ -56,7 +76,9 @@ void main() {
5676
ma.addListener(badListener2);
5777
ma.addListener(listener2);
5878

59-
ma.dispatchObjectEvent(event);
79+
PrintOverrideTestBinding.runWithDebugPrintDisabled(
80+
() => ma.dispatchObjectEvent(event)
81+
);
6082
expect(log, <String>['badListener1', 'listener1', 'badListener2','listener2']);
6183
expect(tester.takeException(), contains('Multiple exceptions (2)'));
6284

0 commit comments

Comments
 (0)