style-logging.exp revision 1.1.1.1
1# Copyright 2019-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 that logging does not style.
17
18# Do not run if gdb debug is enabled as it will interfere with log redirect.
19if {[gdb_debug_enabled]} {
20    untested "debug is enabled"
21    return 0
22}
23
24if {[is_remote host]} {
25    untested "does not work on remote host"
26    return 0
27}
28
29standard_testfile style.c
30
31save_vars { env(TERM) } {
32    # We need an ANSI-capable terminal to get the output.
33    setenv TERM ansi
34
35    if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
36	return -1
37    }
38
39    if {![runto_main]} {
40	fail "style tests failed"
41	return
42    }
43
44    gdb_test_no_output "set style enabled on"
45
46    set log_name [standard_output_file log.txt]
47    gdb_test_no_output "set logging file $log_name" \
48	"set logging filename"
49    gdb_test_no_output "set logging overwrite on"
50    gdb_test "set logging on" "Copying output to .*"
51
52    set main_expr [style main function]
53    set base_file_expr [style ".*style\\.c" file]
54    set file_expr "$base_file_expr:\[0-9\]"
55    set arg_expr [style "arg." variable]
56    gdb_test "frame" \
57	"$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
58
59    gdb_test "set logging off" "Done logging to .*"
60
61    set fd [open $log_name]
62    set data [read -nonewline $fd]
63    close $fd
64
65    set testname "log is escape-free"
66    if {[regexp "\033" $data]} {
67	fail $testname
68    } else {
69	pass $testname
70    }
71}
72