From 86a839999883bc9d3ca304b0806cf50e171587cd Mon Sep 17 00:00:00 2001 From: Lancelot SIX Date: Sat, 20 Nov 2021 23:20:23 +0000 Subject: [PATCH] gdb: completion-support.exp: improve leading whitespace support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- gdb/testsuite/lib/completion-support.exp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp index 52b1bcc3f32..30d3461c226 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] -- 2.30.2