Unverified Commit acdaffc4 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Suppress upgrade message with --machine (#49408)

parent 1cc38683
......@@ -309,7 +309,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.printError('Please ensure you have permissions in the artifact cache directory.');
throwToolExit('Failed to write the version file');
}
if (topLevelResults.command?.name != 'upgrade' && topLevelResults['version-check'] as bool) {
final bool machineFlag = topLevelResults['machine'] as bool;
if (topLevelResults.command?.name != 'upgrade' && topLevelResults['version-check'] as bool && !machineFlag) {
await FlutterVersion.instance.checkFlutterVersionFreshness();
}
......@@ -323,7 +324,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
if (topLevelResults['version'] as bool) {
flutterUsage.sendCommand('version');
String status;
if (topLevelResults['machine'] as bool) {
if (machineFlag) {
status = const JsonEncoder.withIndent(' ').convert(FlutterVersion.instance.toJson());
} else {
status = FlutterVersion.instance.toString();
......@@ -332,7 +333,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
return;
}
if (topLevelResults['machine'] as bool) {
if (machineFlag) {
throwToolExit('The --machine flag is only valid with the --version flag.', exitCode: 2);
}
await super.runCommand(topLevelResults);
......
......@@ -72,6 +72,22 @@ void main() {
Platform: () => platform,
}, initializeFlutterRoot: false);
testUsingContext('does not check that Flutter installation is up-to-date with --machine flag', () async {
final MockFlutterVersion version = FlutterVersion.instance as MockFlutterVersion;
bool versionChecked = false;
when(version.checkFlutterVersionFreshness()).thenAnswer((_) async {
versionChecked = true;
});
await runner.run(<String>['dummy', '--machine', '--version']);
expect(versionChecked, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => platform,
}, initializeFlutterRoot: false);
testUsingContext('throw tool exit if the version file cannot be written', () async {
final MockFlutterVersion version = FlutterVersion.instance as MockFlutterVersion;
when(version.ensureVersionFile()).thenThrow(const FileSystemException());
......
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