Fix linux argument completion with for "--" options (llvm.org/bugs/pr14425)

Patch by Yacine Belkadi!

When __GLIBC__ is defined, optind gets initialized to 0. So for the first parsed
option, parse_start is 0, too. If this option has no argument (Like "--continue"
of "process attach"), then the position stored is 0, instead of 1. This prevents
the completion later on in Options::HandleOptionCompletion() because the opt_pos
doesn't match the cursor_index.

Fix that by getting the option's position from the value of optind, as it's done
for the other types of options.

Re-enable test_process_attach_dash_dash_con() on Linux.

No regressions detected on Mac OS X (in TestCompletion.py)

llvm-svn: 180114
This commit is contained in:
Daniel Malea 2013-04-23 15:28:10 +00:00
parent 43cf90f4d1
commit 243b36931f
2 changed files with 1 additions and 3 deletions

View File

@ -1507,7 +1507,6 @@ Args::ParseArgsForCompletion
while (1)
{
bool missing_argument = false;
int parse_start = optind;
int long_options_index = -1;
val = ::getopt_long_only (dummy_vec.size() - 1,
@ -1601,7 +1600,7 @@ Args::ParseArgsForCompletion
switch (long_options[long_options_index].has_arg)
{
case no_argument:
option_element_vector.push_back (OptionArgElement (opt_defs_index, parse_start, 0));
option_element_vector.push_back (OptionArgElement (opt_defs_index, optind - 1, 0));
break;
case required_argument:
if (optarg != NULL)

View File

@ -29,7 +29,6 @@ class CommandLineCompletionTestCase(TestBase):
"""Test that 'de' completes to 'detach '."""
self.complete_from_to('de', 'detach ')
@expectedFailureLinux # PR-14425: completion broken for strings that begin with --
def test_process_attach_dash_dash_con(self):
"""Test that 'process attach --con' completes to 'process attach --continue '."""
self.complete_from_to('process attach --con', 'process attach --continue ')