Reverts "Rename isAvailableForEnvironment to isForEnvironment (#143176)" (#144855)

Reverts: flutter/flutter#143176
Initiated by: QuncCccccc
Reason for reverting: made tree red.
Original PR Author: Hixie

Reviewed By: {Piinks}

This change reverts the following previous change:
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 commit is contained in:
auto-submit[bot] 2024-03-08 23:19:15 +00:00 committed by GitHub
parent 0a40291f7a
commit 0432a6941d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 46 deletions

View file

@ -23,12 +23,7 @@ export 'skia_client.dart';
// /packages/flutter/test/widgets/basic_test.dart // /packages/flutter/test/widgets/basic_test.dart
const String _kFlutterRootKey = 'FLUTTER_ROOT'; const String _kFlutterRootKey = 'FLUTTER_ROOT';
final RegExp _kMainBranch = RegExp(r'master|main');
bool _isMainBranch(String? branch) {
return branch == 'main'
|| branch == 'master';
}
/// Main method that can be used in a `flutter_test_config.dart` file to set /// Main method that can be used in a `flutter_test_config.dart` file to set
/// [goldenFileComparator] to an instance of [FlutterGoldenFileComparator] that /// [goldenFileComparator] to an instance of [FlutterGoldenFileComparator] that
@ -38,11 +33,11 @@ bool _isMainBranch(String? branch) {
/// When set, the `namePrefix` is prepended to the names of all gold images. /// When set, the `namePrefix` is prepended to the names of all gold images.
Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePrefix}) async { Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePrefix}) async {
const Platform platform = LocalPlatform(); const Platform platform = LocalPlatform();
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) { if (FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform)) {
goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix); goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix);
} else if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) { } else if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) {
goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix); goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix);
} else if (FlutterSkippingFileComparator.isForEnvironment(platform)) { } else if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) {
goldenFileComparator = FlutterSkippingFileComparator.fromDefaultComparator( goldenFileComparator = FlutterSkippingFileComparator.fromDefaultComparator(
'Golden file testing is not executed on Cirrus, or LUCI environments outside of flutter/flutter.', 'Golden file testing is not executed on Cirrus, or LUCI environments outside of flutter/flutter.',
namePrefix: namePrefix namePrefix: namePrefix
@ -264,13 +259,13 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
/// Decides based on the current environment if goldens tests should be /// Decides based on the current environment if goldens tests should be
/// executed through Skia Gold. /// executed through Skia Gold.
static bool isForEnvironment(Platform platform) { static bool isAvailableForEnvironment(Platform platform) {
final bool luciPostSubmit = platform.environment.containsKey('SWARMING_TASK_ID') final bool luciPostSubmit = platform.environment.containsKey('SWARMING_TASK_ID')
&& platform.environment.containsKey('GOLDCTL') && platform.environment.containsKey('GOLDCTL')
// Luci tryjob environments contain this value to inform the [FlutterPreSubmitComparator]. // Luci tryjob environments contain this value to inform the [FlutterPreSubmitComparator].
&& !platform.environment.containsKey('GOLD_TRYJOB') && !platform.environment.containsKey('GOLD_TRYJOB')
// Only run on main branch. // Only run on main branch.
&& _isMainBranch(platform.environment['GIT_BRANCH']); && _kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? '');
return luciPostSubmit; return luciPostSubmit;
} }
@ -354,12 +349,12 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
/// Decides based on the current environment if goldens tests should be /// Decides based on the current environment if goldens tests should be
/// executed as pre-submit tests with Skia Gold. /// executed as pre-submit tests with Skia Gold.
static bool isForEnvironment(Platform platform) { static bool isAvailableForEnvironment(Platform platform) {
final bool luciPreSubmit = platform.environment.containsKey('SWARMING_TASK_ID') final bool luciPreSubmit = platform.environment.containsKey('SWARMING_TASK_ID')
&& platform.environment.containsKey('GOLDCTL') && platform.environment.containsKey('GOLDCTL')
&& platform.environment.containsKey('GOLD_TRYJOB') && platform.environment.containsKey('GOLD_TRYJOB')
// Only run on the main branch // Only run on the main branch
&& _isMainBranch(platform.environment['GIT_BRANCH']); && _kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? '');
return luciPreSubmit; return luciPreSubmit;
} }
} }
@ -425,12 +420,12 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
/// ///
/// If we are in a CI environment, LUCI or Cirrus, but are not using the other /// If we are in a CI environment, LUCI or Cirrus, but are not using the other
/// comparators, we skip. /// comparators, we skip.
static bool isForEnvironment(Platform platform) { static bool isAvailableForEnvironment(Platform platform) {
return (platform.environment.containsKey('SWARMING_TASK_ID') return (platform.environment.containsKey('SWARMING_TASK_ID')
// Some builds are still being run on Cirrus, we should skip these. // Some builds are still being run on Cirrus, we should skip these.
|| platform.environment.containsKey('CIRRUS_CI')) || platform.environment.containsKey('CIRRUS_CI'))
// If we are in CI, skip on branches that are not main. // If we are in CI, skip on branches that are not main.
&& !_isMainBranch(platform.environment['GIT_BRANCH']); && !_kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? '');
} }
} }
@ -440,7 +435,7 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
/// This comparator utilizes the [SkiaGoldClient] to request baseline images for /// This comparator utilizes the [SkiaGoldClient] to request baseline images for
/// the given device under test for comparison. This comparator is initialized /// the given device under test for comparison. This comparator is initialized
/// when conditions for all other [FlutterGoldenFileComparators] have not been /// when conditions for all other [FlutterGoldenFileComparators] have not been
/// met, see the `isForEnvironment` method for each one listed below. /// met, see the `isAvailableForEnvironment` method for each one listed below.
/// ///
/// The [FlutterLocalFileComparator] is intended to run on local machines and /// The [FlutterLocalFileComparator] is intended to run on local machines and
/// serve as a smoke test during development. As such, it will not be able to /// serve as a smoke test during development. As such, it will not be able to

