* gdb.cp/abstract-origin.exp: Use standard_testfile.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / misc.exp
1 # Copyright 1992, 1994-1997, 1999, 2002, 2007-2012 Free Software
2 # Foundation, Inc.
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
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18
19 if { [skip_cplus_tests] } { continue }
20
21 standard_testfile .cc
22
23 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
24 return -1
25 }
26
27 #
28 # Deduce language of main()
29 #
30
31 proc deduce_language_of_main {} {
32 global gdb_prompt
33
34 # See what language gdb thinks main() is, prior to reading full symbols.
35 # I think this fails for COFF targets.
36 gdb_test "show language" \
37 "source language is \"auto; currently c\[+\]+\".*" \
38 "deduced language is C++, before full symbols"
39
40 runto_main
41
42 # See if our idea of the language has changed.
43
44 gdb_test "show language" \
45 "source language is \"auto; currently c\[+\]+\".*" \
46 "deduced language is C++, after full symbols"
47 }
48
49 proc test_expr { args } {
50 if { [llength $args] % 2 } {
51 warning "an even # of arguments should be passed to test_expr"
52 }
53 set last_ent [expr [llength $args] - 1];
54 set testname [lindex $args $last_ent];
55 if [gdb_test_no_output [lindex $args 0] "$testname (setup)"] {
56 gdb_suppress_tests;
57 }
58 for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} {
59 if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] {
60 gdb_suppress_tests;
61 }
62 }
63 gdb_stop_suppressing_tests;
64 }
65
66 proc do_tests {} {
67 deduce_language_of_main
68 # Check for fixes for PRs 8916 and 8630
69 gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)"
70 }
71
72 do_tests
73
74 test_expr "set language c++" \
75 "print 1 == 1" "print.*\\$\[0-9\]* = true" \
76 "print 1 == 2" "print.*\\$\[0-9\]* = false" \
77 "print as bool"
78
79 # Test bool type printing, etc.
80 # Note: Language is already set to C++ above!
81 gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var"
82
83 # set a bool variable
84 test_expr "set variable v_bool = true" \
85 "print v_bool" "\\$\[0-9\]* = true" \
86 "set a bool var"
87
88 # next print an array of bool
89 gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array"
90
91 # set elements of a bool array
92 test_expr "set variable v_bool_array\[1\] = true" \
93 "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \
94 "set a bool array elem"
95
96 # bool constants
97 gdb_test "print true" "\\$\[0-9\]* = true" "print true"
98 gdb_test "print false" "\\$\[0-9\]* = false" "print false"
99
100 # arithmetic conversions
101 gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true"
102 gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false"
103 gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3"
104 gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4"
105 gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43"
106 gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0"
107 gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93"
108 gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0"
109 gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true"
110 gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"
This page took 0.042545 seconds and 5 git commands to generate.