v3-0002-meson-Add-infrastructure-for-TAP-tests-written-in.patch

text/x-patch

Filename: v3-0002-meson-Add-infrastructure-for-TAP-tests-written-in.patch
Type: text/x-patch
Part: 1
Message: Re: Understanding, testing and improving our Windows filesystem code

Patch

Format: format-patch
Series: patch v3-0002
Subject: meson: Add infrastructure for TAP tests written in C.
File+
meson.build 37 6
src/interfaces/libpq/test/meson.build 2 6
src/tools/testwrap 9 2
From b5e633442ccc155cca1d093e435670bce3f0ceb1 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Tue, 11 Oct 2022 10:49:15 -0700
Subject: [PATCH v3 2/4] meson: Add infrastructure for TAP tests written in C.

Allow t/XXX.c files to be used as t/XXX.pl files normally are.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com
---
 meson.build                           | 43 +++++++++++++++++++++++----
 src/interfaces/libpq/test/meson.build |  8 ++---
 src/tools/testwrap                    | 11 +++++--
 3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build
index bfacbdc0af..bb73ad24a6 100644
--- a/meson.build
+++ b/meson.build
@@ -2561,6 +2561,10 @@ default_bin_args = default_target_args + {
   'install_rpath': ':'.join(bin_install_rpaths),
 }
 
+test_bin_args = default_target_args + {
+  'install': false,
+}
+
 
 
 # Helper for exporting a limited number of symbols
@@ -2920,7 +2924,14 @@ foreach test_dir : tests
     endif
 
     t = test_dir[kind]
+    env = test_env
 
+    # Add environment vars from the test specification
+    foreach name, value : t.get('env', {})
+      env.set(name, value)
+    endforeach
+
+    # pg_regress style tests
     if kind in ['regress', 'isolation', 'ecpg']
       if kind == 'regress'
         runner = pg_regress
@@ -2954,7 +2965,6 @@ foreach test_dir : tests
         test_command += t.get('sql', [])
       endif
 
-      env = test_env
       env.prepend('PATH', temp_install_bindir, test_dir['bd'])
 
       test_kwargs = {
@@ -2975,6 +2985,8 @@ foreach test_dir : tests
       )
 
       testport += 1
+
+    # perl tap tests
     elif kind == 'tap'
       if not tap_tests_enabled
         continue
@@ -2988,13 +3000,8 @@ foreach test_dir : tests
 
       # Add temporary install, the build directory for non-installed binaries and
       # also test/ for non-installed test binaries built separately.
-      env = test_env
       env.prepend('PATH', temp_install_bindir, test_dir['bd'], test_dir['bd'] / 'test')
 
-      foreach name, value : t.get('env', {})
-        env.set(name, value)
-      endforeach
-
       test_kwargs = {
         'protocol': 'tap',
         'suite': [test_dir['name']],
@@ -3023,6 +3030,30 @@ foreach test_dir : tests
           ],
         )
       endforeach
+
+    # tap tests using C executables
+    elif kind == 'exec_tap'
+      # Don't have a dependency on perl tap test infrastructure, so we can
+      # test even when not tap_test_enabled.
+      test_kwargs = {
+        'protocol': 'tap',
+        'suite': [test_dir['name']],
+        'timeout': 1000,
+        'env': env,
+      } + t.get('test_kwargs', {})
+
+      foreach onetap : t['tests']
+        test_name = onetap.name()
+        test(test_dir['name'] / test_name,
+          python,
+          kwargs: test_kwargs,
+          depends: test_deps + t.get('deps', []) + [onetap],
+          args: testwrap_base + [
+            '--testname', test_name,
+            '--', onetap.full_path(),
+          ],
+        )
+      endforeach
     else
       error('unknown kind @0@ of test in @1@'.format(kind, test_dir['sd']))
     endif
diff --git a/src/interfaces/libpq/test/meson.build b/src/interfaces/libpq/test/meson.build
index 017f729d43..06e026e400 100644
--- a/src/interfaces/libpq/test/meson.build
+++ b/src/interfaces/libpq/test/meson.build
@@ -11,9 +11,7 @@ endif
 executable('libpq_uri_regress',
   libpq_uri_regress_sources,
   dependencies: [frontend_code, libpq],
-  kwargs: default_bin_args + {
-    'install': false,
-  }
+  kwargs: test_bin_args,
 )
 
 
@@ -30,7 +28,5 @@ endif
 executable('libpq_testclient',
   libpq_testclient_sources,
   dependencies: [frontend_code, libpq],
-  kwargs: default_bin_args + {
-    'install': false,
-  }
+  kwargs: default_bin_args,
 )
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 7a64fe76a2..5ca49b1fac 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -32,9 +32,16 @@ os.chdir(args.srcdir)
 # mark test as having started
 open(os.path.join(testdir, 'test.start'), 'x')
 
+testdatadir = os.path.join(testdir, 'data')
+testlogdir = os.path.join(testdir, 'log')
+
+# pre-create dirs so that the test's infrastructure doesn't have to
+os.makedirs(testdatadir)
+os.makedirs(testlogdir)
+
 env_dict = {**os.environ,
-            'TESTDATADIR': os.path.join(testdir, 'data'),
-            'TESTLOGDIR': os.path.join(testdir, 'log')}
+            'TESTDATADIR': testdatadir,
+            'TESTLOGDIR': testlogdir}
 
 sp = subprocess.run(args.test_command, env=env_dict)
 
-- 
2.35.1