[binutils-gdb] [gdb/testsuite] Improve gdb.src/pre-commit.exp

Tom de Vries via Gdb-cvs <[email protected]> Tue, 21 Jul 2026 20:52:45 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D06efd870fd48=
185b703762dc775b04c089b114ff

commit 06efd870fd48185b703762dc775b04c089b114ff
Author: Tom de Vries <[email protected]>
Date:   Tue Jul 21 22:52:42 2026 +0200

    [gdb/testsuite] Improve gdb.src/pre-commit.exp
   =20
    Test-case gdb.src/pre-commit.exp runs all the pre-commit stage hooks, b=
ut
    produces a single pass:
    ...
    PASS: gdb.src/pre-commit.exp: pre-commit checks
    ...
   =20
    Use a dummy run to find all the hooks, and then run them one by one, pr=
oducing
    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
    ...
   =20
    This allows us to get rid of the current SKIP kludge for the pre-commit=
-setup
    hook.
   =20
    Also skip the gnu-check-style hook, since it only checks patches, not f=
iles.
   =20
    While we're at it, also bail out with unsupported if the pre-commit ver=
sion is
    too old, fixing PR testsuite/33945.
   =20
    Approved-By: Tom Tromey <[email protected]>
   =20
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D33945

Diff:
---
 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/p=
re-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
     }
=20
-    # 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]
=20
-    set result [remote_exec build "pre-commit run --all-files -v"]
-    set status [lindex $result 0]
-    gdb_assert {$status =3D=3D 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] !=3D 0} "get hooks"
+
+	foreach hook $hook_list {
+	    if {$hook =3D=3D "pre-commit-setup"} {
+		# Skip the pre-commit-setup check.  It checks the repository
+		# setup, not the sources.
+		continue
+	    }
+	    if {$hook =3D=3D "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 =3D=3D 0} "run"
+	    }
+	}
+    }
=20
     with_test_prefix commit-msg {
 	set commit_msg [build_standard_output_file "commit-msg.txt"]