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

Tom de Vries <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.