Initial pass at Go language support.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.go / integers.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2012 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # Test integer expressions.
19
20 load_lib "go.exp"
21
22 if { [skip_go_tests] } { continue }
23
24 set testfile "integers"
25 set srcfile ${testfile}.go
26
27 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug go}] } {
28 return -1
29 }
30
31 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
32 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
33
34 if { [go_runto_main] < 0 } {
35 untested $testfile
36 return -1
37 }
38
39 if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
40 pass "setting breakpoint 1"
41 }
42
43 gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
44
45 gdb_test "print i" ".* = 0" "Print i before assigned to 1"
46
47 gdb_test "next" "i = 1" "Next to 'i = 1' line"
48 gdb_test "next" "j = 2" "Next to 'j = 2' line"
49 # At that point,
50 # i should be equal to 1
51 gdb_test "print i" " = 1"
52 # but j should still be equal to zero
53 gdb_test "print j" " = 0" "Test j value before assignment"
54
55 gdb_test "next" "k = 3" "Next to 'k = 3' line"
56 gdb_test "next" "l = k" "Next to 'l = k' line"
57
58 #j should be equal to 2
59 gdb_test "print j" " = 2"
60 # k should be equal to 3
61 gdb_test "print k" " = 3"
62 # But l should still be zero
63 gdb_test "print l" " = 0"
64
65 # Test addition
66 gdb_test "print i + j" " = 3"
67 gdb_test "print i + k" " = 4"
68 gdb_test "print j + k" " = 5"
69 gdb_test "print i + j + k" " = 6"
70
71 # Test substraction
72 gdb_test "print j - i" " = 1"
73 gdb_test "print i - j" "= -1"
74 gdb_test "print k -i -j" " = 0"
75 gdb_test "print k -(i + j)" " = 0"
76
77 # Test unany minus
78 gdb_test "print -i" " = -1"
79 gdb_test "print (-i)" " = -1"
80 gdb_test "print -(i)" " = -1"
81 gdb_test "print -(i+j)" " = -3"
82
83 # Test boolean operators =, <>, <, <=, > and >=
84 gdb_test "print i + 1 == j" " = true"
85 gdb_test "print i + 1 != j" " = false"
86 gdb_test "print i + 1 < j" " = false"
87 gdb_test "print i + 1 <= j" " = true"
88 gdb_test "print i + 1 > j" " = false"
89 gdb_test "print i + 1 >= j" " = true"
90
91 # Test multiplication
92 gdb_test "print 2 * i" " = 2"
93 gdb_test "print j * k" " = 6"
94 gdb_test "print 3000*i" " = 3000"
95
96 #Test div and mod operators
97 gdb_test "print 35 / 2" " = 17"
98 gdb_test "print 35 % 2" " = 1"
99
100 # Test several operators together
101 gdb_test "print i+10*j+100*k" " = 321"
102 gdb_test " print (i + 5) * (j + 7)" " = 54"
103
104 gdb_test "set var i = 2" " = 2"
105 gdb_test "print i" " = 2" "Testing new i value"
106
107 if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
108 pass "setting breakpoint 2"
109 }
110
111 gdb_test "cont" \
112 "Breakpoint .*:${bp_location2}.*" \
113 "Going to second breakpoint"
114 gdb_test "print i" \
115 ".* = 5.*" \
116 "Value of i after assignment"
This page took 0.034191 seconds and 5 git commands to generate.