]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/alias.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / alias.exp
CommitLineData
5a56e9c5 1# Test the alias command.
3666a048 2# Copyright 2011-2021 Free Software Foundation, Inc.
5a56e9c5
DE
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17gdb_exit
18gdb_start
19gdb_reinitialize_dir $srcdir/$subdir
20
21# Helper to test the -a option to alias.
22# Aliases that are abbreviations of commands (e.g. r -> run)
23# do not appear in help output.
24
25proc test_abbrev_not_present { alias_name } {
26 global gdb_prompt
27 set alias_present 0
28 set test_name "abbrev $alias_name not present in help command list"
29 gdb_test_multiple "help aliases" $test_name {
30 -re "\[\r\n\]$alias_name \[^\r\n\]*" {
31 set alias_present 1
32 exp_continue
33 }
34 -re ".*$gdb_prompt $" {
35 if { !$alias_present } then {
36 pass $test_name
37 } else {
38 fail $test_name
39 }
40 }
41 }
42}
43
44proc test_abbrev_alias { name gdb_command test_value } {
45 gdb_test_no_output $gdb_command
46 gdb_test_no_output "$name print elements $test_value"
47 gdb_test "show print elements" "Limit .* is $test_value\[.\]" "verify $name"
48 test_abbrev_not_present $name
49}
50
51test_abbrev_alias set2 "alias -a set2=set" 42
52test_abbrev_alias set3 "alias -a set3= set" 43
53test_abbrev_alias set4 "alias -a set4 =set" 44
54test_abbrev_alias set5 "alias -a set5 = set" 45
55test_abbrev_alias set6 "alias -a -- set6 = set" 46
56test_abbrev_alias -a "alias -a -- -a = set" 47
57
58gdb_test "alias set2=set" "already exists: set2"
746ebfe8 59gdb_test "alias foo=bar" "Undefined command: \"bar\". Try \"help\"."
5a56e9c5
DE
60
61gdb_test_no_output "alias spe = set p elem"
62gdb_test_no_output "spe 50"
63gdb_test "show print elements" "Limit .* is 50\[.\]" "verify spe"
64
65gdb_test_no_output "alias set pr elms = set p elem"
66gdb_test_no_output "set pr elms 51"
67gdb_test "show print elements" "Limit .* is 51\[.\]" "verify set pr elms"
3b3aaacb 68gdb_test "help set print" "set print elements, set print elms, spe .*"
b65b566c
PW
69
70# Verify alias command detects a non existing prefix.
71gdb_test "alias assigne imprime limite-elements = set print elements" \
72 "ALIAS and COMMAND prefixes do not match\." \
73 "assigne imprime prefix not defined"
74
75gdb_test "alias set imprime limite-elements = set print elements" \
76 "ALIAS and COMMAND prefixes do not match\." \
77 "set imprime prefix not defined"
78
79# Verify alias command detects a non matching prefix.
80gdb_test "alias set ada limite-elements = set print elements" \
81 "ALIAS and COMMAND prefixes do not match\." \
82 "mismatched prefix"
83
84# Verify alias command detects a non matching prefix due to length.
85gdb_test "alias set imprime-limite-elements = set print elements" \
86 "Mismatched command length between ALIAS and COMMAND\." \
87 "mismatched length"
88
89
90# Gradually define the prefixes and the limite-elements command.
91gdb_test_no_output "alias assigne = set" "alias assigne"
92gdb_test_no_output "alias assigne imprime = set print" "alias assigne imprime"
93gdb_test_no_output "alias assigne imprime limite-elements = set print elements" \
94 "alias assigne imprime limite-elements"
95
96# Define an alias using the command prefix with a command using an alias prefix.
97gdb_test_no_output "alias set print max-elements = assigne imprime elements" \
98 "alias set print max-elements using assigne imprime"
99
100
101# Tests the resulting prefixes and commands.
102gdb_test_no_output "assigne print elements 52"
103gdb_test "show print elements" "Limit .* is 52\[.\]" "verify 52"
104
105gdb_test_no_output "assigne imprime elements 53"
106gdb_test "show print elements" "Limit .* is 53\[.\]" "verify 53"
107
108gdb_test_no_output "assigne imprime limite-elements 54"
109gdb_test "show print elements" "Limit .* is 54\[.\]" "verify 54"
110
111gdb_test_no_output "set imprime elements 55"
112gdb_test "show print elements" "Limit .* is 55\[.\]" "verify 55"
113
114gdb_test_no_output "set print limite-elements 56"
115gdb_test "show print elements" "Limit .* is 56\[.\]" "verify 56"
116
117gdb_test_no_output "set print max-elements 57"
118gdb_test "show print elements" "Limit .* is 57\[.\]" "verify 57"
0605465f
PW
119
120# Test aliases having a common prefix.
121gdb_test_no_output "alias abcd = backtrace"
122gdb_test_no_output "alias abcde = backtrace"
123gdb_test_no_output "alias fghij = backtrace"
124gdb_test_no_output "alias fghi = backtrace"
57b4f16e
PW
125
126# Verify help aliases shows the user defined aliases
127gdb_test "help aliases" ".*abcd --.*.*abcde --.*"