[v2,3/5] gdb/testsuite: Test completion of convenience variables

Message ID 20240828014916.162446-4-nt8r@protonmail.com
State New
Headers
Series Tab complete convenience variables |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Test failed

Commit Message

Antonio Rische Aug. 28, 2024, 1:50 a.m. UTC
  ---
 gdb/testsuite/gdb.base/completion.exp | 39 +++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
  

Comments

Keith Seitz Aug. 30, 2024, 7:34 p.m. UTC | #1
Thank you so very much for adding tests!

On 8/27/24 6:50 PM, Antonio Rische wrote:
> ---

No commit message? Even something as (redundant as) "This patch adds
tests for the completion of convenience variables and functions."

>   gdb/testsuite/gdb.base/completion.exp | 39 +++++++++++++++++++++++++++
>   1 file changed, 39 insertions(+)
> 
> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 4a0a373fe..131c36e23 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -1005,3 +1005,42 @@ foreach_with_prefix spc { " " "" } {
>   	    }
>       }
>   }
> +
> +# Test command completion with convenience variables.
> +test_gdb_complete_unique \
> +    "print \$_sigin" \
> +    "print \$_siginfo"
> +
> +test_gdb_complete_unique \
> +    "print \$_siginfo" \
> +    "print \$_siginfo"
> +
> +test_gdb_complete_unique \
> +    "print \$_gdb_maj" \
> +    "print \$_gdb_major"
> +
> +test_gdb_complete_unique "print \$_gdb_maint_setting_str" "print \$_gdb_maint_setting_str"

This is actually a convenience function, so kudos for dealing with those
as well.

> +
> +test_gdb_complete_tab_multiple "print \$_gdb_mai" "nt_setting" {
> +	"_gdb_maint_setting"
> +	"_gdb_maint_setting_str"
> +    }
> +
> +test_gdb_complete_cmd_multiple "" "print \$_gdb_maint_setting" {
> +	"print \$_gdb_maint_setting"
> +	"print \$_gdb_maint_setting_str"
> +    }
> +
> +# Check that a nonexisting convenience variable is not completed.
> +test_gdb_complete_none "print \$unique_variable_1234567"
> +test_gdb_complete_none "set \$unique_variable_1234567"
> +
> +# Check that after defining the convenience variable it is completed.
> +set test "complete 'print \$unique_variable_123456'"
> +send_gdb "set \$unique_variable_1234567=4\n"
> +send_gdb "p \$unique_variable_123456\t"
> +gdb_test_multiple "" "$test" {
> +    -re "$gdb_prompt p \\\$unique_variable_1234567 $" {
> +	pass "$test"
> +    }
> +}

You should not need to use "send_gdb" directly. "gdb_test" is much simpler:

gdb_test_no_output "set var \$unique_variable=4"
gdb_test "p \$unique_variable" "= 4"

Reviewed-by: Keith Seitz <keiths@redhat.com>

Keith
  
Antonio Rische Sept. 1, 2024, 9:25 p.m. UTC | #2
As suggested elsewhere I'll merge the test-adding commits with those that add the tested functionality.

I'll change the testing to avoid using `send_gdb` directly.

Thanks,
Antonio

On Friday, August 30th, 2024 at 7:34 PM, Keith Seitz <keiths@redhat.com> wrote:

> Thank you so very much for adding tests!
> 
> On 8/27/24 6:50 PM, Antonio Rische wrote:
> 
> > ---
> 
> 
> No commit message? Even something as (redundant as) "This patch adds
> tests for the completion of convenience variables and functions."
> 
> > gdb/testsuite/gdb.base/completion.exp | 39 +++++++++++++++++++++++++++
> > 1 file changed, 39 insertions(+)
> > 
> > diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> > index 4a0a373fe..131c36e23 100644
> > --- a/gdb/testsuite/gdb.base/completion.exp
> > +++ b/gdb/testsuite/gdb.base/completion.exp
> > @@ -1005,3 +1005,42 @@ foreach_with_prefix spc { " " "" } {
> > }
> > }
> > }
> > +
> > +# Test command completion with convenience variables.
> > +test_gdb_complete_unique \
> > + "print \$_sigin" \
> > + "print \$_siginfo"
> > +
> > +test_gdb_complete_unique \
> > + "print \$_siginfo" \
> > + "print \$_siginfo"
> > +
> > +test_gdb_complete_unique \
> > + "print \$_gdb_maj" \
> > + "print \$_gdb_major"
> > +
> > +test_gdb_complete_unique "print \$_gdb_maint_setting_str" "print \$_gdb_maint_setting_str"
> 
> 
> This is actually a convenience function, so kudos for dealing with those
> as well.
> 
> > +
> > +test_gdb_complete_tab_multiple "print \$_gdb_mai" "nt_setting" {
> > + "_gdb_maint_setting"
> > + "_gdb_maint_setting_str"
> > + }
> > +
> > +test_gdb_complete_cmd_multiple "" "print \$_gdb_maint_setting" {
> > + "print \$_gdb_maint_setting"
> > + "print \$_gdb_maint_setting_str"
> > + }
> > +
> > +# Check that a nonexisting convenience variable is not completed.
> > +test_gdb_complete_none "print \$unique_variable_1234567"
> > +test_gdb_complete_none "set \$unique_variable_1234567"
> > +
> > +# Check that after defining the convenience variable it is completed.
> > +set test "complete 'print \$unique_variable_123456'"
> > +send_gdb "set \$unique_variable_1234567=4\n"
> > +send_gdb "p \$unique_variable_123456\t"
> > +gdb_test_multiple "" "$test" {
> > + -re "$gdb_prompt p \\\$unique_variable_1234567 $" {
> > + pass "$test"
> > + }
> > +}
> 
> 
> You should not need to use "send_gdb" directly. "gdb_test" is much simpler:
> 
> gdb_test_no_output "set var \$unique_variable=4"
> gdb_test "p \$unique_variable" "= 4"
> 
> Reviewed-by: Keith Seitz keiths@redhat.com
> 
> 
> Keith
  

Patch

diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 4a0a373fe..131c36e23 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -1005,3 +1005,42 @@  foreach_with_prefix spc { " " "" } {
 	    }
     }
 }
+
+# Test command completion with convenience variables.
+test_gdb_complete_unique \
+    "print \$_sigin" \
+    "print \$_siginfo"
+
+test_gdb_complete_unique \
+    "print \$_siginfo" \
+    "print \$_siginfo"
+
+test_gdb_complete_unique \
+    "print \$_gdb_maj" \
+    "print \$_gdb_major"
+
+test_gdb_complete_unique "print \$_gdb_maint_setting_str" "print \$_gdb_maint_setting_str"
+
+test_gdb_complete_tab_multiple "print \$_gdb_mai" "nt_setting" {
+	"_gdb_maint_setting"
+	"_gdb_maint_setting_str"
+    }
+
+test_gdb_complete_cmd_multiple "" "print \$_gdb_maint_setting" {
+	"print \$_gdb_maint_setting"
+	"print \$_gdb_maint_setting_str"
+    }
+
+# Check that a nonexisting convenience variable is not completed.
+test_gdb_complete_none "print \$unique_variable_1234567"
+test_gdb_complete_none "set \$unique_variable_1234567"
+
+# Check that after defining the convenience variable it is completed.
+set test "complete 'print \$unique_variable_123456'"
+send_gdb "set \$unique_variable_1234567=4\n"
+send_gdb "p \$unique_variable_123456\t"
+gdb_test_multiple "" "$test" {
+    -re "$gdb_prompt p \\\$unique_variable_1234567 $" {
+	pass "$test"
+    }
+}