Skip to content

Commit c91a3a7

Browse files
authored
[flutter_tools] fix version tag v stripping (flutter#55385)
1 parent 2f0d41b commit c91a3a7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/flutter_tools/lib/src/commands/version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class VersionCommand extends FlutterCommand {
8787
}
8888
}
8989

90-
final String version = argResults.rest[0].replaceFirst('v', '');
90+
final String version = argResults.rest[0].replaceFirst(RegExp('^v'), '');
9191
final List<String> matchingTags = tags.where((String tag) => tag.contains(version)).toList();
9292
String matchingTag;
9393
// TODO(fujino): make this a tool exit and fix tests

packages/flutter_tools/test/commands.shard/hermetic/version_test.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ void main() {
7171
FlutterVersion: () => mockVersion,
7272
});
7373

74+
testUsingContext('dev version switch prompt is accepted', () async {
75+
when(mockStdio.stdinHasTerminal).thenReturn(true);
76+
const String version = '30.0.0-dev.0.0';
77+
final VersionCommand command = VersionCommand();
78+
when(globals.terminal.promptForCharInput(<String>['y', 'n'],
79+
logger: anyNamed('logger'),
80+
prompt: 'Are you sure you want to proceed?')
81+
).thenAnswer((Invocation invocation) async => 'y');
82+
83+
await createTestCommandRunner(command).run(<String>[
84+
'version',
85+
'--no-pub',
86+
version,
87+
]);
88+
expect(testLogger.statusText, contains('Switching Flutter to version $version'));
89+
}, overrides: <Type, Generator>{
90+
ProcessManager: () => MockProcessManager(),
91+
Stdio: () => mockStdio,
92+
AnsiTerminal: () => MockTerminal(),
93+
FlutterVersion: () => mockVersion,
94+
});
95+
7496
testUsingContext('version switch prompt is declined', () async {
7597
when(mockStdio.stdinHasTerminal).thenReturn(true);
7698
const String version = '10.0.0';
@@ -239,7 +261,7 @@ class MockProcessManager extends Mock implements ProcessManager {
239261
return ProcessResult(0, 0, 'v10.0.0\r\nv20.0.0\r\n30.0.0-dev.0.0', '');
240262
}
241263
if (command[0] == 'git' && command[1] == 'checkout') {
242-
version = (command[2] as String).replaceFirst('v', '');
264+
version = (command[2] as String).replaceFirst(RegExp('^v'), '');
243265
}
244266
return ProcessResult(0, 0, '', '');
245267
}

0 commit comments

Comments
 (0)