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: [PATCH] [gdb/testsuite] Improve gdb.src/pre-commit.exp
Date: Fri, 17 Jul 2026 14:27:56 +0200	[thread overview]
Message-ID: <20260717122756.51352-1-tdevries@suse.de> (raw)

Test-case gdb.src/pre-commit.exp runs all the pre-commit stage hooks, but
produces a single pass:
...
PASS: gdb.src/pre-commit.exp: pre-commit checks
...

Use a dummy run to find all the hooks, and then run them one by one, producing
instead the more informative:
...
PASS: gdb.src/pre-commit.exp: pre-commit: black: run
PASS: gdb.src/pre-commit.exp: pre-commit: flake8: run
PASS: gdb.src/pre-commit.exp: pre-commit: isort: run
PASS: gdb.src/pre-commit.exp: pre-commit: codespell: run
PASS: gdb.src/pre-commit.exp: pre-commit: tclint: run
PASS: gdb.src/pre-commit.exp: pre-commit: check-include-guards: run
PASS: gdb.src/pre-commit.exp: pre-commit: check-whitespace: run
PASS: gdb.src/pre-commit.exp: pre-commit: check-file-mode: run
...

This allows us to get rid of the current SKIP kludge for the pre-commit-setup
hook.

Also skip the gnu-check-style hook, since it only checks patches, not files.

While we're at it, also bail out with unsupported if the pre-commit version is
too old, fixing PR testsuite/33945.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33945
---
 gdb/testsuite/gdb.src/pre-commit.exp | 39 +++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/gdb.src/pre-commit.exp b/gdb/testsuite/gdb.src/pre-commit.exp
index 82225f3d652..debf86df19a 100644
--- a/gdb/testsuite/gdb.src/pre-commit.exp
+++ b/gdb/testsuite/gdb.src/pre-commit.exp
@@ -31,13 +31,40 @@ with_cwd $repodir {
 	return
     }
 
-    # Skip the pre-commit-setup check.  It checks the repository setup, not
-    # the sources.
-    setenv SKIP pre-commit-setup
+    set result [remote_exec build "pre-commit run --files foo/bar.c"]
+    set output [lindex $result 1]
 
-    set result [remote_exec build "pre-commit run --all-files -v"]
-    set status [lindex $result 0]
-    gdb_assert {$status == 0} "pre-commit checks"
+    set re \
+	{pre-commit version [0-9.]* is required but version [0-9.]* is installed}
+    if {[regexp $re $output]} {
+	unsupported "pre-commit too old"
+	return
+    }
+
+    with_test_prefix pre-commit {
+	set re {^[a-zA-Z0-9][a-zA-Z0-9_-]+}
+	set hook_list [regexp -lineanchor -all -inline $re $output]
+	gdb_assert {[llength $hook_list] != 0} "get hooks"
+
+	foreach hook $hook_list {
+	    if {$hook == "pre-commit-setup"} {
+		# Skip the pre-commit-setup check.  It checks the repository
+		# setup, not the sources.
+		continue
+	    }
+	    if {$hook == "check-gnu-style"} {
+		# Skip the check-gnu-style check.  It checks patches, not the
+		# sources.
+		continue
+	    }
+
+	    with_test_prefix $hook {
+		set result [remote_exec build "pre-commit run $hook --all-files -v"]
+		set status [lindex $result 0]
+		gdb_assert {$status == 0} "run"
+	    }
+	}
+    }
 
     with_test_prefix commit-msg {
 	set commit_msg [build_standard_output_file "commit-msg.txt"]

base-commit: 0cdde1399d2d453569fe91c55b34b4879f8a6501
-- 
2.51.0


             reply	other threads:[~2026-07-17 12:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 12:27 Tom de Vries [this message]
2026-07-21 17:43 ` Tom Tromey

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=20260717122756.51352-1-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