Reviewed and approved by Daniel Jacobowitz <drow@false.org>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / cond-expr.exp
CommitLineData
b6ba6518 1# Copyright 1998, 1999 Free Software Foundation, Inc.
c906108c
SS
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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Elena Zannoni (ezannoni@cygnus.com)
21
22# This file is part of the gdb testsuite
23
24#
25# test of evaluation of conditional expressions, with constants and
26# variables. Using the print and the whatis command
27# written with the only purpose in mind to cover the holes in the
28# eval.c file
29#
30# source file "int-type.c"
31#
32
33
34if $tracelevel then {
35 strace $tracelevel
36}
37
38# Check to see if we have an executable to test. If not, then either we
39# haven't tried to compile one, or the compilation failed for some reason.
40# In either case, just notify the user and skip the tests in this file.
41
42set testfile "int-type"
43set srcfile ${testfile}.c
44set binfile ${objdir}/${subdir}/${testfile}
fc91c6c2 45if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
c906108c
SS
46 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
47 }
48
49
50gdb_exit
51gdb_start
52gdb_reinitialize_dir $srcdir/$subdir
53gdb_load ${binfile}
54
55
56if ![runto_main] then {
57 perror "couldn't run to breakpoint"
58 continue
59}
60
61send_gdb "print (2 ? 3 : 4)\n"
62gdb_expect {
63 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
64 pass "print value of cond expr (const true)"
65 }
66 -re ".*$gdb_prompt $" { fail "print value of cond expr (const true)" }
67 timeout { fail "(timeout) print value of cond expr (const true)" }
68 }
69
70send_gdb "print (0 ? 3 : 4)\n"
71gdb_expect {
72 -re ".\[0-9\]* = 4.*$gdb_prompt $" {
73 pass "print value of cond expr (const false)"
74 }
75 -re ".*$gdb_prompt $" { fail "print value of cond expr (const false)" }
76 timeout { fail "(timeout) print value of cond expr (const false)" }
77 }
78
79gdb_test "set variable x=14" "" "set variable x=14"
80gdb_test "set variable y=2" "" "set variable y=2"
81gdb_test "set variable z=3" "" "set variable z=3"
82
83send_gdb "print (x ? y : z)\n"
84gdb_expect {
85 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
86 pass "print value of cond expr (var true)"
87 }
88 -re ".*$gdb_prompt $" { fail "print value of cond expr (var true)" }
89 timeout { fail "(timeout) print value of cond expr (var true)" }
90 }
91
92gdb_test "set variable x=0" "" "set variable x=0"
93
94send_gdb "print (x ? y : z)\n"
95gdb_expect {
96 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
97 pass "print value of cond expr (var false)"
98 }
99 -re ".*$gdb_prompt $" { fail "print value of cond expr (var false)" }
100 timeout { fail "(timeout) print value of cond expr (var false)" }
101 }
102
103
104send_gdb "whatis (0 ? 3 : 4)\n"
105gdb_expect {
106 -re "type = int.*$gdb_prompt $" {
107 pass "print whatis of cond expr"
108 }
109 -re ".*$gdb_prompt $" { fail "print whatis of cond expr" }
110 timeout { fail "(timeout) print whatis of cond expr" }
111 }
112
113
114
115
116
117
118
119
120
121
122
This page took 0.65836 seconds and 4 git commands to generate.