Add completion styling
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / style.exp
1 # Copyright 2018-2020 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Test CLI output styling.
17
18 standard_testfile
19
20 save_vars { env(TERM) } {
21 # We need an ANSI-capable terminal to get the output.
22 setenv TERM ansi
23
24 set test_macros 0
25 set options debug
26 get_compiler_info
27 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
28 lappend options additional_flags=-g3
29 set test_macros 1
30 }
31
32 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
33 $options]} {
34 return -1
35 }
36
37 set readnow [readnow]
38
39 if {![runto_main]} {
40 fail "style tests failed"
41 return
42 }
43
44 # Check that the source highlighter has not stripped away the leading
45 # newlines.
46 set main_line [gdb_get_line_number "break here"]
47 gdb_test "list $main_line,$main_line" "return.*some_called_function.*"
48
49 gdb_test_no_output "set style enabled on"
50
51 set main_expr [style main function]
52 set base_file_expr [style ".*style\\.c" file]
53 set file_expr "$base_file_expr:\[0-9\]"
54 set arg_expr [style "arg." variable]
55
56 gdb_test "frame" \
57 "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
58 gdb_test "info breakpoints" "$main_expr at $file_expr.*"
59
60 gdb_test_no_output "set style sources off"
61 gdb_test "frame" \
62 "\r\n\[^\033\]*break here.*" \
63 "frame without styling"
64 gdb_test_no_output "set style sources on"
65
66 gdb_test "break main" "file $base_file_expr.*"
67
68 gdb_test "print &main" " = .* [style $hex address] <$main_expr>"
69
70 # Regression test for a bug where line-wrapping would occur at the
71 # wrong spot with styling. There were different bugs at different
72 # widths, so try two.
73 foreach width {20 30} {
74 gdb_test_no_output "set width $width"
75 # There was also a bug where the styling could be wrong in the
76 # line listing; this is why the words from the source code are
77 # spelled out in the final result line of the test.
78 gdb_test "frame" \
79 [multi_line \
80 "#0 *$main_expr.*$arg_expr.*" \
81 ".*$arg_expr.*" \
82 ".* at .*$file_expr.*" \
83 "\[0-9\]+.*return.* break here .*"
84 ] \
85 "frame when width=$width"
86 }
87
88 if {$test_macros} {
89 set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
90 gdb_test "info macro SOME_MACRO" \
91 "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
92 }
93
94 set func [style some_called_function function]
95 # Somewhere should see the call to the function.
96 gdb_test "disassemble main" "[style $hex address].*$func.*"
97
98 set ifield [style int_field variable]
99 set sfield [style string_field variable]
100 set efield [style e_field variable]
101 set evalue [style VALUE_TWO variable]
102 gdb_test "print struct_value" \
103 "\{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*"
104
105 gdb_exit
106 gdb_spawn
107
108 set vers [style "GNU gdb.*" "35;1"]
109 gdb_test "" "${vers}.*" \
110 "version is styled"
111
112 set address_style_expr [style ".*\".*address.*\".*style.*" address]
113 gdb_test "show style address foreground" \
114 "The ${address_style_expr} foreground color is: blue" \
115 "style name and style word styled using its own style in show style"
116
117 set aliases_expr [style ".*aliases.*" title]
118 set breakpoints_expr [style ".*breakpoints.*" title]
119 gdb_test "help" \
120 [multi_line \
121 "List of classes of commands:" \
122 "" \
123 "${aliases_expr} -- Aliases of other commands\." \
124 "${breakpoints_expr} -- Making program stop at certain points\." \
125 ".*" \
126 ] \
127 "help classes of commands styled with title"
128
129 set taas_expr [style ".*taas.*" title]
130 set tfaas_expr [style ".*tfaas.*" title]
131 set cut_for_thre_expr [style "cut for 'thre" highlight]
132 gdb_test "apropos -v cut for 'thre" \
133 [multi_line \
134 "" \
135 "${taas_expr} --.*" \
136 "Usage:.*" \
137 "short${cut_for_thre_expr}ad apply.*" \
138 "" \
139 "${tfaas_expr} --.*" \
140 "Usage:.*" \
141 "short${cut_for_thre_expr}ad apply.*" \
142 ]
143
144 set quoted [string_to_regexp $binfile]
145 set pass_re "Reading symbols from [style $quoted file]\.\.\."
146 if { $readnow } {
147 set pass_re \
148 [multi_line \
149 $pass_re \
150 "Expanding full symbols from [style $quoted file]\.\.\."]
151 }
152 gdb_test "file $binfile" \
153 $pass_re \
154 "filename is styled when loading symbol file"
155
156 gdb_test "pwd" "Working directory [style .*? file].*"
157
158 gdb_test_no_output "set print repeat 3"
159 gdb_test "print {0,0,0,0,0,0,0,0}" \
160 " = \\{0 [style {<repeats.*8.*times>} metadata]\\}"
161
162 gdb_test "show logging file" \
163 "The current logfile is \"[style .*? file]\"\\..*"
164
165 # Check warnings are styled by setting a rubbish data directory.
166 gdb_test "set data-directory Makefile" \
167 "warning: [style .*? file] is not a directory\\..*"
168 gdb_test "show data-directory" \
169 "GDB's data directory is \"[style .*? file]\"\\..*"
170
171 if {[readline_is_used]} {
172 set test "complete print VALUE_"
173 # ESC-? is the readline binding to show all completions.
174 send_gdb "print VALUE_\x1b?"
175 set pfx [style VALUE_ completion-prefix]
176 set d1 [style O completion-difference]
177 set d2 [style T completion-difference]
178 gdb_test_multiple "" $test {
179 -re "${pfx}${d1}NE\[ \t\]+${pfx}${d2}WO.*$gdb_prompt print VALUE_$" {
180 gdb_test "ONE" " = .*"
181 }
182 }
183 }
184 }
This page took 0.034954 seconds and 4 git commands to generate.