[14/16] gdb/testsuite: test get/set value of unregistered Guile parameter

Message ID 20210714045520.1623120-15-simon.marchi@polymtl.ca
State New
Headers show
Series
  • Bunch of commands related cleanups
Related show

Commit Message

Simon Marchi via Gdb-patches July 14, 2021, 4:55 a.m.
When creating a parameter in Guile, you have to create it using
make-parameter and then register it with GDB with register-parameter!.
In between, it's still possible (though not documented) to set the
parameter's value.  I broke this use case by mistake while writing this
series, so thought it would be good to have a test for it.

I suppose that people could use this "feature" to give their parameter
an initial value, even though make-parameter has an initial-value
parameter for this.  Nevertheless, changing this behavior could break
some scripts, which is why I think it's important for it to be tested.

Change-Id: I5b2103e3cec0cfdcccf7ffb00eb05fed8626e66d
---
 gdb/testsuite/gdb.guile/scm-parameter.exp | 8 ++++++++
 1 file changed, 8 insertions(+)

-- 
2.32.0

Comments

Simon Marchi via Gdb-patches July 23, 2021, 7:42 p.m. | #1
On 2021-07-14 12:55 a.m., Simon Marchi wrote:
> When creating a parameter in Guile, you have to create it using

> make-parameter and then register it with GDB with register-parameter!.

> In between, it's still possible (though not documented) to set the

> parameter's value.  I broke this use case by mistake while writing this

> series, so thought it would be good to have a test for it.

> 

> I suppose that people could use this "feature" to give their parameter

> an initial value, even though make-parameter has an initial-value

> parameter for this.  Nevertheless, changing this behavior could break

> some scripts, which is why I think it's important for it to be tested.

> 

> Change-Id: I5b2103e3cec0cfdcccf7ffb00eb05fed8626e66d

> ---

>  gdb/testsuite/gdb.guile/scm-parameter.exp | 8 ++++++++

>  1 file changed, 8 insertions(+)

> 

> diff --git a/gdb/testsuite/gdb.guile/scm-parameter.exp b/gdb/testsuite/gdb.guile/scm-parameter.exp

> index 67120b233664..5a2fb42503d0 100644

> --- a/gdb/testsuite/gdb.guile/scm-parameter.exp

> +++ b/gdb/testsuite/gdb.guile/scm-parameter.exp

> @@ -176,6 +176,14 @@ with_test_prefix "test-restricted-param" {

>  gdb_test "guile (register-parameter! (make-parameter \"height\"))" \

>      "ERROR.*is already defined.*" "error registering existing parameter"

>  

> +# Test printing and setting the value of an unregistered parameter.

> +gdb_test "guile (print (parameter-value (make-parameter \"foo\")))" \

> +    "= #f"

> +gdb_test "guile (define myparam (make-parameter \"foo\"))"

> +gdb_test_no_output "guile (set-parameter-value! myparam #t)"

> +gdb_test "guile (print (parameter-value myparam))" \

> +    "= #t"

> +

>  # Test registering a parameter named with what was an ambiguous spelling

>  # of existing parameters.

>  

> 


I pushed everything up to this point.

Simon

Patch

diff --git a/gdb/testsuite/gdb.guile/scm-parameter.exp b/gdb/testsuite/gdb.guile/scm-parameter.exp
index 67120b233664..5a2fb42503d0 100644
--- a/gdb/testsuite/gdb.guile/scm-parameter.exp
+++ b/gdb/testsuite/gdb.guile/scm-parameter.exp
@@ -176,6 +176,14 @@  with_test_prefix "test-restricted-param" {
 gdb_test "guile (register-parameter! (make-parameter \"height\"))" \
     "ERROR.*is already defined.*" "error registering existing parameter"
 
+# Test printing and setting the value of an unregistered parameter.
+gdb_test "guile (print (parameter-value (make-parameter \"foo\")))" \
+    "= #f"
+gdb_test "guile (define myparam (make-parameter \"foo\"))"
+gdb_test_no_output "guile (set-parameter-value! myparam #t)"
+gdb_test "guile (print (parameter-value myparam))" \
+    "= #t"
+
 # Test registering a parameter named with what was an ambiguous spelling
 # of existing parameters.