Add "excluding" optional parameter to TargetPlatformVariant to communicate cases where test should be ran everywhere but specific platforms (#106216)
added "excluding" optional parameter to targetPlatforms.all
Co-authored-by: Anthony Oleinik <oleina@google.com>
diff --git a/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart b/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart
index 6c3b675..ebd7a21 100644
--- a/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart
+++ b/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart
@@ -47,7 +47,7 @@
expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, equals(0.0));
- }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet()));
+ }, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.fuchsia }));
testWidgets('FlexibleSpaceBar collapse mode pin', (WidgetTester tester) async {
await tester.pumpWidget(
@@ -85,7 +85,7 @@
expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, equals(-100.0));
- }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet()));
+ }, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.fuchsia }));
testWidgets('FlexibleSpaceBar collapse mode parallax', (WidgetTester tester) async {
await tester.pumpWidget(
@@ -123,7 +123,7 @@
expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, lessThan(10.0));
expect(topAfterScroll.dy, greaterThan(-50.0));
- }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet()));
+ }, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.fuchsia }));
}
Future<void> slowDrag(WidgetTester tester, Key widget, Offset offset) async {
diff --git a/packages/flutter/test/widgets/editable_text_cursor_test.dart b/packages/flutter/test/widgets/editable_text_cursor_test.dart
index 9d9147c..99c34cb 100644
--- a/packages/flutter/test/widgets/editable_text_cursor_test.dart
+++ b/packages/flutter/test/widgets/editable_text_cursor_test.dart
@@ -234,7 +234,7 @@
await tester.pump(const Duration(milliseconds: 100));
expect(tester.hasRunningAnimations, false);
}
- }, variant: TargetPlatformVariant(TargetPlatform.values.toSet()..remove(TargetPlatform.iOS)));
+ }, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS }));
testWidgets('Cursor does not animate on Android', (WidgetTester tester) async {
final Color defaultCursorColor = Color(ThemeData.fallback().colorScheme.primary.value);
diff --git a/packages/flutter/test/widgets/editable_text_shortcuts_test.dart b/packages/flutter/test/widgets/editable_text_shortcuts_test.dart
index 36aefc5..0661410 100644
--- a/packages/flutter/test/widgets/editable_text_shortcuts_test.dart
+++ b/packages/flutter/test/widgets/editable_text_shortcuts_test.dart
@@ -138,7 +138,7 @@
group('Common text editing shortcuts: ',
() {
- final TargetPlatformVariant allExceptApple = TargetPlatformVariant(TargetPlatform.values.toSet()..removeAll(<TargetPlatform>[TargetPlatform.macOS, TargetPlatform.iOS]));
+ final TargetPlatformVariant allExceptApple = TargetPlatformVariant.all(excluding: <TargetPlatform>{TargetPlatform.macOS, TargetPlatform.iOS});
group('backspace', () {
const LogicalKeyboardKey trigger = LogicalKeyboardKey.backspace;
@@ -1813,7 +1813,7 @@
}, skip: kIsWeb); // [intended] on web these keys are handled by the browser.
group('Web does not accept', () {
- final TargetPlatformVariant allExceptApple = TargetPlatformVariant(TargetPlatform.values.toSet()..removeAll(<TargetPlatform>[TargetPlatform.macOS, TargetPlatform.iOS]));
+ final TargetPlatformVariant allExceptApple = TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS });
const TargetPlatformVariant appleOnly = TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS, TargetPlatform.iOS });
group('macOS shortcuts', () {
diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart
index 351acbb..2b4149d 100644
--- a/packages/flutter_test/lib/src/widget_tester.dart
+++ b/packages/flutter_test/lib/src/widget_tester.dart
@@ -254,8 +254,11 @@
const TargetPlatformVariant(this.values);
/// Creates a [TargetPlatformVariant] that tests all values from
- /// the [TargetPlatform] enum.
- TargetPlatformVariant.all() : values = TargetPlatform.values.toSet();
+ /// the [TargetPlatform] enum. If [excluding] is provided, will test all platforms
+ /// except those in [excluding].
+ TargetPlatformVariant.all({
+ Set<TargetPlatform> excluding = const <TargetPlatform>{},
+ }) : values = TargetPlatform.values.toSet()..removeAll(excluding);
/// Creates a [TargetPlatformVariant] that includes platforms that are
/// considered desktop platforms.
diff --git a/packages/flutter_test/test/widget_tester_test.dart b/packages/flutter_test/test/widget_tester_test.dart
index efaec2b..9d35cb6 100644
--- a/packages/flutter_test/test/widget_tester_test.dart
+++ b/packages/flutter_test/test/widget_tester_test.dart
@@ -720,13 +720,29 @@
expect(defaultTargetPlatform, equals(TargetPlatform.iOS));
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
- testWidgets('TargetPlatformVariant.all tests run all variants', (WidgetTester tester) async {
- if (debugDefaultTargetPlatformOverride == null) {
- expect(numberOfVariationsRun, equals(TargetPlatform.values.length));
- } else {
- numberOfVariationsRun += 1;
- }
- }, variant: TargetPlatformVariant.all());
+ group('all', () {
+ testWidgets('TargetPlatformVariant.all tests run all variants', (WidgetTester tester) async {
+ if (debugDefaultTargetPlatformOverride == null) {
+ expect(numberOfVariationsRun, equals(TargetPlatform.values.length));
+ } else {
+ numberOfVariationsRun += 1;
+ }
+ }, variant: TargetPlatformVariant.all());
+
+ const Set<TargetPlatform> excludePlatforms = <TargetPlatform>{ TargetPlatform.android, TargetPlatform.linux };
+ testWidgets('TargetPlatformVariant.all, excluding runs an all variants except those provided in excluding', (WidgetTester tester) async {
+ if (debugDefaultTargetPlatformOverride == null) {
+ expect(numberOfVariationsRun, equals(TargetPlatform.values.length - excludePlatforms.length));
+ expect(
+ excludePlatforms,
+ isNot(contains(debugDefaultTargetPlatformOverride)),
+ reason: 'this test should not run on any platform in excludePlatforms'
+ );
+ } else {
+ numberOfVariationsRun += 1;
+ }
+ }, variant: TargetPlatformVariant.all(excluding: excludePlatforms));
+ });
testWidgets('TargetPlatformVariant.desktop + mobile contains all TargetPlatform values', (WidgetTester tester) async {
final TargetPlatformVariant all = TargetPlatformVariant.all();