Hi,

On Tue, 28 Oct 2025 at 07:19, Michael Paquier <[email protected]> wrote:
>
> Another less invasive solution for the code tree would be to have
> meson cross-check that the list of files it defines matches with
> what's on disk.  With the drop of Makefiles and ./configure at some
> point in mind, I am not convinced that the t/*.pl rule needs to
> change, but meson could be made more reliable by making sure that
> what's listed matches with  what we have in the source tree.  That
> would prevent a lot of mistakes.

I tried to implement this but it didn't quite work, please see details below.

I introduced a new test, meson_tap_test_check, in the meson build
system. This test runs first in the test suite and compares two file
sets:

1-  Files on disk matching the t/*.pl wildcard.
2- The output of "meson introspect ${pg_root_dir} --tests" filtered
with the same t/*.pl wildcard.

The test subtracts the second list from the first and fails if there
is any difference.

However, this approach didn’t work because some tests are not
registered if their dependencies (or such) aren’t found. For example,
'001_sepgsql.pl' test isn't registered if the 'selinux' dependency is
missing and that causes a difference between #1 and #2. Given that, I
think it would be better if we register all tests and skip those whose
dependencies aren’t found, rather than not registering them when the
dependency isn’t found.

The attached patch shows what I implemented.

--
Regards,
Nazir Bilal Yavuz
Microsoft
From be5155a54032581aee973b66a681a22c03dd7ff8 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <[email protected]>
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

Reply via email to