Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed 2/3] [gdb/testsuite] Add gdb.testsuite/foreach_with_prefix-2.exp
Date: Thu, 24 Sep 2026 16:06:03 +0200	[thread overview]
Message-ID: <20260924140605.1009056-2-tdevries@suse.de> (raw)
In-Reply-To: <20260924140605.1009056-1-tdevries@suse.de>

Add test-case gdb.testsuite/foreach_with_prefix-2.exp.

It tests the foreach_with_prefix construct, similar to how test-case
gdb.testsuite/transparent-uplevel.exp does.
---
 .../gdb.testsuite/foreach_with_prefix-2.exp   | 102 ++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 gdb/testsuite/gdb.testsuite/foreach_with_prefix-2.exp

diff --git a/gdb/testsuite/gdb.testsuite/foreach_with_prefix-2.exp b/gdb/testsuite/gdb.testsuite/foreach_with_prefix-2.exp
new file mode 100644
index 00000000000..861aa2e50f7
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/foreach_with_prefix-2.exp
@@ -0,0 +1,102 @@
+# 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/>.
+
+set stmts \
+    [list \
+	 {} \
+	 "error foo" \
+	 return \
+	 break \
+	 continue \
+	 "return -code ok" \
+	 "return -code error" \
+	 "return -code return" \
+	 "return -code break" \
+	 "return -code continue" \
+	 "return -code ok -level 0" \
+	 "return -code ok -level 1" \
+	 "return -code ok -level 2" \
+	 "return -code error -level 0" \
+	 "return -code error -level 1" \
+	 "return -code error -level 2" \
+	 "return -code return -level 0" \
+	 "return -code return -level 1" \
+	 "return -code return -level 2" \
+	 "return -code break -level 0" \
+	 "return -code break -level 1" \
+	 "return -code break -level 2" \
+	 "return -code continue -level 0" \
+	 "return -code continue -level 1" \
+	 "return -code continue -level 2"]
+
+foreach stmt $stmts {
+    verbose -log "STMT: $stmt"
+
+    set counter 0
+    set res1 [catch {
+	incr counter 1
+	foreach i {1 2 3} {
+	    incr counter 10
+	    if {$i == 2} {
+		{*}$stmt
+	    }
+	    incr counter 100
+	}
+	incr counter 1000
+    } script_res1 opts1]
+    set counter1 $counter
+
+    set counter 0
+    set res2 [catch {
+	incr counter 1
+	foreach_with_prefix i {1 2 3} {
+	    incr counter 10
+	    if {$i == 2} {
+		{*}$stmt
+	    }
+	    incr counter 100
+	}
+	incr counter 1000
+    } script_res2 opts2]
+    set counter2 $counter
+
+    verbose -log "COUNTER1: $counter1"
+    verbose -log "COUNTER2: $counter2"
+    gdb_assert {$counter1 == $counter2} "$stmt: counter"
+
+    verbose -log "RES1: $res1"
+    verbose -log "RES2: $res2"
+    gdb_assert {$res1 == $res2} "$stmt: res"
+
+    verbose -log "SCRIPT_RES1: '$script_res1'"
+    verbose -log "SCRIPT_RES2: '$script_res2'"
+    gdb_assert {$script_res1 == $script_res2} "$stmt: script_res"
+
+    # Note: we skip -errorinfo and -errorstack here.  These differ for
+    # something like "error foo", and they should.  When it comes to errors,
+    # we're not trying to hide the indirection.
+    foreach key {-code -level -errorcode} {
+	set v1 {}
+	set v2 {}
+	if {[dict exists $opts1 $key]} {
+	    set v1 [dict get $opts1 $key]
+	}
+	if {[dict exists $opts2 $key]} {
+	    set v2 [dict get $opts2 $key]
+	}
+	verbose -log "KEY: $key, V1: $v1"
+	verbose -log "KEY: $key, V2: $v2"
+	gdb_assert {$v1 == $v2} "$stmt: opts: $key"
+    }
+}
-- 
2.51.0


  reply	other threads:[~2026-09-24 14:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 14:06 [pushed 1/3] [gdb/testsuite] Use transparent_uplevel in foreach_with_prefix Tom de Vries
2026-09-24 14:06 ` Tom de Vries [this message]
2026-09-24 14:06 ` [pushed 3/3] [gdb/testsuite] Simplify foreach_mi_ui_mode Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260924140605.1009056-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox