Commit d66b23b0 authored by Andrew Dunstan's avatar Andrew Dunstan

Enable almost all TAP tests involving symlinks on Windows

Windows has junction points which function as symbolic links for
directories. This patch introduces a new function TestLib::dir_symlink()
which creates a junction point on Windows and a standard Unix type
symbolic link elsewhere.

The function TestLib::perl2host is also modified, first to use cygpath
where it's available (e.g. msys2) and second to allow it to succeed if
the gandparent directory exists but the parent does not.

Given these changes the only symlink tests that need to be skipped on
Windows are those related to permissions or to use of readlink. The
relevant tests for pg_basebackup and pg_rewind are therefore adjusted
accordingly.

Andrew Dunstan, reviewed by Peter Eisentraut and Michael Paquier.

Discussion: https://postgr.es/m/c50a646c-d9bb-7c62-a4bf-8256ff6ff338@2ndquadrant.com
parent 932f9fb5
...@@ -5,7 +5,7 @@ use PostgresNode; ...@@ -5,7 +5,7 @@ use PostgresNode;
use TestLib; use TestLib;
use Test::More; use Test::More;
if ($^O eq 'msys' && `uname -or` =~ /^[2-9].*Msys/) if ($TestLib::is_msys2)
{ {
plan skip_all => 'High bit name tests fail on Msys2'; plan skip_all => 'High bit name tests fail on Msys2';
} }
...@@ -27,7 +27,7 @@ $ENV{PGCLIENTENCODING} = 'LATIN1'; ...@@ -27,7 +27,7 @@ $ENV{PGCLIENTENCODING} = 'LATIN1';
# The odds of finding something interesting by testing all ASCII letters # The odds of finding something interesting by testing all ASCII letters
# seem too small to justify the cycles of testing a fifth name. # seem too small to justify the cycles of testing a fifth name.
my $dbname1 = my $dbname1 =
'regression' 'regression'
. generate_ascii_string(1, 9) . generate_ascii_string(1, 9)
. generate_ascii_string(11, 12) . generate_ascii_string(11, 12)
. generate_ascii_string(14, 33) . generate_ascii_string(14, 33)
......
...@@ -6,16 +6,7 @@ use warnings; ...@@ -6,16 +6,7 @@ use warnings;
use File::Copy; use File::Copy;
use File::Path qw(rmtree); use File::Path qw(rmtree);
use TestLib; use TestLib;
use Test::More; use Test::More tests => 5;
if ($windows_os)
{
plan skip_all => 'symlinks not supported on Windows';
exit;
}
else
{
plan tests => 5;
}
use FindBin; use FindBin;
use lib $FindBin::RealBin; use lib $FindBin::RealBin;
...@@ -36,7 +27,7 @@ sub run_test ...@@ -36,7 +27,7 @@ sub run_test
# turn pg_wal into a symlink # turn pg_wal into a symlink
print("moving $test_primary_datadir/pg_wal to $primary_xlogdir\n"); print("moving $test_primary_datadir/pg_wal to $primary_xlogdir\n");
move("$test_primary_datadir/pg_wal", $primary_xlogdir) or die; move("$test_primary_datadir/pg_wal", $primary_xlogdir) or die;
symlink($primary_xlogdir, "$test_primary_datadir/pg_wal") or die; dir_symlink($primary_xlogdir, "$test_primary_datadir/pg_wal") or die;
RewindTest::start_primary(); RewindTest::start_primary();
......
...@@ -67,6 +67,7 @@ our @EXPORT = qw( ...@@ -67,6 +67,7 @@ our @EXPORT = qw(
check_mode_recursive check_mode_recursive
chmod_recursive chmod_recursive
check_pg_config check_pg_config
dir_symlink
system_or_bail system_or_bail
system_log system_log
run_log run_log
...@@ -84,10 +85,12 @@ our @EXPORT = qw( ...@@ -84,10 +85,12 @@ our @EXPORT = qw(
command_checks_all command_checks_all
$windows_os $windows_os
$is_msys2
$use_unix_sockets $use_unix_sockets
); );
our ($windows_os, $use_unix_sockets, $tmp_check, $log_path, $test_logfile); our ($windows_os, $is_msys2, $use_unix_sockets, $tmp_check, $log_path,
$test_logfile);
BEGIN BEGIN
{ {
...@@ -114,6 +117,9 @@ BEGIN ...@@ -114,6 +117,9 @@ BEGIN
# Must be set early # Must be set early
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'; $windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
# Check if this environment is MSYS2.
$is_msys2 = $^O eq 'msys' && `uname -or` =~ /^[2-9].*Msys/;
if ($windows_os) if ($windows_os)
{ {
require Win32API::File; require Win32API::File;
...@@ -137,6 +143,10 @@ BEGIN ...@@ -137,6 +143,10 @@ BEGIN
Set to true when running under Windows, except on Cygwin. Set to true when running under Windows, except on Cygwin.
=item C<$is_msys2>
Set to true when running under MSYS2.
=back =back
=cut =cut
...@@ -152,7 +162,7 @@ INIT ...@@ -152,7 +162,7 @@ INIT
# TESTDIR environment variable, which is normally set by the invoking # TESTDIR environment variable, which is normally set by the invoking
# Makefile. # Makefile.
$tmp_check = $ENV{TESTDIR} ? "$ENV{TESTDIR}/tmp_check" : "tmp_check"; $tmp_check = $ENV{TESTDIR} ? "$ENV{TESTDIR}/tmp_check" : "tmp_check";
$log_path = "$tmp_check/log"; $log_path = "$tmp_check/log";
mkdir $tmp_check; mkdir $tmp_check;
mkdir $log_path; mkdir $log_path;
...@@ -263,9 +273,10 @@ sub tempdir_short ...@@ -263,9 +273,10 @@ sub tempdir_short
=item perl2host() =item perl2host()
Translate a Perl file name to a host file name. Currently, this is a no-op Translate a virtual file name to a host file name. Currently, this is a no-op
except for the case of Perl=msys and host=mingw32. The subject need not except for the case of Perl=msys and host=mingw32. The subject need not
exist, but its parent directory must exist. exist, but its parent or grandparent directory must exist unless cygpath is
available.
=cut =cut
...@@ -273,6 +284,17 @@ sub perl2host ...@@ -273,6 +284,17 @@ sub perl2host
{ {
my ($subject) = @_; my ($subject) = @_;
return $subject unless $Config{osname} eq 'msys'; return $subject unless $Config{osname} eq 'msys';
if ($is_msys2)
{
# get absolute, windows type path
my $path = qx{cygpath -a -w "$subject"};
if (!$?)
{
chomp $path;
return $path if $path;
}
# fall through if this didn't work.
}
my $here = cwd; my $here = cwd;
my $leaf; my $leaf;
if (chdir $subject) if (chdir $subject)
...@@ -283,7 +305,12 @@ sub perl2host ...@@ -283,7 +305,12 @@ sub perl2host
{ {
$leaf = '/' . basename $subject; $leaf = '/' . basename $subject;
my $parent = dirname $subject; my $parent = dirname $subject;
chdir $parent or die "could not chdir \"$parent\": $!"; if (!chdir $parent)
{
$leaf = '/' . basename($parent) . $leaf;
$parent = dirname $parent;
chdir $parent or die "could not chdir \"$parent\": $!";
}
} }
# this odd way of calling 'pwd -W' is the only way that seems to work. # this odd way of calling 'pwd -W' is the only way that seems to work.
...@@ -602,6 +629,40 @@ sub check_pg_config ...@@ -602,6 +629,40 @@ sub check_pg_config
=pod =pod
=item dir_symlink(oldname, newname)
Portably create a symlink for a directory. On Windows this creates a junction
point. Elsewhere it just calls perl's builtin symlink.
=cut
sub dir_symlink
{
my $oldname = shift;
my $newname = shift;
if ($windows_os)
{
$oldname = perl2host($oldname);
$newname = perl2host($newname);
$oldname =~ s,/,\\,g;
$newname =~ s,/,\\,g;
my $cmd = qq{mklink /j "$newname" "$oldname"};
if ($Config{osname} eq 'msys')
{
# need some indirection on msys
$cmd = qq{echo '$cmd' | \$COMSPEC /Q};
}
system($cmd);
}
else
{
symlink $oldname, $newname;
}
die "No $newname" unless -e $newname;
}
=pod
=back =back
=head1 Test::More-LIKE METHODS =head1 Test::More-LIKE METHODS
...@@ -664,7 +725,7 @@ sub command_exit_is ...@@ -664,7 +725,7 @@ sub command_exit_is
# long as the process was not terminated by an exception. To work around # long as the process was not terminated by an exception. To work around
# that, use $h->full_results on Windows instead. # that, use $h->full_results on Windows instead.
my $result = my $result =
($Config{osname} eq "MSWin32") ($Config{osname} eq "MSWin32")
? ($h->full_results)[0] ? ($h->full_results)[0]
: $h->result(0); : $h->result(0);
is($result, $expected, $test_name); is($result, $expected, $test_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment