Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.rust / expr.exp
CommitLineData
88b9d363 1# Copyright (C) 2016-2022 Free Software Foundation, Inc.
67218854
TT
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 basic expression parsing and evaluation, without requiring a
17# Rust compiler. This serves as a smoke test.
18
19load_lib "rust-support.exp"
20if {[skip_rust_tests]} { continue }
21
22gdb_start
23
24gdb_test_no_output "set var \$something = 27"
25
26if {![set_lang_rust]} {
27 warning "Rust expression tests suppressed."
28 continue
29}
30
31gdb_test "print 9__97" " = 997"
32gdb_test "print -5" " = -5"
33gdb_test "print +5" " = 5"
34gdb_test "print +-+-5" " = 5"
35gdb_test "print 3_2i32" " = 32"
36gdb_test "print 32i64" " = 32"
37gdb_test "print 8u8" " = 8"
38gdb_test "print 0x1f" " = 31"
39gdb_test "print 0o07" " = 7"
40gdb_test "print 0o70" " = 56"
41gdb_test "print 0b1_111" " = 15"
42gdb_test "print 32usize" " = 32"
43gdb_test "print 0x_4" " = 4"
44
45gdb_test "print 'z'" " = 122 'z'"
46gdb_test "print '\\t'" " = 9 '\\\\t'"
47gdb_test "print '\\n'" " = 10 '\\\\n'"
48gdb_test "print '\\r'" " = 13 '\\\\r'"
49gdb_test "print '\\\\'" " = 92 '\\\\\\\\'"
50gdb_test "print '\\0'" " = 0 '\\\\0'"
51gdb_test "print '\\''" " = 39 '\\\\''"
52gdb_test "print '\\\"'" " = 34 '\"'"
53gdb_test "print '\\xff'" " = 255 '\\\\xff'"
54gdb_test "print '\\xFF'" " = 255 '\\\\xff'"
55gdb_test "print '\\u\{F0eF\}'" " = 61679 '\\\\u\\{00f0ef\\}'"
56
57gdb_test "print b'z'" " = 122"
58gdb_test "print b'\\xfe'" " = 254"
59gdb_test "print b'\\t'" " = 9"
60gdb_test "print b'\\n'" " = 10"
61gdb_test "print b'\\r'" " = 13"
62gdb_test "print b'\\\\'" " = 92"
63gdb_test "print b'\\0'" " = 0"
64gdb_test "print b'\\''" " = 39"
65gdb_test "print b'\\\"'" " = 34"
66gdb_test "print b'\\xff'" " = 255"
67
68gdb_test "print 23.5" " = 23.5"
69gdb_test "print 23.5e1" " = 235"
70gdb_test "print 2e4" " = 20000"
71gdb_test "print 2_E+4_f64" " = 20000"
72gdb_test "print 5e-1" " = 0.5"
73gdb_test "print 5e-1f32" " = 0.5"
74
75gdb_test "print false" " = false"
76gdb_test "print true" " = true"
77
78gdb_test "print 1+2" " = 3"
79gdb_test "print 1i32 + 2i32" " = 3"
80gdb_test "print 2.0 - 1.0" " = 1"
81gdb_test "print !false" " = true"
82gdb_test "print !true" " = false"
83gdb_test "print !0u8" " = 255"
84gdb_test "print 7 * 7" " = 49"
85gdb_test "print 7usize * 7usize" " = 49"
86gdb_test "print 42 / 7" " = 6"
87gdb_test "print 42 % 7" " = 0"
88gdb_test "print 1.0 / 2.0" " = 0.5"
89gdb_test "print 1 < 2" " = true"
90gdb_test "print !(1 < 2)" " = false"
91gdb_test "print 3 + 4 * 7" " = 31"
92gdb_test "print 1 > 2" " = false"
93gdb_test "print 1 | 2" " = 3"
94gdb_test "print 1 & 2" " = 0"
95gdb_test "print 3 & 2" " = 2"
96gdb_test "print 3 ^ 2" " = 1"
97gdb_test "print (1 < 0) || true" " = true"
98gdb_test "print (1 > 0) && false" " = false"
99gdb_test "print 'z' == 'z'" " = true"
100gdb_test "print '\\u{1016f}' != 'q'" " = true"
101gdb_test "print 32 <= 32" " = true"
102gdb_test "print 32 >= 32" " = true"
103gdb_test "print 1 << 5" " = 32"
104gdb_test "print 32usize >> 5" " = 1"
105gdb_test "ptype 32i32 as f64" "type = f64"
106
347dc102
TT
107gdb_test "ptype 0xf9f9f9f90000" "type = i64"
108
67218854
TT
109gdb_test "print ()" " = \\(\\)"
110
111gdb_test "print \[1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
112gdb_test "ptype \[1,2,3,4\]" "type = \\\[i32; 4\\\]"
113gdb_test "print \[mut 1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
22f80c0f
TT
114gdb_test "print \[1,2 3" "',' or ']' expected"
115gdb_test "print \[1 2" "',', ';', or ']' expected"
67218854
TT
116
117gdb_test "print b\"hi rust\"" " = b\"hi rust\""
118# This isn't rusty syntax yet, but that's another bug -- this is just
119# testing that byte escapes work properly.
120gdb_test "print b\"\\xddhi bob\"" " = b\"\\\\335hi bob\""
121gdb_test "print b\"has\\0nul\"" " = b\"has\\\\000nul\""
122
123gdb_test "print br##\"hi\"##" " = b\"hi\""
124gdb_test "print br##\"hi" "Unexpected EOF in string"
125gdb_test "print br##\"hi\"" "Unexpected EOF in string"
126gdb_test "print br##\"hi\"#" "Unexpected EOF in string"
127
128# Test that convenience variables and functions work with the Rust
129# parser.
130gdb_test "print \$something" " = 27"
131gdb_test "print \$_isvoid(\$nosuchvariable)" " = 1"
132gdb_test "print \$_isvoid(\$something)" " = 0"
133
134gdb_test "print \[23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
135gdb_test "ptype \[23usize; 4\]" " = \\\[usize; 4\\\]"
136gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
137
1632f8ba 138# Test lexer corner cases.
73fc52c4
TT
139gdb_test "print 0x0 as *mut ()" " = \\\(\\*mut \\\(\\\)\\\) 0x0"
140gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\\\) 0x0"
3cbc7ac3
TT
141
142# The lexer doesn't treat this as a failure, but rather as two tokens,
143# and we error out while trying to look up 'r'. This is fine, though
144# -- what's important is that it isn't accepted.
145gdb_test "print r#" "No symbol 'r' in current context"
67218854
TT
146
147gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
This page took 0.693394 seconds and 4 git commands to generate.