Unverified Commit 0116b2e7 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] fix RangeError in flutter channel command (#103766)

parent 2ad7ced9
......@@ -79,6 +79,10 @@ class ChannelCommand extends FlutterCommand {
for (final String line in rawOutput) {
final List<String> split = line.split('/');
if (split.length != 2) {
// We don't know how to parse this line, skip it.
continue;
}
final String branch = split[1];
if (split.length > 1) {
final int index = officialChannels.indexOf(branch);
......
......@@ -136,6 +136,38 @@ void main() {
FileSystem: () => MemoryFileSystem.test(),
});
testUsingContext('ignores lines with unexpected output', () async {
fakeProcessManager.addCommand(
const FakeCommand(
command: <String>['git', 'branch', '-r'],
stdout: 'origin/beta\n'
'origin/stable\n'
'upstream/beta\n'
'upstream/stable\n'
'foo',
),
);
final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['channel']);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
expect(testLogger.errorText, hasLength(0));
// format the status text for a simpler assertion.
final Iterable<String> rows = testLogger.statusText
.split('\n')
.map((String line) => line.trim())
.where((String line) => line?.isNotEmpty == true)
.skip(1); // remove `Flutter channels:` line
expect(rows, <String>['beta', 'stable', 'Currently not on an official channel.']);
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
});
testUsingContext('removes duplicates', () async {
fakeProcessManager.addCommand(
const FakeCommand(
......
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