From be5155a54032581aee973b66a681a22c03dd7ff8 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Fri, 31 Oct 2025 14:40:47 +0300
Subject: [PATCH v1] Ensure all TAP tests are registered in the Meson build
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Introduce a new script `src/tools/meson_tap_test_check` that verifies
all TAP tests under the source tree are properly registered in the
Meson build system. This helps prevent missing test registrations
caused by Meson’s lack of wildcard support at configure time.
---
 meson.build                    | 12 ++++++++
 src/tools/meson_tap_test_check | 51 ++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100755 src/tools/meson_tap_test_check

diff --git a/meson.build b/meson.build
index 0f61ff6a700..28277634331 100644
--- a/meson.build
+++ b/meson.build
@@ -3542,6 +3542,18 @@ test('install_test_files',
     is_parallel: false,
     suite: ['setup'])
 
+meson_tap_test_check = files('src/tools/meson_tap_test_check')
+test('meson_tap_test_check',
+    python,
+    args: [
+      meson_tap_test_check,
+      '--rootdir', meson.current_source_dir()
+    ],
+    # Since this test checks if all of the TAP tests are registered, run this
+    # test before setup tests.
+    priority: setup_tests_priority + 1,
+    suite: ['setup'])
+
 test_result_dir = meson.project_build_root() / 'testrun'
 
 
diff --git a/src/tools/meson_tap_test_check b/src/tools/meson_tap_test_check
new file mode 100755
index 00000000000..5a4cd5e4e52
--- /dev/null
+++ b/src/tools/meson_tap_test_check
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+
+# In meson build, wildcards can't be used at "configure" time; since wildcards
+# do not allow reliable detection of when re-configure is needed. This script
+# checks if meson build misses any TAP tests, if there is then test fails.
+
+import argparse
+import subprocess
+import os
+import sys
+import glob
+import json
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument('--rootdir', help='root directory of Postgres', type=str)
+args = parser.parse_args()
+root_dir = args.rootdir
+
+if not os.path.isdir(root_dir):
+    print(f"Error: directory '{root_dir}' not found", file=sys.stderr)
+    sys.exit(1)
+
+def get_test_files(root_dir):
+    test_files = []
+
+    test_files_temp = glob.glob(os.path.join(root_dir, "**", "t", "*.pl"), recursive=True)
+    for f in test_files_temp:
+        test_files.append(f)
+    return test_files
+
+def get_meson_tests():
+    res = subprocess.run(['meson', 'introspect', '.', '--tests'], stdout=subprocess.PIPE, text=True)
+    if res.returncode != 0:
+        sys.exit(res.returncode)
+
+    tap_tests = []
+    json_data = json.loads(res.stdout)
+    for elem in json_data:
+        if "cmd" in elem and elem["cmd"][-1].endswith(".pl"):
+            tap_tests.append(elem["cmd"][-1])
+
+    return tap_tests
+
+test_files = get_test_files(root_dir)
+meson_tests = get_meson_tests()
+test_diff = list(set(test_files) - set(meson_tests))
+
+if len(test_diff):
+    print(f"Following TAP tests are not registered in the meson build: {test_diff}")
+    sys.exit(1)
-- 
2.51.0

