Unverified Commit c91a3a74 authored by Peter Lauri's avatar Peter Lauri Committed by GitHub

[flutter_tools] fix version tag `v` stripping (#55385)

parent 2f0d41b2
......@@ -87,7 +87,7 @@ class VersionCommand extends FlutterCommand {
}
}
final String version = argResults.rest[0].replaceFirst('v', '');
final String version = argResults.rest[0].replaceFirst(RegExp('^v'), '');
final List<String> matchingTags = tags.where((String tag) => tag.contains(version)).toList();
String matchingTag;
// TODO(fujino): make this a tool exit and fix tests
......
......@@ -71,6 +71,28 @@ void main() {
FlutterVersion: () => mockVersion,
});
testUsingContext('dev version switch prompt is accepted', () async {
when(mockStdio.stdinHasTerminal).thenReturn(true);
const String version = '30.0.0-dev.0.0';
final VersionCommand command = VersionCommand();
when(globals.terminal.promptForCharInput(<String>['y', 'n'],
logger: anyNamed('logger'),
prompt: 'Are you sure you want to proceed?')
).thenAnswer((Invocation invocation) async => 'y');
await createTestCommandRunner(command).run(<String>[
'version',
'--no-pub',
version,
]);
expect(testLogger.statusText, contains('Switching Flutter to version $version'));
}, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio,
AnsiTerminal: () => MockTerminal(),
FlutterVersion: () => mockVersion,
});
testUsingContext('version switch prompt is declined', () async {
when(mockStdio.stdinHasTerminal).thenReturn(true);
const String version = '10.0.0';
......@@ -239,7 +261,7 @@ class MockProcessManager extends Mock implements ProcessManager {
return ProcessResult(0, 0, 'v10.0.0\r\nv20.0.0\r\n30.0.0-dev.0.0', '');
}
if (command[0] == 'git' && command[1] == 'checkout') {
version = (command[2] as String).replaceFirst('v', '');
version = (command[2] as String).replaceFirst(RegExp('^v'), '');
}
return ProcessResult(0, 0, '', '');
}
......
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