Skip to content

Commit

Permalink
[lldb] Fix and test completion for ambiguous long options
Browse files Browse the repository at this point in the history
The refactoring patch for the option completion broke the completion
for ambiguous long options. As this feature was also untested (as
testing ambiguous options with the current test methods is impossible),
I just noticed now. This patch restores the old behavior and adds a
test for this feature.

llvm-svn: 370185
  • Loading branch information
Teemperor committed Aug 28, 2019
1 parent 1c5b143 commit efb8b7b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def test_process_launch_arch(self):
['mips',
'arm64'])

@skipIfFreeBSD # timing out on the FreeBSD buildbot
def test_ambiguous_long_opt(self):
self.completions_match('breakpoint modify --th',
['--thread-id',
'--thread-index',
'--thread-name'])

@skipIfFreeBSD # timing out on the FreeBSD buildbot
def test_plugin_load(self):
self.complete_from_to('plugin load ', [])
Expand Down
10 changes: 10 additions & 0 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,16 @@ def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
compare_string, msg=COMPLETION_MSG(
str_input, p, match_strings), exe=False, patterns=[p])

def completions_match(self, command, completions):
"""Checks that the completions for the given command are equal to the
given list of completions"""
interp = self.dbg.GetCommandInterpreter()
match_strings = lldb.SBStringList()
interp.HandleCompletion(command, len(command), 0, -1, match_strings)
# match_strings is a 1-indexed list, so we have to slice...
self.assertItemsEqual(completions, list(match_strings)[1:],
"List of returned completion is wrong")

def filecheck(
self,
command,
Expand Down
14 changes: 4 additions & 10 deletions lldb/source/Interpreter/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,11 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
// elements
// that are not unique up to this point. getopt_long_only does
// shortest unique match for long options already.

if (cur_opt_str.startswith("--")) {
if (cur_opt_str.consume_front("--")) {
for (auto &def : opt_defs) {
if (!def.long_option)
continue;

if (cur_opt_str.startswith(def.long_option)) {
std::string full_name("--");
full_name.append(def.long_option);
request.AddCompletion(full_name);
}
llvm::StringRef long_option(def.long_option);
if (long_option.startswith(cur_opt_str))
request.AddCompletion("--" + long_option.str());
}
}
return true;
Expand Down

0 comments on commit efb8b7b

Please sign in to comment.