Unverified Commit 5bd34ef5 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Rename isAvailableForEnvironment to isForEnvironment (#143176)

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.)
parent fde345a6
...@@ -23,7 +23,12 @@ export 'skia_client.dart'; ...@@ -23,7 +23,12 @@ 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
...@@ -33,11 +38,11 @@ final RegExp _kMainBranch = RegExp(r'master|main'); ...@@ -33,11 +38,11 @@ final RegExp _kMainBranch = RegExp(r'master|main');
/// 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.isAvailableForEnvironment(platform)) { if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix); goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix);
} else if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) { } else if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix); goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(platform, namePrefix: namePrefix);
} else if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) { } else if (FlutterSkippingFileComparator.isForEnvironment(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
...@@ -259,13 +264,13 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator { ...@@ -259,13 +264,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 isAvailableForEnvironment(Platform platform) { static bool isForEnvironment(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.
&& _kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? ''); && _isMainBranch(platform.environment['GIT_BRANCH']);
return luciPostSubmit; return luciPostSubmit;
} }
...@@ -349,12 +354,12 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator { ...@@ -349,12 +354,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 isAvailableForEnvironment(Platform platform) { static bool isForEnvironment(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
&& _kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? ''); && _isMainBranch(platform.environment['GIT_BRANCH']);
return luciPreSubmit; return luciPreSubmit;
} }
} }
...@@ -420,12 +425,12 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator { ...@@ -420,12 +425,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 isAvailableForEnvironment(Platform platform) { static bool isForEnvironment(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.
&& !_kMainBranch.hasMatch(platform.environment['GIT_BRANCH'] ?? ''); && !_isMainBranch(platform.environment['GIT_BRANCH']);
} }
} }
...@@ -435,7 +440,7 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator { ...@@ -435,7 +440,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 `isAvailableForEnvironment` method for each one listed below. /// met, see the `isForEnvironment` 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
......
...@@ -39,13 +39,13 @@ _Comparator _testRecommendations({ ...@@ -39,13 +39,13 @@ _Comparator _testRecommendations({
}, },
operatingSystem: os, operatingSystem: os,
); );
if (FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform)) { if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
return _Comparator.post; return _Comparator.post;
} }
if (FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform)) { if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
return _Comparator.pre; return _Comparator.pre;
} }
if (FlutterSkippingFileComparator.isAvailableForEnvironment(platform)) { if (FlutterSkippingFileComparator.isForEnvironment(platform)) {
return _Comparator.skip; return _Comparator.skip;
} }
return _Comparator.local; return _Comparator.local;
...@@ -165,4 +165,11 @@ void main() { ...@@ -165,4 +165,11 @@ 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);
});
} }
...@@ -725,7 +725,7 @@ void main() { ...@@ -725,7 +725,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -741,7 +741,7 @@ void main() { ...@@ -741,7 +741,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -757,7 +757,7 @@ void main() { ...@@ -757,7 +757,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -773,7 +773,7 @@ void main() { ...@@ -773,7 +773,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -787,7 +787,7 @@ void main() { ...@@ -787,7 +787,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -803,7 +803,7 @@ void main() { ...@@ -803,7 +803,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -820,7 +820,7 @@ void main() { ...@@ -820,7 +820,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -893,7 +893,7 @@ void main() { ...@@ -893,7 +893,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -910,7 +910,7 @@ void main() { ...@@ -910,7 +910,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -927,7 +927,7 @@ void main() { ...@@ -927,7 +927,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -944,7 +944,7 @@ void main() { ...@@ -944,7 +944,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -957,7 +957,7 @@ void main() { ...@@ -957,7 +957,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -972,7 +972,7 @@ void main() { ...@@ -972,7 +972,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -987,7 +987,7 @@ void main() { ...@@ -987,7 +987,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPreSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPreSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -1004,7 +1004,7 @@ void main() { ...@@ -1004,7 +1004,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterPostSubmitFileComparator.isAvailableForEnvironment(platform), FlutterPostSubmitFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
...@@ -1025,7 +1025,7 @@ void main() { ...@@ -1025,7 +1025,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isAvailableForEnvironment(platform), FlutterSkippingFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -1041,7 +1041,7 @@ void main() { ...@@ -1041,7 +1041,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isAvailableForEnvironment(platform), FlutterSkippingFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -1055,7 +1055,7 @@ void main() { ...@@ -1055,7 +1055,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isAvailableForEnvironment(platform), FlutterSkippingFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -1069,7 +1069,7 @@ void main() { ...@@ -1069,7 +1069,7 @@ void main() {
operatingSystem: 'macos' operatingSystem: 'macos'
); );
expect( expect(
FlutterSkippingFileComparator.isAvailableForEnvironment(platform), FlutterSkippingFileComparator.isForEnvironment(platform),
isTrue, isTrue,
); );
}); });
...@@ -1082,7 +1082,7 @@ void main() { ...@@ -1082,7 +1082,7 @@ void main() {
operatingSystem: 'macos', operatingSystem: 'macos',
); );
expect( expect(
FlutterSkippingFileComparator.isAvailableForEnvironment(platform), FlutterSkippingFileComparator.isForEnvironment(platform),
isFalse, isFalse,
); );
}); });
......
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