From f83df74b6ba876d65858973b301a7520217036ed Mon Sep 17 00:00:00 2001 From: sjindel-google Date: Thu, 6 Jun 2019 19:39:32 +0200 Subject: [PATCH] Don't print warning message when running benchmarks test. (#33842) # Description Currently the benchmarks test prints a scary warning message, even when it passes, that a benchmark is being run with asserts enabled. Normally we don't want developers to do this, because the performance of code with asserts is not characteristic of what end-users will experience. However, we need to unit-test benchmarkWidgets, so I've added a contraindicated option to suppress the warning for the test. # Related Issues 25049 (comment) --- packages/flutter/test/scheduler/benchmarks_test.dart | 5 ++++- packages/flutter_test/lib/src/widget_tester.dart | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/flutter/test/scheduler/benchmarks_test.dart b/packages/flutter/test/scheduler/benchmarks_test.dart index 4539a8fad3..70472b7ff6 100644 --- a/packages/flutter/test/scheduler/benchmarks_test.dart +++ b/packages/flutter/test/scheduler/benchmarks_test.dart @@ -63,6 +63,9 @@ Future main() async { expect(endFramesBegun, equals(startFramesBegun + 1)); expect(endFramesDrawn, equals(startFramesDrawn + 1)); - }); + }, + // We are not interested in the performance of the "benchmark", we are just + // testing the behavior. So it's OK that asserts are enabled. + mayRunWithAsserts: true); }); } diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 45142cf533..0000f91131 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -133,8 +133,10 @@ void testWidgets( /// If the callback is asynchronous, make sure you `await` the call /// to [benchmarkWidgets], otherwise it won't run! /// -/// Benchmarks must not be run in checked mode. To avoid this, this -/// function will print a big message if it is run in checked mode. +/// Benchmarks must not be run in checked mode, because the performance is not +/// representative. To avoid this, this function will print a big message if it +/// is run in checked mode. Unit tests of this method pass `mayRunWithAsserts`, +/// but it should not be used for actual benchmarking. /// /// Example: /// @@ -152,8 +154,11 @@ void testWidgets( /// }); /// exit(0); /// } -Future benchmarkWidgets(WidgetTesterCallback callback) { +Future benchmarkWidgets(WidgetTesterCallback callback, {bool mayRunWithAsserts = false}) { assert(() { + if (mayRunWithAsserts) + return true; + print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓'); print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇'); print('┡╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┦');