Commit 440ddef6 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Regression tests should verify that debug are not set (#7090)

parent 94de7e30
...@@ -7,40 +7,55 @@ import 'package:flutter/rendering.dart'; ...@@ -7,40 +7,55 @@ import 'package:flutter/rendering.dart';
export 'package:flutter/foundation.dart' show debugPrint; export 'package:flutter/foundation.dart' show debugPrint;
// Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset()
// function below.
const Color _kDebugPaintSizeColor = const Color(0xFF00FFFF);
const Color _kDebugPaintSpacingColor = const Color(0x90909090);
const Color _kDebugPaintPaddingColor = const Color(0x900090FF);
const Color _kDebugPaintPaddingInnerEdgeColor = const Color(0xFF0090FF);
const Color _kDebugPaintArrowColor = const Color(0xFFFFFF00);
const Color _kDebugPaintAlphabeticBaselineColor = const Color(0xFF00FF00);
const Color _kDebugPaintIdeographicBaselineColor = const Color(0xFFFFD000);
const Color _kDebugPaintLayerBordersColor = const Color(0xFFFF9800);
const int _kDebugPaintPointersColorValue = 0x00BBBB;
const HSVColor _kDebugCurrentRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0);
const double _kDebugRepaintRainbowHueIncrement = 2.0;
/// Causes each RenderBox to paint a box around its bounds, and some extra /// Causes each RenderBox to paint a box around its bounds, and some extra
/// boxes, such as RenderPadding, to draw construction lines. /// boxes, such as RenderPadding, to draw construction lines.
bool debugPaintSizeEnabled = false; bool debugPaintSizeEnabled = false;
/// The color to use when painting RenderObject bounds. /// The color to use when painting RenderObject bounds.
Color debugPaintSizeColor = const Color(0xFF00FFFF); Color debugPaintSizeColor = _kDebugPaintSizeColor;
/// The color to use when painting some boxes that just add space (e.g. an empty /// The color to use when painting some boxes that just add space (e.g. an empty
/// RenderConstrainedBox or RenderPadding). /// RenderConstrainedBox or RenderPadding).
Color debugPaintSpacingColor = const Color(0x90909090); Color debugPaintSpacingColor = _kDebugPaintSpacingColor;
/// The color to use when painting RenderPadding edges. /// The color to use when painting RenderPadding edges.
Color debugPaintPaddingColor = const Color(0x900090FF); Color debugPaintPaddingColor = _kDebugPaintPaddingColor;
/// The color to use when painting RenderPadding edges. /// The color to use when painting RenderPadding edges.
Color debugPaintPaddingInnerEdgeColor = const Color(0xFF0090FF); Color debugPaintPaddingInnerEdgeColor = _kDebugPaintPaddingInnerEdgeColor;
/// The color to use when painting the arrows used to show RenderPositionedBox alignment. /// The color to use when painting the arrows used to show RenderPositionedBox alignment.
Color debugPaintArrowColor = const Color(0xFFFFFF00); Color debugPaintArrowColor = _kDebugPaintArrowColor;
/// Causes each RenderBox to paint a line at each of its baselines. /// Causes each RenderBox to paint a line at each of its baselines.
bool debugPaintBaselinesEnabled = false; bool debugPaintBaselinesEnabled = false;
/// The color to use when painting alphabetic baselines. /// The color to use when painting alphabetic baselines.
Color debugPaintAlphabeticBaselineColor = const Color(0xFF00FF00); Color debugPaintAlphabeticBaselineColor = _kDebugPaintAlphabeticBaselineColor;
/// The color ot use when painting ideographic baselines. /// The color ot use when painting ideographic baselines.
Color debugPaintIdeographicBaselineColor = const Color(0xFFFFD000); Color debugPaintIdeographicBaselineColor = _kDebugPaintIdeographicBaselineColor;
/// Causes each Layer to paint a box around its bounds. /// Causes each Layer to paint a box around its bounds.
bool debugPaintLayerBordersEnabled = false; bool debugPaintLayerBordersEnabled = false;
/// The color to use when painting Layer borders. /// The color to use when painting Layer borders.
Color debugPaintLayerBordersColor = const Color(0xFFFF9800); Color debugPaintLayerBordersColor = _kDebugPaintLayerBordersColor;
/// Causes objects like [RenderPointerListener] to flash while they are being /// Causes objects like [RenderPointerListener] to flash while they are being
/// tapped. This can be useful to see how large the hit box is, e.g. when /// tapped. This can be useful to see how large the hit box is, e.g. when
...@@ -51,16 +66,16 @@ Color debugPaintLayerBordersColor = const Color(0xFFFF9800); ...@@ -51,16 +66,16 @@ Color debugPaintLayerBordersColor = const Color(0xFFFF9800);
bool debugPaintPointersEnabled = false; bool debugPaintPointersEnabled = false;
/// The color to use when reporting pointers for [debugPaintPointersEnabled]. /// The color to use when reporting pointers for [debugPaintPointersEnabled].
int debugPaintPointersColorValue = 0x00BBBB; int debugPaintPointersColorValue = _kDebugPaintPointersColorValue;
/// Overlay a rotating set of colors when repainting layers in checked mode. /// Overlay a rotating set of colors when repainting layers in checked mode.
bool debugRepaintRainbowEnabled = false; bool debugRepaintRainbowEnabled = false;
/// The current color to overlay when repainting a layer. /// The current color to overlay when repainting a layer.
HSVColor debugCurrentRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0); HSVColor debugCurrentRepaintColor = _kDebugCurrentRepaintColor;
/// The amount to increment the hue of the current repaint color. /// The amount to increment the hue of the current repaint color.
double debugRepaintRainbowHueIncrement = 2.0; double debugRepaintRainbowHueIncrement = _kDebugRepaintRainbowHueIncrement;
/// Log the call stacks that mark render objects as needing paint. /// Log the call stacks that mark render objects as needing paint.
bool debugPrintMarkNeedsPaintStacks = false; bool debugPrintMarkNeedsPaintStacks = false;
...@@ -89,3 +104,39 @@ List<String> debugDescribeTransform(Matrix4 transform) { ...@@ -89,3 +104,39 @@ List<String> debugDescribeTransform(Matrix4 transform) {
matrix.removeLast(); matrix.removeLast();
return matrix; return matrix;
} }
/// Returns true if none of the rendering library debug variables have been changed.
///
/// This function is used by the test framework to ensure that debug variables
/// haven't been inadvertently changed.
///
/// See [https://docs.flutter.io/flutter/rendering/rendering-library.html] for
/// a complete list.
bool debugAssertAllRenderVarsUnset(String reason) {
assert(() {
if (debugPaintSizeEnabled ||
debugPaintBaselinesEnabled ||
debugPaintLayerBordersEnabled ||
debugPaintPointersEnabled ||
debugRepaintRainbowEnabled ||
debugPrintMarkNeedsPaintStacks ||
debugPrintMarkNeedsLayoutStacks ||
debugCheckIntrinsicSizes ||
debugProfilePaintsEnabled ||
debugPaintSizeColor != _kDebugPaintSizeColor ||
debugPaintSpacingColor != _kDebugPaintSpacingColor ||
debugPaintPaddingColor != _kDebugPaintPaddingColor ||
debugPaintPaddingInnerEdgeColor != _kDebugPaintPaddingInnerEdgeColor ||
debugPaintArrowColor != _kDebugPaintArrowColor ||
debugPaintAlphabeticBaselineColor != _kDebugPaintAlphabeticBaselineColor ||
debugPaintIdeographicBaselineColor != _kDebugPaintIdeographicBaselineColor ||
debugPaintLayerBordersColor != _kDebugPaintLayerBordersColor ||
debugPaintPointersColorValue != _kDebugPaintPointersColorValue ||
debugCurrentRepaintColor != _kDebugCurrentRepaintColor ||
debugRepaintRainbowHueIncrement != _kDebugRepaintRainbowHueIncrement) {
throw new FlutterError(reason);
}
return true;
});
return true;
}
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
// Any changes to this file should be reflected in the debugAssertAllSchedulerVarsUnset()
// function below.
/// Print a banner at the beginning of each frame. /// Print a banner at the beginning of each frame.
/// ///
/// Frames triggered by the engine and handler by the scheduler binding will /// Frames triggered by the engine and handler by the scheduler binding will
...@@ -24,3 +29,21 @@ bool debugPrintBeginFrameBanner = false; ...@@ -24,3 +29,21 @@ bool debugPrintBeginFrameBanner = false;
/// Combined with [debugPrintBeginFrameBanner], this can be helpful for /// Combined with [debugPrintBeginFrameBanner], this can be helpful for
/// determining if code is running during a frame or between frames. /// determining if code is running during a frame or between frames.
bool debugPrintEndFrameBanner = false; bool debugPrintEndFrameBanner = false;
/// Returns true if none of the scheduler library debug variables have been changed.
///
/// This function is used by the test framework to ensure that debug variables
/// haven't been inadvertently changed.
///
/// See [https://docs.flutter.io/flutter/scheduler/scheduler-library.html] for
/// a complete list.
bool debugAssertAllSchedulerVarsUnset(String reason) {
assert(() {
if (debugPrintBeginFrameBanner ||
debugPrintEndFrameBanner) {
throw new FlutterError(reason);
}
return true;
});
return true;
}
...@@ -8,6 +8,9 @@ import 'package:flutter/foundation.dart'; ...@@ -8,6 +8,9 @@ import 'package:flutter/foundation.dart';
import 'framework.dart'; import 'framework.dart';
import 'table.dart'; import 'table.dart';
// Any changes to this file should be reflected in the debugAssertAllWidgetVarsUnset()
// function below.
/// Log the dirty widgets that are built each frame. /// Log the dirty widgets that are built each frame.
/// ///
/// Combined with [debugPrintBuildScope] or [debugPrintBeginFrameBanner], this /// Combined with [debugPrintBuildScope] or [debugPrintBeginFrameBanner], this
...@@ -167,3 +170,24 @@ void debugWidgetBuilderValue(Widget widget, Widget built) { ...@@ -167,3 +170,24 @@ void debugWidgetBuilderValue(Widget widget, Widget built) {
return true; return true;
}); });
} }
/// Returns true if none of the widget library debug variables have been changed.
///
/// This function is used by the test framework to ensure that debug variables
/// haven't been inadvertently changed.
///
/// See [https://docs.flutter.io/flutter/widgets/widgets-library.html] for
/// a complete list.
bool debugAssertAllWidgetVarsUnset(String reason) {
assert(() {
if (debugPrintRebuildDirtyWidgets ||
debugPrintBuildScope ||
debugPrintScheduleBuildForStacks ||
debugPrintGlobalKeyedWidgetLifecycle ||
debugProfileBuildsEnabled) {
throw new FlutterError(reason);
}
return true;
});
return true;
}
...@@ -395,6 +395,15 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -395,6 +395,15 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
assert(debugAssertNoTransientCallbacks( assert(debugAssertNoTransientCallbacks(
'An animation is still running even after the widget tree was disposed.' 'An animation is still running even after the widget tree was disposed.'
)); ));
assert(debugAssertAllRenderVarsUnset(
'The value of a rendering debug variable was changed by the test.'
));
assert(debugAssertAllWidgetVarsUnset(
'The value of a widget debug variable was changed by the test.'
));
assert(debugAssertAllSchedulerVarsUnset(
'The value of a scheduler debug variable was changed by the test.'
));
} }
/// Called by the [testWidgets] function after a test is executed. /// Called by the [testWidgets] function after a test is executed.
......
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