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)
This commit is contained in:
@@ -63,6 +63,9 @@ Future<void> 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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<void> benchmarkWidgets(WidgetTesterCallback callback) {
|
||||
Future<void> benchmarkWidgets(WidgetTesterCallback callback, {bool mayRunWithAsserts = false}) {
|
||||
assert(() {
|
||||
if (mayRunWithAsserts)
|
||||
return true;
|
||||
|
||||
print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓');
|
||||
print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇');
|
||||
print('┡╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┦');
|
||||
|
||||
Reference in New Issue
Block a user