From 68cf18b094d9ccb6d72948440568ead019de12bd Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Fri, 26 Aug 2022 12:00:10 -0500
Subject: [PATCH 13/23] ..and chdir

compare: 1053f85 91ae677 557eb01

sending the srcdir means that libpq_pipeline fails; it needs to set path to the
build dir (testdir).  Why doesn't it break the other tests that set PATH, though ??

pipeline is working now, but failing in basebackup test??
https://github.com/justinpryzby/postgres/runs/8044385257

XX-os-only: windows

ci-os-only: freebsd
---
 src/Makefile.global.in                 | 15 ++++++---------
 src/test/perl/PostgreSQL/Test/Utils.pm | 12 ++++++++++--
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index ac970215495..b65a4630228 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -452,24 +452,22 @@ define prove_installcheck
 echo "+++ tap install-check in $(subdir) +++" && \
 rm -rf '$(CURDIR)'/tmp_check && \
 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
-cd $(srcdir) && \
    PATH="$(bindir):$$PATH" \
    PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' \
-   PG_SUBDIR='$(CURDIR)' \
+   PG_SRCDIR='$(srcdir)' \
    PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
-   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
+   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),$(srcdir)/t/*.pl)
 endef
 else # PGXS case
 define prove_installcheck
 echo "+++ tap install-check in $(subdir) +++" && \
 rm -rf '$(CURDIR)'/tmp_check && \
 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
-cd $(srcdir) && \
    PATH="$(bindir):$$PATH" \
    PGPORT='6$(DEF_PGPORT)' top_builddir='$(top_builddir)' \
-   PG_SUBDIR='$(CURDIR)' \
+   PG_SRCDIR='$(srcdir)' \
    PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' \
-   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
+   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),$(srcdir)/t/*.pl)
 endef
 endif # PGXS
 
@@ -477,11 +475,10 @@ define prove_check
 echo "+++ tap check in $(subdir) +++" && \
 rm -rf '$(CURDIR)'/tmp_check && \
 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
-cd $(srcdir) && \
    $(with_temp_install) PGPORT='6$(DEF_PGPORT)' \
-   PG_SUBDIR='$(CURDIR)' \
+   PG_SRCDIR='$(srcdir)' \
    PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
-   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
+   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),$(srcdir)/t/*.pl)
 endef
 
 else
diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm
index 4a1629a8e16..0b52101e835 100644
--- a/src/test/perl/PostgreSQL/Test/Utils.pm
+++ b/src/test/perl/PostgreSQL/Test/Utils.pm
@@ -47,6 +47,7 @@ use warnings;
 use Carp;
 use Config;
 use Cwd;
+use Cwd qw(abs_path);
 use Exporter 'import';
 use Fcntl qw(:mode :seek);
 use File::Basename;
@@ -189,20 +190,27 @@ INIT
 	# test may still fail, but it's more likely to report useful facts.
 	$SIG{PIPE} = 'IGNORE';
 
-	my $test_dir = File::Spec->rel2abs($ENV{PG_SUBDIR} || dirname(dirname($0)));
+	my $test_dir = abs_path($ENV{PG_SRCDIR} || dirname(dirname($0)));
+	#my $test_dir = File::Spec->rel2abs($ENV{PG_SUBDIR} || dirname(dirname($0)));
 	my $test_name = basename($0);
 	$test_name =~ s/\.[^.]+$//;
 
 	$ENV{TESTDIR} = $test_dir;
 
+	my $cwd = getcwd();
+	chdir($test_dir);
+	#$ENV{BUILD_DIR} = $cwd;
 	if ($PostgreSQL::Test::Utils::windows_os &&
 		$Config{osname} eq 'MSWin32')
 	{
+		# $test_dir is what's needed for windows
+		#$ENV{PATH} =~ s!;!;$test_dir;$test_dir/test;$cwd;$cwd/test;!;
 		$ENV{PATH} =~ s!;!;$test_dir;$test_dir/test;!;
 	}
 	else
 	{
-		$ENV{PATH} =~ s!:!:$test_dir:$test_dir/test:!;
+		# $cwd is what's needed for a vpath build (and same as testdir for non-vpath build)
+		$ENV{PATH} =~ s!:!:$cwd:$cwd/test:!;
 	}
 
 	# Determine output directories, and create them.
-- 
2.17.1

