Unverified Commit f83df74b authored by sjindel-google's avatar sjindel-google Committed by GitHub

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)
parent 366dcb15
...@@ -63,6 +63,9 @@ Future<void> main() async { ...@@ -63,6 +63,9 @@ Future<void> main() async {
expect(endFramesBegun, equals(startFramesBegun + 1)); expect(endFramesBegun, equals(startFramesBegun + 1));
expect(endFramesDrawn, equals(startFramesDrawn + 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);
}); });
} }
...@@ -133,8 +133,10 @@ void testWidgets( ...@@ -133,8 +133,10 @@ void testWidgets(
/// If the callback is asynchronous, make sure you `await` the call /// If the callback is asynchronous, make sure you `await` the call
/// to [benchmarkWidgets], otherwise it won't run! /// to [benchmarkWidgets], otherwise it won't run!
/// ///
/// Benchmarks must not be run in checked mode. To avoid this, this /// Benchmarks must not be run in checked mode, because the performance is not
/// function will print a big message if it is run in checked mode. /// 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: /// Example:
/// ///
...@@ -152,8 +154,11 @@ void testWidgets( ...@@ -152,8 +154,11 @@ void testWidgets(
/// }); /// });
/// exit(0); /// exit(0);
/// } /// }
Future<void> benchmarkWidgets(WidgetTesterCallback callback) { Future<void> benchmarkWidgets(WidgetTesterCallback callback, {bool mayRunWithAsserts = false}) {
assert(() { assert(() {
if (mayRunWithAsserts)
return true;
print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓'); print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓');
print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇'); print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇');
print('┡╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┦'); print('┡╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┦');
......
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