[v2,1/3] Introduce rust_at_least helper proc
Commit Message
This adds a 'rust_at_least' helper proc, for checking the version of
the Rust compiler in use. It then changes various tests to use this
with 'require'.
---
gdb/testsuite/gdb.rust/rawids.exp | 8 +-------
gdb/testsuite/gdb.rust/unicode.exp | 8 +-------
gdb/testsuite/gdb.rust/unsized.exp | 5 +----
gdb/testsuite/lib/rust-support.exp | 25 +++++++++++++++++++++++++
4 files changed, 28 insertions(+), 18 deletions(-)
@@ -16,13 +16,7 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 30} {
- untested "raw identifiers require rust 1.30 or greater"
- return -1
-}
+require allow_rust_tests {rust_at_least 1.30}
standard_testfile .rs
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
@@ -16,14 +16,8 @@
# Test raw identifiers.
load_lib rust-support.exp
-require allow_rust_tests
-
# Non-ASCII identifiers were allowed starting in 1.53.
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 53} {
- untested "this test requires rust 1.53 or greater"
- return -1
-}
+require allow_rust_tests {rust_at_least 1.53}
# Enable basic use of UTF-8. LC_ALL gets reset for each testfile.
setenv LC_ALL C.UTF-8
@@ -31,10 +31,7 @@ if {![runto ${srcfile}:$line]} {
gdb_test "ptype us" " = .*V<\\\[u8\\\]>.*"
-set v [split [rust_compiler_version] .]
-# The necessary debuginfo generation landed in 1.60, but had a bug
-# that was fixed in 1.61.
-if {[lindex $v 0] > 1 || [lindex $v 1] >= 61} {
+if {[rust_at_least 1.61]} {
gdb_test "print us2" " = .*Box<.*> \\\[1, 2, 3\\\]"
gdb_test "ptype us2" "type = .*"
}
@@ -112,3 +112,28 @@ gdb_caching_proc rust_compiler_version {} {
}
return 0.0
}
+
+# A helper that checks that the rust compiler is at least the given
+# version. This is handy for use with 'require'.
+proc rust_at_least {atleast} {
+ foreach n1 [split [rust_compiler_version] .] n2 [split $atleast .] {
+ if {$n1 == ""} {
+ # Have 1.2, wanted 1.2.1.
+ return 0
+ }
+ if {$n2 == ""} {
+ # Have 1.2.1, wanted 1.2.
+ return 1
+ }
+ if {$n1 > $n2} {
+ # Have 1.3, wanted 1.2.
+ return 1
+ }
+ if {$n1 < $n2} {
+ # Have 1.1, wanted 1.2.
+ return 0
+ }
+ }
+ # Completely equal.
+ return 1
+}