Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.guile / guile.exp
blob7c8fb18dc81d26ffb8bc7123b2ba6ecc780f9d18
1 # Copyright (C) 2008-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 # This file is part of the GDB testsuite.
17 # It tests basic Guile features.
19 load_lib gdb-guile.exp
21 clean_restart
23 set host_source2_scm [gdb_remote_download host $srcdir/$subdir/source2.scm]
25 # Do this instead of the skip_guile_check.
26 # We want to do some tests when Guile is not present.
27 gdb_test_multiple "guile (display 23) (newline)" "verify guile support" {
28     -re "Undefined command.*$gdb_prompt $" {
29         unsupported "guile not supported."
30         return
31     }
32     -re "not supported.*$gdb_prompt $"  {
33       unsupported "guile support is disabled"
35       # If Guile is not supported, verify that sourcing a guile script
36       # causes an error.
37       gdb_test "source $host_source2_scm" \
38           "Error in sourced command file:.*" \
39           "source source2.scm when guile disabled"
41       # Verify multi-line guile commands cause an error.
42       gdb_test_multiline "multi-line guile command" \
43           "guile" "" \
44           "(print 23)" "" \
45           "end" "not supported.*"
47       return
48     }
49     -re "$gdb_prompt $" {}
52 gdb_install_guile_utils
53 gdb_install_guile_module
55 gdb_test_multiline "multi-line guile command" \
56   "guile" "" \
57   "(print 23)" "" \
58   "end" "= 23"
60 gdb_test_multiline "show guile command" \
61   "define zzq" "Type commands for definition of .* just \"end\"\\.*" \
62   "guile" "" \
63   "(print 23)" "" \
64   "end" "" \
65   "end" "" \
66   "show user zzq" "User command \"zzq\":.*  guile.*\\(print 23\\).*  end\r\n"
68 gdb_test "source $host_source2_scm" "yes" "source source2.scm"
70 gdb_test "source -s source2.scm" "yes"
72 gdb_test "guile (print (current-objfile))" "= #f"
73 gdb_test "guile (print (objfiles))" "= \\(\\)"
75 gdb_test_no_output \
76     {guile (define x (execute "printf \"%d\", 23" #:to-string #t))}
77 gdb_test "guile (print x)" "= 23"
79 gdb_test_no_output "guile (define a (execute \"help\" #:to-string #t))" \
80     "collect help from uiout"
82 gdb_test "guile (print a)" "= .*aliases -- User-defined aliases of other commands.*" \
83     "verify help to uiout"
85 # Verify that we can source a guile script using ~ for the HOME directory.
86 if { ![is_remote host ] } {
87     save_vars { env(HOME) } {
88         # Create a new directory to act as a temporary HOME directory.
89         set tmp_home [standard_output_file tmp_home]
90         file mkdir $tmp_home
92         # Copy the file we want to source into the new HOME directory.
93         gdb_remote_download host ${srcdir}/${subdir}/source2.scm \
94             ${tmp_home}/source2.scm
96         # Arrange to use the new HOME directory.
97         set env(HOME) $tmp_home
98         clean_restart
100         # Finally, source the file out of our new HOME directory.
101         gdb_test "source ~/source2.scm" "yes"
102     }