[flutter_tools] Add channel order aware version_test (#62417)
This commit is contained in:
@@ -72,7 +72,7 @@ class ChannelCommand extends FlutterCommand {
|
||||
throwToolExit('List channels failed: $result$details', exitCode: result);
|
||||
}
|
||||
|
||||
final List<String> officialChannels = FlutterVersion.officialChannels.toList();
|
||||
final List<String> officialChannels = kOfficialChannels.toList();
|
||||
final List<bool> availableChannels = List<bool>.filled(officialChannels.length, false);
|
||||
|
||||
for (final String line in rawOutput) {
|
||||
@@ -116,10 +116,10 @@ class ChannelCommand extends FlutterCommand {
|
||||
|
||||
Future<void> _switchChannel(String branchName) async {
|
||||
globals.printStatus("Switching to flutter channel '$branchName'...");
|
||||
if (FlutterVersion.obsoleteBranches.containsKey(branchName)) {
|
||||
final String alternative = FlutterVersion.obsoleteBranches[branchName];
|
||||
if (kObsoleteBranches.containsKey(branchName)) {
|
||||
final String alternative = kObsoleteBranches[branchName];
|
||||
globals.printStatus("This channel is obsolete. Consider switching to the '$alternative' channel instead.");
|
||||
} else if (!FlutterVersion.officialChannels.contains(branchName)) {
|
||||
} else if (!kOfficialChannels.contains(branchName)) {
|
||||
globals.printStatus('This is not an official channel. For a list of available channels, try "flutter channel".');
|
||||
}
|
||||
await _checkout(branchName);
|
||||
@@ -129,8 +129,8 @@ class ChannelCommand extends FlutterCommand {
|
||||
|
||||
static Future<void> upgradeChannel() async {
|
||||
final String channel = globals.flutterVersion.channel;
|
||||
if (FlutterVersion.obsoleteBranches.containsKey(channel)) {
|
||||
final String alternative = FlutterVersion.obsoleteBranches[channel];
|
||||
if (kObsoleteBranches.containsKey(channel)) {
|
||||
final String alternative = kObsoleteBranches[channel];
|
||||
globals.printStatus("Transitioning from '$channel' to '$alternative'...");
|
||||
return _checkout(alternative);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class UpgradeCommandRunner {
|
||||
if (!force && gitTagVersion == const GitTagVersion.unknown()) {
|
||||
// If the commit is a recognized branch and not master,
|
||||
// explain that we are avoiding potential damage.
|
||||
if (flutterVersion.channel != 'master' && FlutterVersion.officialChannels.contains(flutterVersion.channel)) {
|
||||
if (flutterVersion.channel != 'master' && kOfficialChannels.contains(flutterVersion.channel)) {
|
||||
throwToolExit(
|
||||
'Unknown flutter tag. Abandoning upgrade to avoid destroying local '
|
||||
'changes. It is recommended to use git directly if not working on '
|
||||
|
||||
@@ -13,6 +13,20 @@ import 'cache.dart';
|
||||
import 'convert.dart';
|
||||
import 'globals.dart' as globals;
|
||||
|
||||
/// The flutter GitHub repository.
|
||||
String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
|
||||
|
||||
/// This maps old branch names to the names of branches that replaced them.
|
||||
///
|
||||
/// For example, in early 2018 we changed from having an "alpha" branch to
|
||||
/// having a "dev" branch, so anyone using "alpha" now gets transitioned to
|
||||
/// "dev".
|
||||
const Map<String, String> kObsoleteBranches = <String, String>{
|
||||
'alpha': 'dev',
|
||||
'hackathon': 'dev',
|
||||
'codelab': 'dev',
|
||||
};
|
||||
|
||||
/// The names of each channel/branch in order of increasing stability.
|
||||
enum Channel {
|
||||
master,
|
||||
@@ -21,23 +35,28 @@ enum Channel {
|
||||
stable,
|
||||
}
|
||||
|
||||
/// The flutter GitHub repository.
|
||||
String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
|
||||
// Beware: Keep order in accordance with stability
|
||||
const Set<String> kOfficialChannels = <String>{
|
||||
'master',
|
||||
'dev',
|
||||
'beta',
|
||||
'stable',
|
||||
};
|
||||
|
||||
/// Retrieve a human-readable name for a given [channel].
|
||||
///
|
||||
/// Requires [FlutterVersion.officialChannels] to be correctly ordered.
|
||||
/// Requires [kOfficialChannels] to be correctly ordered.
|
||||
String getNameForChannel(Channel channel) {
|
||||
return FlutterVersion.officialChannels.elementAt(channel.index);
|
||||
return kOfficialChannels.elementAt(channel.index);
|
||||
}
|
||||
|
||||
/// Retrieve the [Channel] representation for a string [name].
|
||||
///
|
||||
/// Returns `null` if [name] is not in the list of official channels, according
|
||||
/// to [FlutterVersion.officialChannels].
|
||||
/// to [kOfficialChannels].
|
||||
Channel getChannelForName(String name) {
|
||||
if (FlutterVersion.officialChannels.contains(name)) {
|
||||
return Channel.values[FlutterVersion.officialChannels.toList().indexOf(name)];
|
||||
if (kOfficialChannels.contains(name)) {
|
||||
return Channel.values[kOfficialChannels.toList().indexOf(name)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -84,25 +103,6 @@ class FlutterVersion {
|
||||
return !<String>['dev', 'beta', 'stable'].contains(branchName);
|
||||
}
|
||||
|
||||
// Beware: Keep order in accordance with stability
|
||||
static const Set<String> officialChannels = <String>{
|
||||
'master',
|
||||
'dev',
|
||||
'beta',
|
||||
'stable',
|
||||
};
|
||||
|
||||
/// This maps old branch names to the names of branches that replaced them.
|
||||
///
|
||||
/// For example, in early 2018 we changed from having an "alpha" branch to
|
||||
/// having a "dev" branch, so anyone using "alpha" now gets transitioned to
|
||||
/// "dev".
|
||||
static Map<String, String> obsoleteBranches = <String, String>{
|
||||
'alpha': 'dev',
|
||||
'hackathon': 'dev',
|
||||
'codelab': 'dev',
|
||||
};
|
||||
|
||||
String _channel;
|
||||
/// The channel is the upstream branch.
|
||||
/// `master`, `dev`, `beta`, `stable`; or old ones, like `alpha`, `hackathon`, ...
|
||||
@@ -298,8 +298,8 @@ class FlutterVersion {
|
||||
}();
|
||||
if (redactUnknownBranches || _branch.isEmpty) {
|
||||
// Only return the branch names we know about; arbitrary branch names might contain PII.
|
||||
if (!officialChannels.contains(_branch) &&
|
||||
!obsoleteBranches.containsKey(_branch)) {
|
||||
if (!kOfficialChannels.contains(_branch) &&
|
||||
!kObsoleteBranches.containsKey(_branch)) {
|
||||
return '[user-branch]';
|
||||
}
|
||||
}
|
||||
@@ -388,7 +388,7 @@ class FlutterVersion {
|
||||
/// writes shared cache files.
|
||||
Future<void> checkFlutterVersionFreshness() async {
|
||||
// Don't perform update checks if we're not on an official channel.
|
||||
if (!officialChannels.contains(channel)) {
|
||||
if (!kOfficialChannels.contains(channel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ void main() {
|
||||
final Iterable<String> rows = testLogger.statusText
|
||||
.split('\n')
|
||||
.map((String line) => line.substring(2)); // remove '* ' or ' ' from output
|
||||
expect(rows, containsAllInOrder(FlutterVersion.officialChannels));
|
||||
expect(rows, containsAllInOrder(kOfficialChannels));
|
||||
|
||||
// clear buffer for next process
|
||||
testLogger.clear();
|
||||
@@ -107,7 +107,7 @@ void main() {
|
||||
final Iterable<String> rows2 = testLogger.statusText
|
||||
.split('\n')
|
||||
.map((String line) => line.substring(2)); // remove '* ' or ' ' from output
|
||||
expect(rows2, containsAllInOrder(FlutterVersion.officialChannels));
|
||||
expect(rows2, containsAllInOrder(kOfficialChannels));
|
||||
|
||||
// clear buffer for next process
|
||||
testLogger.clear();
|
||||
@@ -127,7 +127,7 @@ void main() {
|
||||
// check if available official channels are in order of stability
|
||||
int prev = -1;
|
||||
int next = -1;
|
||||
for (final String branch in FlutterVersion.officialChannels) {
|
||||
for (final String branch in kOfficialChannels) {
|
||||
next = testLogger.statusText.indexOf(branch);
|
||||
if (next != -1) {
|
||||
expect(prev < next, isTrue);
|
||||
|
||||
@@ -36,7 +36,15 @@ void main() {
|
||||
mockCache = MockCache();
|
||||
});
|
||||
|
||||
for (final String channel in FlutterVersion.officialChannels) {
|
||||
testUsingContext('Channel enum and string transform to each other', () {
|
||||
for (final Channel channel in Channel.values) {
|
||||
expect(getNameForChannel(channel), kOfficialChannels.toList()[channel.index]);
|
||||
}
|
||||
expect(kOfficialChannels.toList().map((String str) => getChannelForName(str)).toList(),
|
||||
Channel.values);
|
||||
});
|
||||
|
||||
for (final String channel in kOfficialChannels) {
|
||||
DateTime getChannelUpToDateVersion() {
|
||||
return _testClock.ago(FlutterVersion.versionAgeConsideredUpToDate(channel) ~/ 2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user