View file

@ -39,13 +39,13 @@ _Comparator _testRecommendations({
}, },
operatingSystem: os, operatingSystem: os,
); );
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) { if (FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform)) {
return _Comparator.post; return _Comparator.post;
} }
if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) { if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) {
return _Comparator.pre; return _Comparator.pre;
} }
if (FlutterSkippingFileComparator.isForEnvironment(platform)) { if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) {
return _Comparator.skip; return _Comparator.skip;
} }
return _Comparator.local; return _Comparator.local;
@ -165,11 +165,4 @@ void main() {
expect(_testRecommendations(os: 'linux', hasCirrus: true, hasGold: true, hasFlutterRoot: true), _Comparator.local); // TODO(ianh): this should be skip expect(_testRecommendations(os: 'linux', hasCirrus: true, hasGold: true, hasFlutterRoot: true), _Comparator.local); // TODO(ianh): this should be skip
expect(_testRecommendations(os: 'linux', hasCirrus: true, hasGold: true, hasFlutterRoot: true, hasTryJob: true), _Comparator.local); // TODO(ianh): this should be skip expect(_testRecommendations(os: 'linux', hasCirrus: true, hasGold: true, hasFlutterRoot: true, hasTryJob: true), _Comparator.local); // TODO(ianh): this should be skip
}); });
test('Branch names', () {
expect(_testRecommendations(hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.post);
expect(_testRecommendations(branch: 'master', hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.post);
expect(_testRecommendations(branch: 'the_master_of_justice', hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.skip);
expect(_testRecommendations(branch: 'maintain_accuracy', hasLuci: true, hasGold: true, hasFlutterRoot: true), _Comparator.skip);
});
} }

View file

@ -725,7 +725,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -741,7 +741,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -757,7 +757,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -773,7 +773,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -787,7 +787,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -803,7 +803,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -820,7 +820,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -893,7 +893,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -910,7 +910,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -927,7 +927,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -944,7 +944,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -957,7 +957,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -972,7 +972,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -987,7 +987,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isForEnvironment(platform), FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -1004,7 +1004,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isForEnvironment(platform), FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });
@ -1025,7 +1025,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isForEnvironment(platform), FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -1041,7 +1041,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isForEnvironment(platform), FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -1055,7 +1055,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isForEnvironment(platform), FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -1069,7 +1069,7 @@ void main() {
operatingSystem: 'macos' operatingSystem: 'macos'
); );
expect( expect(
FlutterSkippingFileComparator.isForEnvironment(platform), FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
isTrue, isTrue,
); );
}); });
@ -1082,7 +1082,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isForEnvironment(platform), FlutterSkippingFileComparator.isAvailableForEnvironment(platform),
isFalse, isFalse,
); );
}); });