]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add build-time check for unregistered unit test files
authorMichal Nowak <mnowak@isc.org>
Sun, 24 May 2026 18:12:53 +0000 (18:12 +0000)
committerMichal Nowak <mnowak@isc.org>
Tue, 9 Jun 2026 11:22:18 +0000 (13:22 +0200)
Fail at meson configure time if a *_test.c file exists in a test
directory but is not listed in the corresponding test array. This
prevents test files from being silently orphaned when added without
updating meson.build, as happened with diff_test.c and skr_test.c.

Assisted-by: Claude:claude-opus-4-7
.gitattributes
tests/dns/meson.build
tests/isc/meson.build
tests/isccfg/meson.build
tests/meson.build
tests/ns/meson.build
util/check_test_registration.py [new file with mode: 0644]

index e2a0641fbfa633a43b74a2a3193f41c98ca7930c..79c472aba8549393a463cd522bac166b9abdf313 100644 (file)
@@ -32,4 +32,5 @@ dangerfile.py                  export-ignore
 /util/dtrace.sh                        -export-ignore
 /util/meson.build              -export-ignore
 /util/meson-system-test-init.sh        -export-ignore
+/util/check_test_registration.py       -export-ignore
 /util/meson-dist-package.sh    -export-ignore
index 3808c559bc5dd6bb7ae3c0b89084efe92874da19..36294a0629c43bedbe40020190dcead9cb1b6628 100644 (file)
@@ -53,6 +53,14 @@ dns_tests = [
     'zt',
 ]
 
+_all_dns_tests = dns_tests + ['geoip', 'dnstap']
+run_command(
+    check_test_registration,
+    meson.current_source_dir(),
+    _all_dns_tests,
+    check: true,
+)
+
 if config.has('HAVE_GEOIP2')
     dns_tests += 'geoip'
 endif
index 81955d759db8e97939e07595767d547d9a3b2c88..779018194125ec9794e649e8177237e1b5f68f54 100644 (file)
@@ -62,6 +62,14 @@ flaky_isc_test = [
 
 is_el8 = run_command('grep', '-q', '-F', 'platform:el8', '/etc/os-release', check: false).returncode() == 0
 
+_all_isc_test = isc_test + ['doh']
+run_command(
+    check_test_registration,
+    meson.current_source_dir(),
+    _all_isc_test,
+    check: true,
+)
+
 if config.has('HAVE_LIBNGHTTP2') and not is_el8
     isc_test += 'doh'
 endif
index 0055f42f43b7e6870fe2de3f48b0c92fc72dd207..66adda5ccd1b8fb4e3f75b96c73d534ea98ddf08 100644 (file)
@@ -9,11 +9,20 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-foreach unit : [
+isccfg_tests = [
     'duration',
     'grammar',
     'parser',
 ]
+
+run_command(
+    check_test_registration,
+    meson.current_source_dir(),
+    isccfg_tests,
+    check: true,
+)
+
+foreach unit : isccfg_tests
     test_bin = executable(
         unit,
         files(f'@unit@_test.c'),
index e62cf01de311b4b8fadff4b2cb655d8f80f47253..7b7cb9f9c85329ba724be8ba0495e1aab82a83eb 100644 (file)
@@ -52,6 +52,8 @@ if not cmocka_dep.found()
     subdir_done()
 endif
 
+check_test_registration = [python, files('../util/check_test_registration.py')]
+
 subdir('bench')
 subdir('dns')
 subdir('isc')
index 75c5260223583e1db7b6f64906c72eb9b6e85555..452c7ea05f102e94828682a2c06d413a2754b67c 100644 (file)
@@ -9,11 +9,15 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-foreach unit : [
+ns_tests = [
     'notify',
     'plugin',
     'query',
 ]
+
+run_command(check_test_registration, meson.current_source_dir(), ns_tests, check: true)
+
+foreach unit : ns_tests
     test_bin = executable(
         unit,
         files(f'@unit@_test.c', 'netmgr_wrap.c'),
diff --git a/util/check_test_registration.py b/util/check_test_registration.py
new file mode 100644 (file)
index 0000000..1bde17e
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+
+import glob
+import os
+import sys
+
+test_dir = sys.argv[1]
+registered = sys.argv[2:]
+
+for path in sorted(glob.glob(os.path.join(test_dir, "*_test.c"))):
+    name = os.path.basename(path).removesuffix("_test.c")
+    if name not in registered:
+        print(
+            f"Unit test file {os.path.basename(path)} is not registered"
+            f" (add '{name}' to the list)",
+            file=sys.stderr,
+        )
+        sys.exit(1)