From 8326585575b7571e227392269afae272fdb3eb28 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Wed, 11 Sep 2024 15:46:33 +0300
Subject: [PATCH v5 2/2] Add PG_TEST_EXTRA configure option to the make builds

The Meson builds have PG_TEST_EXTRA as a configure-time option, which was
not available in the make builds. To ensure both build systems are in
sync, PG_TEST_EXTRA is now added as a configure-time option. It can be
set like this:
./configure PG_TEST_EXTRA="kerberos, ssl, ..."

Note that to preserve the old behavior, this configure-time option is
overridden by the PG_TEST_EXTRA environment variable.
---
 src/test/Makefile      |  5 -----
 configure              |  4 ++++
 configure.ac           |  2 ++
 src/Makefile.global.in | 10 ++++++++++
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/test/Makefile b/src/test/Makefile
index dbd3192874d..fc42f1db2b9 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -27,11 +27,6 @@ ifeq ($(with_ssl),openssl)
 SUBDIRS += ssl
 endif
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA to check it in individual tap tests.
-export PG_TEST_EXTRA
-
 # We don't build or execute these by default, but we do want "make
 # clean" etc to recurse into them.  (We must filter out those that we
 # have conditionally included into SUBDIRS above, else there will be
diff --git a/configure b/configure
index 53c8a1f2bad..31e547816f3 100755
--- a/configure
+++ b/configure
@@ -764,6 +764,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -880,6 +881,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1587,6 +1589,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
diff --git a/configure.ac b/configure.ac
index 6a35b2880bf..cd63ed803af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,8 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA,
+           [Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 42f50b49761..4859343153b 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -642,6 +642,16 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+# Store any configure-time setting for PG_TEST_EXTRA, but let environment
+# variables override it to maintain the historical behavior of the tests.
+# (Standard `=` assignment would require devs to use a commandline option.)
+# This is skipped in PGXS mode to keep the setting from escaping into other
+# projects' builds.
+ifndef PGXS
+PG_TEST_EXTRA ?= @PG_TEST_EXTRA@
+export PG_TEST_EXTRA
+endif
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
-- 
2.45.2

