diff options
author | Lancelot SIX <lsix@lancelotsix.com> | 2021-11-20 23:20:23 +0000 |
---|---|---|
committer | Lancelot SIX <lsix@lancelotsix.com> | 2022-01-07 22:43:33 +0000 |
commit | 86a839999883bc9d3ca304b0806cf50e171587cd (patch) | |
tree | 094503213ca338efea23f2eaf13ede81a6803fdc | |
parent | 0d3ca327972d34eeb4b74cf239aab3bf973a3c97 (diff) | |
download | gdb-86a839999883bc9d3ca304b0806cf50e171587cd.zip gdb-86a839999883bc9d3ca304b0806cf50e171587cd.tar.gz gdb-86a839999883bc9d3ca304b0806cf50e171587cd.tar.bz2 |
gdb: completion-support.exp: improve leading whitespace support
There is a expect support library in the source tree designed to help
developers test the auto-completion capabilities of GDB.
One of the functions is test_gdb_complete_unique_re. It is used
(usually indirectly via test_gdb_complete_unique) to test that a given
input line is completed as a given output line. The test checks for two
ways to do the completion: using tab-completion, or using the
'complete' command. To do this, calls to two dedicated functions are
performed. If we omit few details, we can consider that a call to
test_gdb_complete_unique $input $expected
is equivalent to the two following calls:
test_gdb_complete_tab_unique $input $expected
test_gdb_complete_cmd_unique $input $expected
When using the tab-completion, everything works as expected, but some
care must be taken when using the 'complete' command if the given input
has leading whitespaces. In such situation, the output of the
'complete' command will drop the leading whitespaces.
The current approach is that in such situation, the input and expected
outputs are right trimmed (i.e. all leading whitespaces are removed)
when performing the command completion check.
This means that the following call:
test_gdb_complete_unique " $input" " $expected"
is almost equivalent to (again, omitting few details and arguments):
test_gdb_complete_tab_unique " $input" " $expected"
test_gdb_complete_cmd_unique "$input" "$expected"
This approach comes with a problem that we encounter when running the
tests in complete-empty.exp. When doing so, we have:
Running .../gdb/testsuite/gdb.base/complete-empty.exp ...
DUPLICATE: gdb.base/complete-empty.exp: empty-input-line: cmd complete ""
This is because the test file does something like:
test_gdb_complete_unique "" "!" " " 1
test_gdb_complete_unique " " " !" " " 1¬
which, if we do the substitution introduced above is equivalent to:
test_gdb_complete_tab_unique "" "!"
test_gdb_complete_cmd_unique "" "!"
test_gdb_complete_tab_unique " " " !"
test_gdb_complete_cmd_unique "" "!"
We see that the lines 2 and 4 are now the same, and for this reason the
testing framework complains about DUPLICATE test names.
To fix that, this commit proposes that instead of left trimming both
input and expected outputs, only the expected output is trimmed.
Care must be taken in the case the completion gives more possibilities
than allowed by the max-completions setting. In this case, the input
will be repeated in the output in its left trimmed version. This commit
also ensures that this is taken care of.
With this commit, the gdb.base/complete-empty.exp still passes all its
tests but does not report the DUPLICATE anymore.
Tested on x86_64-linux.
-rw-r--r-- | gdb/testsuite/lib/completion-support.exp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp index 52b1bcc..30d3461 100644 --- a/gdb/testsuite/lib/completion-support.exp +++ b/gdb/testsuite/lib/completion-support.exp @@ -254,10 +254,8 @@ proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} } } - # Trim INPUT_LINE and COMPLETE LINE, for the case we're completing - # a command with leading whitespace. Leading command whitespace - # is discarded by GDB. - set input_line [string trimleft $input_line] + # Trim COMPLETE LINE, for the case we're completing a command with leading + # whitespace. Leading command whitespace is discarded by GDB. set expected_output_re [string trimleft $complete_line_re] if {$append_char_re != " "} { append expected_output_re $append_char_re @@ -266,7 +264,7 @@ proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} set max_completion_reached_msg \ "*** List may be truncated, max-completions reached. ***" set input_line_re \ - [string_to_regexp $input_line] + [string_to_regexp [string trimleft $input_line]] set max_completion_reached_msg_re \ [string_to_regexp $max_completion_reached_msg] |