Home | History | Annotate | Line # | Download | only in gdb.base
style.exp revision 1.1
      1  1.1  christos # Copyright 2018-2019 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # Test CLI output styling.
     17  1.1  christos 
     18  1.1  christos standard_testfile
     19  1.1  christos 
     20  1.1  christos save_vars { env(TERM) } {
     21  1.1  christos     # We need an ANSI-capable terminal to get the output.
     22  1.1  christos     setenv TERM ansi
     23  1.1  christos 
     24  1.1  christos     set test_macros 0
     25  1.1  christos     set options debug
     26  1.1  christos     get_compiler_info
     27  1.1  christos     if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
     28  1.1  christos 	lappend options additional_flags=-g3
     29  1.1  christos 	set test_macros 1
     30  1.1  christos     }
     31  1.1  christos 
     32  1.1  christos     if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
     33  1.1  christos 	     $options]} {
     34  1.1  christos 	return -1
     35  1.1  christos     }
     36  1.1  christos 
     37  1.1  christos     if {![runto_main]} {
     38  1.1  christos 	fail "style tests failed"
     39  1.1  christos 	return
     40  1.1  christos     }
     41  1.1  christos 
     42  1.1  christos     gdb_test_no_output "set style enabled on"
     43  1.1  christos 
     44  1.1  christos     set main_expr "\033\\\[33mmain\033\\\[m"
     45  1.1  christos     set base_file_expr "\033\\\[32m.*style\\.c\033\\\[m"
     46  1.1  christos     set file_expr "$base_file_expr:\[0-9\]"
     47  1.1  christos     set arg_expr "\033\\\[36marg.\033\\\[m"
     48  1.1  christos 
     49  1.1  christos     gdb_test "frame" \
     50  1.1  christos 	"$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
     51  1.1  christos     gdb_test "info breakpoints" "$main_expr at $file_expr.*"
     52  1.1  christos 
     53  1.1  christos     gdb_test_no_output "set style sources off"
     54  1.1  christos     gdb_test "frame" \
     55  1.1  christos 	"\r\n\[^\033\]*break here.*" \
     56  1.1  christos 	"frame without styling"
     57  1.1  christos     gdb_test_no_output "set style sources on"
     58  1.1  christos 
     59  1.1  christos     gdb_test "break main" "file $base_file_expr.*"
     60  1.1  christos 
     61  1.1  christos     gdb_test "print &main" " = .* \033\\\[34m$hex\033\\\[m <$main_expr>"
     62  1.1  christos 
     63  1.1  christos     # Regression test for a bug where line-wrapping would occur at the
     64  1.1  christos     # wrong spot with styling.  There were different bugs at different
     65  1.1  christos     # widths, so try two.
     66  1.1  christos     foreach width {20 30} {
     67  1.1  christos 	gdb_test_no_output "set width $width"
     68  1.1  christos 	# There was also a bug where the styling could be wrong in the
     69  1.1  christos 	# line listing; this is why the words from the source code are
     70  1.1  christos 	# spelled out in the final result line of the test.
     71  1.1  christos 	gdb_test "frame" \
     72  1.1  christos 	    [multi_line \
     73  1.1  christos 		 "#0 *$main_expr.*$arg_expr.*" \
     74  1.1  christos 		 ".*$arg_expr.*" \
     75  1.1  christos 		 ".* at .*$file_expr.*" \
     76  1.1  christos 		 "\[0-9\]+.*return.* break here .*"
     77  1.1  christos 	    ] \
     78  1.1  christos 	    "frame when width=$width"
     79  1.1  christos     }
     80  1.1  christos 
     81  1.1  christos     if {$test_macros} {
     82  1.1  christos 	gdb_test "info macro SOME_MACRO" \
     83  1.1  christos 	    "Defined at $base_file_expr:16\r\n#define SOME_MACRO 23"
     84  1.1  christos     }
     85  1.1  christos 
     86  1.1  christos     gdb_exit
     87  1.1  christos     gdb_spawn
     88  1.1  christos 
     89  1.1  christos     gdb_test "" "\033\\\[35;1mGNU gdb.*\033\\\[m.*" \
     90  1.1  christos 	"version is styled"
     91  1.1  christos 
     92  1.1  christos     set quoted [string_to_regexp $binfile]
     93  1.1  christos     gdb_test "file $binfile" \
     94  1.1  christos 	"Reading symbols from \033\\\[32m${quoted}\033\\\[m..." \
     95  1.1  christos 	"filename is styled when loading symbol file"
     96  1.1  christos }
     97