Add tests for Ada "in" operator

Message ID 20260529202223.4130030-1-tromey@adacore.com
State New
Headers
Series Add tests for Ada "in" operator |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey May 29, 2026, 8:22 p.m. UTC
  Coverage testing showed that there were no existing tests of the Ada
"in" operator.  This patch adds tests for this.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34041
---
 gdb/testsuite/gdb.ada/range.exp      | 70 ++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/range/prog.adb | 29 ++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 gdb/testsuite/gdb.ada/range.exp
 create mode 100644 gdb/testsuite/gdb.ada/range/prog.adb


base-commit: 742a479fc38a2b119d74a0bac270489911a1fd6c
  

Comments

Tom Tromey June 12, 2026, 3:21 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> Coverage testing showed that there were no existing tests of the Ada
Tom> "in" operator.  This patch adds tests for this.

Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34041

I'm checking this in.

Tom
  

Patch

diff --git a/gdb/testsuite/gdb.ada/range.exp b/gdb/testsuite/gdb.ada/range.exp
new file mode 100644
index 00000000000..370f2fdcc85
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/range.exp
@@ -0,0 +1,70 @@ 
+# Copyright 2026 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/>.
+
+# Simple tests of the 'abs' operator.
+
+load_lib "ada.exp"
+
+require allow_ada_tests
+
+standard_ada_testfile prog
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+    return
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "START" ${testdir}/prog.adb]
+if {![runto "prog.adb:$bp_location"]} {
+    return
+}
+
+set is_true [quotemeta {$@DECIMAL = true}]
+set is_false [quotemeta {$@DECIMAL = false}]
+
+proc check_true {var expr} {
+    gdb_test "print $var in $expr" $::is_true
+    gdb_test "print $var not in $expr" $::is_false
+}
+
+proc check_false {var expr} {
+    gdb_test "print $var in $expr" $::is_false
+    gdb_test "print $var not in $expr" $::is_true
+}
+
+check_true se smaller_enum
+check_true se classic_enum
+check_false ce smaller_enum
+check_true ce classic_enum
+
+check_true gamma smaller_enum
+check_true gamma classic_enum
+check_false alpha smaller_enum
+check_true alpha classic_enum
+
+check_true gamma "alpha .. epsilon"
+check_false gamma "alpha .. beta"
+check_false alpha "gamma .. epsilon"
+
+check_true beta "a'range"
+check_false alpha "a'range"
+check_false epsilon "a'range"
+check_true beta "a'range(1)"
+check_false alpha "a'range(1)"
+check_false epsilon "a'range(1)"
+check_true beta "a'range(2)"
+check_true alpha "a'range(2)"
+check_true epsilon "a'range(2)"
diff --git a/gdb/testsuite/gdb.ada/range/prog.adb b/gdb/testsuite/gdb.ada/range/prog.adb
new file mode 100644
index 00000000000..7b095a5bf36
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/range/prog.adb
@@ -0,0 +1,29 @@ 
+--  Copyright 2026 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/>.
+
+procedure Prog is
+   type Classic_Enum is (Alpha, Beta, Gamma, Epsilon);
+   subtype Smaller_Enum is Classic_Enum range Beta .. Gamma;
+
+   type A_T is array (Smaller_Enum, Classic_Enum) of Integer;
+
+   SE : Smaller_Enum := Gamma;
+   CE : Classic_Enum := Epsilon;
+
+   A : A_T := (others => (others => 0));
+
+begin
+   null;                        --  START
+end Prog;