[Lldb-commits] [lldb] r370185 - [lldb] Fix and test completion for ambiguous long options
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 28 03:17:23 PDT 2019
Author: teemperor
Date: Wed Aug 28 03:17:23 2019
New Revision: 370185
URL: http://llvm.org/viewvc/llvm-project?rev=370185&view=rev
Log:
[lldb] Fix and test completion for ambiguous long options
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.
Modified:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py
lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
lldb/trunk/source/Interpreter/Options.cpp
Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py?rev=370185&r1=370184&r2=370185&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py Wed Aug 28 03:17:23 2019
@@ -91,6 +91,13 @@ class CommandLineCompletionTestCase(Test
'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 ', [])
Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py?rev=370185&r1=370184&r2=370185&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py Wed Aug 28 03:17:23 2019
@@ -2194,6 +2194,16 @@ class TestBase(Base):
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,
Modified: lldb/trunk/source/Interpreter/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=370185&r1=370184&r2=370185&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Options.cpp (original)
+++ lldb/trunk/source/Interpreter/Options.cpp Wed Aug 28 03:17:23 2019
@@ -706,17 +706,11 @@ bool Options::HandleOptionCompletion(Com
// 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;
More information about the lldb-commits
mailing list