From 213b049f4f62d22e9b87fbaa572f9e35cf518d63 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Thu, 10 Aug 2023 18:40:35 +0300
Subject: [PATCH v2 2/3] Make PG_TEST_USE_UNIX_SOCKETS work for tap tests on
 windows.

This commit is backpatched version of
45f52709d86ceaaf282a440f6311c51fc526340b for PG 14.
---
 src/bin/pg_ctl/t/001_start_stop.pl |  1 +
 src/test/perl/PostgresNode.pm      | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl
index d656a7fe183..110926e40e3 100644
--- a/src/bin/pg_ctl/t/001_start_stop.pl
+++ b/src/bin/pg_ctl/t/001_start_stop.pl
@@ -35,6 +35,7 @@ print $conf TestLib::slurp_file($ENV{TEMP_CONFIG})
 if ($use_unix_sockets)
 {
 	print $conf "listen_addresses = ''\n";
+	$tempdir_short =~ s!\\!/!g if $TestLib::windows_os;
 	print $conf "unix_socket_directories = '$tempdir_short'\n";
 }
 else
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index aae02b18d69..ca2902e6430 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -126,7 +126,18 @@ INIT
 	$use_tcp            = !$TestLib::use_unix_sockets;
 	$test_localhost     = "127.0.0.1";
 	$last_host_assigned = 1;
-	$test_pghost        = $use_tcp ? $test_localhost : TestLib::tempdir_short;
+	if ($use_tcp)
+	{
+		$test_pghost = $test_localhost;
+	}
+	else
+	{
+		# On windows, replace windows-style \ path separators with / when
+		# putting socket directories either in postgresql.conf or libpq
+		# connection strings, otherwise they are interpreted as escapes.
+		$test_pghost = TestLib::tempdir_short;
+		$test_pghost =~ s!\\!/!g if $TestLib::windows_os;
+	}
 	$ENV{PGHOST}        = $test_pghost;
 	$ENV{PGDATABASE}    = 'postgres';
 
-- 
2.40.1

