Skip to content

Commit dbcce27

Browse files
authored
Rename isAvailableForEnvironment to isForEnvironment (#143176) (#144858)
This is part 4 of a broken down version of the #140101 refactor. This PR renames isAvailableForEnvironment to isForEnvironment and replaces a regular expression with a simple function. (The latter will change the behaviour for people with branch names like `mainly_refactors` or `chess_master_experiment` or whatever, but I'm pretty sure the old behaviour was not intended.) ---- This is a reland of #143176 which was speculatively reverted in #144855 but turned out not to be the cause of the tree redness.
1 parent 640d212 commit dbcce27

File tree

3 files changed

+46
-34
lines changed

3 files changed

+46
-34
lines changed

packages/flutter_goldens/lib/flutter_goldens.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export 'skia_client.dart';
2323
// /packages/flutter/test/widgets/basic_test.dart
2424

2525
const String _kFlutterRootKey = 'FLUTTER_ROOT';
26-
final RegExp _kMainBranch = RegExp(r'master|main');
26+
27+
bool _isMainBranch(String? branch) {
28+
return branch == 'main'
29+
|| branch == 'master';
30+
}
31+
2732

2833
/// Main method that can be used in a `flutter_test_config.dart` file to set
2934
/// [goldenFileComparator] to an instance of [FlutterGoldenFileComparator] that
@@ -33,11 +38,11 @@ final RegExp _kMainBranch = RegExp(r'master|main');
3338
/// When set, the `namePrefix` is prepended to the names of all gold images.
3439
Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePrefix}) async {
3540
const Platform platform = LocalPlatform();
36-
if (FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform)) {
41+
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
3742
goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix);
38-
} else if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) {
43+
} else if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
3944
goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix);
40-
} else if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) {
45+
} else if (FlutterSkippingFileComparator.isForEnvironment(platform)) {
4146
goldenFileComparator = FlutterSkippingFileComparator.fromDefaultComparator(
4247
'Golden file testing is not executed on Cirrus, or LUCI environments outside of flutter/flutter.',
4348
namePrefix: namePrefix
@@ -259,13 +264,13 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
259264

260265
/// Decides based on the current environment if goldens tests should be
261266
/// executed through Skia Gold.
262-
static bool isAvailableForEnvironment(Platform platform) {
267+
static bool isForEnvironment(Platform platform) {
263268
final bool luciPostSubmit = platform.environment.containsKey('SWARMING_TASK_ID')
264269
&& platform.environment.containsKey('GOLDCTL')
265270
// Luci tryjob environments contain this value to inform the [FlutterPreSubmitComparator].
266271
&& !platform.environment.containsKey('GOLD_TRYJOB')
267272
// Only run on main branch.
268-
&& _kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? '');
273+
&& _isMainBranch(platform.environment['GIT_BRANCH']);
269274

270275
return luciPostSubmit;
271276
}
@@ -349,12 +354,12 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
349354

350355
/// Decides based on the current environment if goldens tests should be
351356
/// executed as pre-submit tests with Skia Gold.
352-
static bool isAvailableForEnvironment(Platform platform) {
357+
static bool isForEnvironment(Platform platform) {
353358
final bool luciPreSubmit = platform.environment.containsKey('SWARMING_TASK_ID')
354359
&& platform.environment.containsKey('GOLDCTL')
355360
&& platform.environment.containsKey('GOLD_TRYJOB')
356361
// Only run on the main branch
357-
&& _kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? '');
362+
&& _isMainBranch(platform.environment['GIT_BRANCH']);
358363
return luciPreSubmit;
359364
}
360365
}
@@ -420,12 +425,12 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
420425
///
421426
/// If we are in a CI environment, LUCI or Cirrus, but are not using the other
422427
/// comparators, we skip.
423-
static bool isAvailableForEnvironment(Platform platform) {
428+
static bool isForEnvironment(Platform platform) {
424429
return (platform.environment.containsKey('SWARMING_TASK_ID')
425430
// Some builds are still being run on Cirrus, we should skip these.
426431
|| platform.environment.containsKey('CIRRUS_CI'))
427432
// If we are in CI, skip on branches that are not main.
428-
&& !_kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? '');
433+
&& !_isMainBranch(platform.environment['GIT_BRANCH']);
429434
}
430435
}
431436

@@ -435,7 +440,7 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
435440
/// This comparator utilizes the [SkiaGoldClient] to request baseline images for
436441
/// the given device under test for comparison. This comparator is initialized
437442
/// when conditions for all other [FlutterGoldenFileComparators] have not been
438-
/// met, see the `isAvailableForEnvironment` method for each one listed below.
443+
/// met, see the `isForEnvironment` method for each one listed below.
439444
///
440445
/// The [FlutterLocalFileComparator] is intended to run on local machines and
441446
/// serve as a smoke test during development. As such, it will not be able to

