Skip to content

Commit a494a12

Browse files
antholeoleAnthony Oleinik
andauthored
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 <[email protected]>
1 parent 8ff6911 commit a494a12

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747

4848
expect(topBeforeScroll.dy, equals(0.0));
4949
expect(topAfterScroll.dy, equals(0.0));
50-
}, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet()));
50+
}, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.fuchsia }));
5151

5252
testWidgets('FlexibleSpaceBar collapse mode pin', (WidgetTester tester) async {
5353
await tester.pumpWidget(
@@ -85,7 +85,7 @@ void main() {
8585

8686
expect(topBeforeScroll.dy, equals(0.0));
8787
expect(topAfterScroll.dy, equals(-100.0));
88-
}, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet()));
88+
}, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.fuchsia }));
8989

9090
testWidgets('FlexibleSpaceBar collapse mode parallax', (WidgetTester tester) async {
9191
await tester.pumpWidget(
@@ -123,7 +123,7 @@ void main() {
123123
expect(topBeforeScroll.dy, equals(0.0));
124124
expect(topAfterScroll.dy, lessThan(10.0));
125125
expect(topAfterScroll.dy, greaterThan(-50.0));
126-
}, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet()));
126+
}, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.fuchsia }));
127127
}
128128

129129
Future<void> slowDrag(WidgetTester tester, Key widget, Offset offset) async {

packages/flutter/test/widgets/editable_text_cursor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void main() {
234234
await tester.pump(const Duration(milliseconds: 100));
235235
expect(tester.hasRunningAnimations, false);
236236
}
237-
}, variant: TargetPlatformVariant(TargetPlatform.values.toSet()..remove(TargetPlatform.iOS)));
237+
}, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS }));
238238

239239
testWidgets('Cursor does not animate on Android', (WidgetTester tester) async {
240240
final Color defaultCursorColor = Color(ThemeData.fallback().colorScheme.primary.value);

packages/flutter/test/widgets/editable_text_shortcuts_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void main() {
138138

139139
group('Common text editing shortcuts: ',
140140
() {
141-
final TargetPlatformVariant allExceptApple = TargetPlatformVariant(TargetPlatform.values.toSet()..removeAll(<TargetPlatform>[TargetPlatform.macOS, TargetPlatform.iOS]));
141+
final TargetPlatformVariant allExceptApple = TargetPlatformVariant.all(excluding: <TargetPlatform>{TargetPlatform.macOS, TargetPlatform.iOS});
142142

143143
group('backspace', () {
144144
const LogicalKeyboardKey trigger = LogicalKeyboardKey.backspace;
@@ -1813,7 +1813,7 @@ void main() {
18131813
}, skip: kIsWeb); // [intended] on web these keys are handled by the browser.
18141814

18151815
group('Web does not accept', () {
1816-
final TargetPlatformVariant allExceptApple = TargetPlatformVariant(TargetPlatform.values.toSet()..removeAll(<TargetPlatform>[TargetPlatform.macOS, TargetPlatform.iOS]));
1816+
final TargetPlatformVariant allExceptApple = TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS });
18171817
const TargetPlatformVariant appleOnly = TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS, TargetPlatform.iOS });
18181818
group('macOS shortcuts', () {
18191819

packages/flutter_test/lib/src/widget_tester.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ class TargetPlatformVariant extends TestVariant<TargetPlatform> {
254254
const TargetPlatformVariant(this.values);
255255

256256
/// Creates a [TargetPlatformVariant] that tests all values from
257-
/// the [TargetPlatform] enum.
258-
TargetPlatformVariant.all() : values = TargetPlatform.values.toSet();
257+
/// the [TargetPlatform] enum. If [excluding] is provided, will test all platforms
258+
/// except those in [excluding].
259+
TargetPlatformVariant.all({
260+
Set<TargetPlatform> excluding = const <TargetPlatform>{},
261+
}) : values = TargetPlatform.values.toSet()..removeAll(excluding);
259262

260263
/// Creates a [TargetPlatformVariant] that includes platforms that are
261264
/// considered desktop platforms.

packages/flutter_test/test/widget_tester_test.dart

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,29 @@ void main() {
720720
expect(defaultTargetPlatform, equals(TargetPlatform.iOS));
721721
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
722722

723-
testWidgets('TargetPlatformVariant.all tests run all variants', (WidgetTester tester) async {
724-
if (debugDefaultTargetPlatformOverride == null) {
725-
expect(numberOfVariationsRun, equals(TargetPlatform.values.length));
726-
} else {
727-
numberOfVariationsRun += 1;
728-
}
729-
}, variant: TargetPlatformVariant.all());
723+
group('all', () {
724+
testWidgets('TargetPlatformVariant.all tests run all variants', (WidgetTester tester) async {
725+
if (debugDefaultTargetPlatformOverride == null) {
726+
expect(numberOfVariationsRun, equals(TargetPlatform.values.length));
727+
} else {
728+
numberOfVariationsRun += 1;
729+
}
730+
}, variant: TargetPlatformVariant.all());
731+
732+
const Set<TargetPlatform> excludePlatforms = <TargetPlatform>{ TargetPlatform.android, TargetPlatform.linux };
733+
testWidgets('TargetPlatformVariant.all, excluding runs an all variants except those provided in excluding', (WidgetTester tester) async {
734+
if (debugDefaultTargetPlatformOverride == null) {
735+
expect(numberOfVariationsRun, equals(TargetPlatform.values.length - excludePlatforms.length));
736+
expect(
737+
excludePlatforms,
738+
isNot(contains(debugDefaultTargetPlatformOverride)),
739+
reason: 'this test should not run on any platform in excludePlatforms'
740+
);
741+
} else {
742+
numberOfVariationsRun += 1;
743+
}
744+
}, variant: TargetPlatformVariant.all(excluding: excludePlatforms));
745+
});
730746

731747
testWidgets('TargetPlatformVariant.desktop + mobile contains all TargetPlatform values', (WidgetTester tester) async {
732748
final TargetPlatformVariant all = TargetPlatformVariant.all();

0 commit comments

Comments
 (0)