aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.rust/expr.exp
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-04-26 19:38:43 -0600
committerTom Tromey <tom@tromey.com>2016-05-17 12:02:01 -0600
commit67218854b1987d89593ccaf5feaf5b29b1b976f2 (patch)
tree8137e1713d27a507dfc57015308f44166543ffc6 /gdb/testsuite/gdb.rust/expr.exp
parentc44af4ebc000f606d16b42224cba2cfe80391d5c (diff)
downloadbinutils-67218854b1987d89593ccaf5feaf5b29b1b976f2.zip
binutils-67218854b1987d89593ccaf5feaf5b29b1b976f2.tar.gz
binutils-67218854b1987d89593ccaf5feaf5b29b1b976f2.tar.bz2
Update gdb test suite for Rust
This updates the gdb test suite for Rust. 2016-05-17 Tom Tromey <tom@tromey.com> Manish Goregaokar <manishsmail@gmail.com> * lib/rust-support.exp: New file. * lib/gdb.exp (skip_rust_tests): New proc. (build_executable_from_specs): Handle rust. * lib/future.exp (gdb_find_rustc): New proc. (gdb_default_target_compile): Handle rust. * gdb.rust/expr.exp: New file. * gdb.rust/generics.exp: New file. * gdb.rust/generics.rs: New file. * gdb.rust/methods.exp: New file. * gdb.rust/methods.rs: New file. * gdb.rust/modules.exp: New file. * gdb.rust/modules.rs: New file. * gdb.rust/simple.exp: New file. * gdb.rust/simple.rs: New file.
Diffstat (limited to 'gdb/testsuite/gdb.rust/expr.exp')
-rw-r--r--gdb/testsuite/gdb.rust/expr.exp137
1 files changed, 137 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
new file mode 100644
index 0000000..99a697e
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -0,0 +1,137 @@
+# Copyright (C) 2016 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test basic expression parsing and evaluation, without requiring a
+# Rust compiler. This serves as a smoke test.
+
+load_lib "rust-support.exp"
+if {[skip_rust_tests]} { continue }
+
+gdb_start
+
+gdb_test_no_output "set var \$something = 27"
+
+if {![set_lang_rust]} {
+ warning "Rust expression tests suppressed."
+ continue
+}
+
+gdb_test "print 9__97" " = 997"
+gdb_test "print -5" " = -5"
+gdb_test "print +5" " = 5"
+gdb_test "print +-+-5" " = 5"
+gdb_test "print 3_2i32" " = 32"
+gdb_test "print 32i64" " = 32"
+gdb_test "print 8u8" " = 8"
+gdb_test "print 0x1f" " = 31"
+gdb_test "print 0o07" " = 7"
+gdb_test "print 0o70" " = 56"
+gdb_test "print 0b1_111" " = 15"
+gdb_test "print 32usize" " = 32"
+gdb_test "print 0x_4" " = 4"
+
+gdb_test "print 'z'" " = 122 'z'"
+gdb_test "print '\\t'" " = 9 '\\\\t'"
+gdb_test "print '\\n'" " = 10 '\\\\n'"
+gdb_test "print '\\r'" " = 13 '\\\\r'"
+gdb_test "print '\\\\'" " = 92 '\\\\\\\\'"
+gdb_test "print '\\0'" " = 0 '\\\\0'"
+gdb_test "print '\\''" " = 39 '\\\\''"
+gdb_test "print '\\\"'" " = 34 '\"'"
+gdb_test "print '\\xff'" " = 255 '\\\\xff'"
+gdb_test "print '\\xFF'" " = 255 '\\\\xff'"
+gdb_test "print '\\u\{F0eF\}'" " = 61679 '\\\\u\\{00f0ef\\}'"
+
+gdb_test "print b'z'" " = 122"
+gdb_test "print b'\\xfe'" " = 254"
+gdb_test "print b'\\t'" " = 9"
+gdb_test "print b'\\n'" " = 10"
+gdb_test "print b'\\r'" " = 13"
+gdb_test "print b'\\\\'" " = 92"
+gdb_test "print b'\\0'" " = 0"
+gdb_test "print b'\\''" " = 39"
+gdb_test "print b'\\\"'" " = 34"
+gdb_test "print b'\\xff'" " = 255"
+
+gdb_test "print 23.5" " = 23.5"
+gdb_test "print 23.5e1" " = 235"
+gdb_test "print 2e4" " = 20000"
+gdb_test "print 2_E+4_f64" " = 20000"
+gdb_test "print 5e-1" " = 0.5"
+gdb_test "print 5e-1f32" " = 0.5"
+
+gdb_test "print false" " = false"
+gdb_test "print true" " = true"
+
+gdb_test "print 1+2" " = 3"
+gdb_test "print 1i32 + 2i32" " = 3"
+gdb_test "print 2.0 - 1.0" " = 1"
+gdb_test "print !false" " = true"
+gdb_test "print !true" " = false"
+gdb_test "print !0u8" " = 255"
+gdb_test "print 7 * 7" " = 49"
+gdb_test "print 7usize * 7usize" " = 49"
+gdb_test "print 42 / 7" " = 6"
+gdb_test "print 42 % 7" " = 0"
+gdb_test "print 1.0 / 2.0" " = 0.5"
+gdb_test "print 1 < 2" " = true"
+gdb_test "print !(1 < 2)" " = false"
+gdb_test "print 3 + 4 * 7" " = 31"
+gdb_test "print 1 > 2" " = false"
+gdb_test "print 1 | 2" " = 3"
+gdb_test "print 1 & 2" " = 0"
+gdb_test "print 3 & 2" " = 2"
+gdb_test "print 3 ^ 2" " = 1"
+gdb_test "print (1 < 0) || true" " = true"
+gdb_test "print (1 > 0) && false" " = false"
+gdb_test "print 'z' == 'z'" " = true"
+gdb_test "print '\\u{1016f}' != 'q'" " = true"
+gdb_test "print 32 <= 32" " = true"
+gdb_test "print 32 >= 32" " = true"
+gdb_test "print 1 << 5" " = 32"
+gdb_test "print 32usize >> 5" " = 1"
+gdb_test "ptype 32i32 as f64" "type = f64"
+
+gdb_test "print ()" " = \\(\\)"
+
+gdb_test "print \[1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
+gdb_test "ptype \[1,2,3,4\]" "type = \\\[i32; 4\\\]"
+gdb_test "print \[mut 1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
+
+gdb_test "print b\"hi rust\"" " = b\"hi rust\""
+# This isn't rusty syntax yet, but that's another bug -- this is just
+# testing that byte escapes work properly.
+gdb_test "print b\"\\xddhi bob\"" " = b\"\\\\335hi bob\""
+gdb_test "print b\"has\\0nul\"" " = b\"has\\\\000nul\""
+
+gdb_test "print br##\"hi\"##" " = b\"hi\""
+gdb_test "print br##\"hi" "Unexpected EOF in string"
+gdb_test "print br##\"hi\"" "Unexpected EOF in string"
+gdb_test "print br##\"hi\"#" "Unexpected EOF in string"
+
+# Test that convenience variables and functions work with the Rust
+# parser.
+gdb_test "print \$something" " = 27"
+gdb_test "print \$_isvoid(\$nosuchvariable)" " = 1"
+gdb_test "print \$_isvoid(\$something)" " = 0"
+
+gdb_test "print \[23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
+gdb_test "ptype \[23usize; 4\]" " = \\\[usize; 4\\\]"
+gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
+
+# Test a lexer corner case.
+gdb_test "print r#" "syntax error in expression, near `#'\\."
+
+gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"