packages/flutter_goldens/test/comparator_selection_test.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ _Comparator _testRecommendations({
3939
},
4040
operatingSystem: os,
4141
);
42-
if (FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform)) {
42+
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
4343
return _Comparator.post;
4444
}
45-
if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) {
45+
if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
4646
return _Comparator.pre;
4747
}
48-
if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) {
48+
if (FlutterSkippingFileComparator.isForEnvironment(platform)) {
4949
return _Comparator.skip;
5050
}
5151
return _Comparator.local;
@@ -165,4 +165,11 @@ void main() {
165165
expect(_testRecommendations(os: 'linux', hasCirrus: true, hasGold: true, hasFlutterRoot: true), _Comparator.local); // TODO(ianh): this should be skip
166166
expect(_testRecommendations(os: 'linux', hasCirrus: true, hasGold: true, hasFlutterRoot: true, hasTryJob: true), _Comparator.local); // TODO(ianh): this should be skip
167167
});
168+
169+
test('Branch names', () {
170+
expect(_testRecommendations(hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.post);
171+
expect(_testRecommendations(branch: 'master', hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.post);
172+
expect(_testRecommendations(branch: 'the_master_of_justice', hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.skip);
173+
expect(_testRecommendations(branch: 'maintain_accuracy', hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.skip);
174+
});
168175
}

packages/flutter_goldens/test/flutter_goldens_test.dart

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ void main() {
725725
operatingSystem: 'macos',
726726
);
727727
expect(
728-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
728+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
729729
isTrue,
730730
);
731731
});
@@ -741,7 +741,7 @@ void main() {
741741
operatingSystem: 'macos',
742742
);
743743
expect(
744-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
744+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
745745
isFalse,
746746
);
747747
});
@@ -757,7 +757,7 @@ void main() {
757757
operatingSystem: 'macos',
758758
);
759759
expect(
760-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
760+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
761761
isTrue,
762762
);
763763
});
@@ -773,7 +773,7 @@ void main() {
773773
operatingSystem: 'macos',
774774
);
775775
expect(
776-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
776+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
777777
isTrue,
778778
);
779779
});
@@ -787,7 +787,7 @@ void main() {
787787
operatingSystem: 'macos',
788788
);
789789
expect(
790-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
790+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
791791
isFalse,
792792
);
793793
});
@@ -803,7 +803,7 @@ void main() {
803803
operatingSystem: 'macos',
804804
);
805805
expect(
806-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
806+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
807807
isFalse,
808808
);
809809
});
@@ -820,7 +820,7 @@ void main() {
820820
operatingSystem: 'macos',
821821
);
822822
expect(
823-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
823+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
824824
isFalse,
825825
);
826826
});
@@ -893,7 +893,7 @@ void main() {
893893
operatingSystem: 'macos',
894894
);
895895
expect(
896-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
896+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
897897
isFalse,
898898
);
899899
});
@@ -910,7 +910,7 @@ void main() {
910910
operatingSystem: 'macos',
911911
);
912912
expect(
913-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
913+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
914914
isTrue,
915915
);
916916
});
@@ -927,7 +927,7 @@ void main() {
927927
operatingSystem: 'macos',
928928
);
929929
expect(
930-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
930+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
931931
isTrue,
932932
);
933933
});
@@ -944,7 +944,7 @@ void main() {
944944
operatingSystem: 'macos',
945945
);
946946
expect(
947-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
947+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
948948
isTrue,
949949
);
950950
});
@@ -957,7 +957,7 @@ void main() {
957957
operatingSystem: 'macos',
958958
);
959959
expect(
960-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
960+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
961961
isFalse,
962962
);
963963
});
@@ -972,7 +972,7 @@ void main() {
972972
operatingSystem: 'macos',
973973
);
974974
expect(
975-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
975+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
976976
isFalse,
977977
);
978978
});
@@ -987,7 +987,7 @@ void main() {
987987
operatingSystem: 'macos',
988988
);
989989
expect(
990-
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
990+
FlutterPreSubmitFileComparator.isForEnvironment(platform),
991991
isFalse,
992992
);
993993
});
@@ -1004,7 +1004,7 @@ void main() {
10041004
operatingSystem: 'macos',
10051005
);
10061006
expect(
1007-
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
1007+
FlutterPostSubmitFileComparator.isForEnvironment(platform),
10081008
isFalse,
10091009
);
10101010
});
@@ -1025,7 +1025,7 @@ void main() {
10251025
operatingSystem: 'macos',
10261026
);
10271027
expect(
1028-
FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
1028+
FlutterSkippingFileComparator.isForEnvironment(platform),
10291029
isTrue,
10301030
);
10311031
});
@@ -1041,7 +1041,7 @@ void main() {
10411041
operatingSystem: 'macos',
10421042
);
10431043
expect(
1044-
FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
1044+
FlutterSkippingFileComparator.isForEnvironment(platform),
10451045
isTrue,
10461046
);
10471047
});
@@ -1055,7 +1055,7 @@ void main() {
10551055
operatingSystem: 'macos',
10561056
);
10571057
expect(
1058-
FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
1058+
FlutterSkippingFileComparator.isForEnvironment(platform),
10591059
isTrue,
10601060
);
10611061
});
@@ -1069,7 +1069,7 @@ void main() {
10691069
operatingSystem: 'macos'
10701070
);
10711071
expect(
1072-
FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
1072+
FlutterSkippingFileComparator.isForEnvironment(platform),
10731073
isTrue,
10741074
);
10751075
});
@@ -1082,7 +1082,7 @@ void main() {
10821082
operatingSystem: 'macos',
10831083
);
10841084
expect(
1085-
FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
1085+
FlutterSkippingFileComparator.isForEnvironment(platform),
10861086
isFalse,
10871087
);
10881088
});

0 commit comments

Comments
 (0)