Skip to content

Commit

Permalink
Fix tests on msys without symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Aug 24, 2020
1 parent 7471a11 commit 69319c6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Revision history for Path-Tiny

{{$NEXT}}

[Tests]

- Fixes tests on MSYS without symlinks enabled.

0.114 2020-04-26 10:10:29-04:00 America/New_York

- No changes from 0.113-TRIAL.
Expand Down
5 changes: 2 additions & 3 deletions t/filesystem.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use warnings;
use Test::More 0.96;
use File::Temp qw(tmpnam tempdir);
use File::Spec;
use Config;
use Cwd;

use lib 't/lib';
use TestUtils qw/exception/;
use TestUtils qw/exception has_symlinks/;

use Path::Tiny;

Expand Down Expand Up @@ -344,8 +343,8 @@ SKIP: {
my $file = $newtmp->child("foo.txt");
my $link = $newtmp->child("bar.txt");
$file->spew("Hello World\n");
skip "symlink unavailable", 1 unless has_symlinks();
eval { symlink $file => $link };
skip "symlink unavailable", 1 unless $Config{d_symlink};
ok( $link->lstat->size, "lstat" );

is( $link->realpath, $file->realpath, "realpath resolves symlinks" );
Expand Down
11 changes: 11 additions & 0 deletions t/lib/TestUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package TestUtils;

use Carp;
use Cwd qw/getcwd/;
use Config;
use File::Temp 0.19 ();

use Exporter;
Expand All @@ -14,13 +15,23 @@ our @EXPORT = qw(
exception
pushd
tempd
has_symlinks
);

# If we have Test::FailWarnings, use it
BEGIN {
eval { require Test::FailWarnings; 1 } and do { Test::FailWarnings->import };
}

sub has_symlinks {
return $Config{d_symlink}
unless $^O eq 'msys';

# msys needs both `d_symlink` and a special environment variable
return unless $Config{d_symlink};
return $ENV{MSYS} =~ /winsymlinks:nativestrict/;
}

sub exception(&) {
my $code = shift;
my $success = eval { $code->(); 1 };
Expand Down
5 changes: 2 additions & 3 deletions t/recurse.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use strict;
use warnings;
use Test::More 0.92;
use File::Temp;
use Config;

use lib 't/lib';
use TestUtils qw/exception tempd/;
use TestUtils qw/exception tempd has_symlinks/;

use Path::Tiny;

Expand Down Expand Up @@ -69,7 +68,7 @@ subtest 'no symlinks' => sub {

subtest 'with symlinks' => sub {
plan skip_all => "No symlink support"
unless $Config{d_symlink};
unless has_symlinks();

my $wd = tempd;

Expand Down
5 changes: 2 additions & 3 deletions t/rel-abs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use Config;

use lib 't/lib';
use TestUtils qw/exception pushd tempd/;
use TestUtils qw/exception pushd tempd has_symlinks/;

use Path::Tiny;

Expand Down Expand Up @@ -111,7 +110,7 @@ subtest "relative on absolute paths with symlinks" => sub {
$deep->mkpath();

plan skip_all => "No symlink support"
unless $Config{d_symlink};
unless has_symlinks();

my ( $path, $base, $expect );

Expand Down
5 changes: 2 additions & 3 deletions t/symlinks.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use warnings;
use Test::More 0.96;

use lib 't/lib';
use TestUtils qw/exception/;
use TestUtils qw/exception has_symlinks/;

use Config;
use Path::Tiny;
use Cwd 'abs_path';

plan skip_all => "No symlink support" unless $Config{d_symlink};
plan skip_all => "No symlink support" unless has_symlinks();

subtest "relative symlinks with updir" => sub {
my $temp = Path::Tiny->tempdir;
Expand Down

0 comments on commit 69319c6

Please sign in to comment.