Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make IO::Path's test environment controlled
  • Loading branch information
lizmat committed Oct 3, 2014
1 parent 1f3a867 commit d13c1a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 56 deletions.
34 changes: 12 additions & 22 deletions S32-io/io-path-cygwin.t
Expand Up @@ -2,7 +2,11 @@ use v6;
use Test;
# L<S32::IO/IO::Path>

plan 52;
plan 50;

# Make sure we have a controlled environment
my $*SPEC = IO::Spec::Cygwin;
my $*CWD = '/zip/loc/';

my $relpath = IO::Path::Cygwin.new('foo/bar' );
my $abspath = IO::Path::Cygwin.new('/foo/bar');
Expand All @@ -18,12 +22,8 @@ is $path.volume, "C:", 'volume "C:foo\\\\bar\\" -> "C:"';
is $path.directory, "foo", 'directory "C:foo\\\\bar\\" -> "foo"';
is $path.basename, "bar", 'basename "C:foo\\\\bar\\" -> "bar"';
isa_ok $path.path, Str, ".path returns Str of path";
{
my $*SPEC = IO::Spec::Cygwin; # perl does an .IO
say $path.path;
say $path.perl;
is $path.perl.EVAL, $path, ".perl loopback";
}

is $path.perl.EVAL, $path, ".perl loopback";

my $uncpath = IO::Path::Cygwin.new("\\\\server\\share\\");
is $uncpath.volume, "//server/share", 'volume "//server/share/" -> ""/server/share"';
Expand Down Expand Up @@ -58,13 +58,11 @@ ok IO::Path::Cygwin.new("A:b").is-relative, '"A:b" is relative';
is $relpath.absolute, IO::Spec::Cygwin.canonpath("$*CWD/foo/bar"), "absolute path from \$*CWD";
is $relpath.absolute("/usr"), "/usr/foo/bar", "absolute path specified";
is IO::Path::Cygwin.new("/usr/bin").relative("/usr"), "bin", "relative path specified";
{
my $*SPEC = IO::Spec::Cygwin; # .IO needs Cygwin by default
is $relpath.absolute.IO.relative, "foo/bar", "relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("\\foo"), "foo/bar", "absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.IO.absolute.IO.resolve, "\\foo\\bar", "absolute inverts relative with resolve";
}

is $relpath.absolute.IO.relative, "foo/bar", "relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("\\foo"), "foo/bar", "absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.IO.absolute.IO.resolve, "\\foo\\bar", "absolute inverts relative with resolve";

is IO::Path::Cygwin.new("foo/bar").parent, "foo", "parent of 'foo/bar' is 'foo'";
is IO::Path::Cygwin.new("foo").parent, ".", "parent of 'foo' is '.'";
Expand All @@ -83,11 +81,3 @@ is $numfile.succ.succ, "foo/file03.txt", "succ x 2";
is $numfile.pred, "foo/file00.txt", "pred basic";
is IO::Path::Unix.new("foo/()").succ, "foo/()", "succ only effects basename";
is IO::Path::Unix.new("foo/()").succ, "foo/()", "pred only effects basename";

if IO::Spec.FSTYPE eq 'Win32' {
ok IO::Path::Cygwin.new(~$*CWD).e, "cwd exists, filetest inheritance ok";
ok IO::Path::Cygwin.new(~$*CWD).d, "cwd is a directory";
}
else {
skip "On-system tests for filetest inheritance", 2;
}
29 changes: 11 additions & 18 deletions S32-io/io-path-unix.t
Expand Up @@ -2,7 +2,11 @@ use v6;
use Test;
# L<S32::IO/IO::Path>

plan 37;
plan 35;

# make sure we have a controlled environment here
my $*SPEC = IO::Spec::Unix;
my $*CWD = '/zip/loc'.IO;

my $relpath = IO::Path::Unix.new('foo/bar' );
my $abspath = IO::Path::Unix.new('/foo/bar');
Expand Down Expand Up @@ -38,15 +42,12 @@ is $relpath.absolute("/usr"), "/usr/foo/bar",
is IO::Path::Unix.new("/usr/bin").relative("/usr"), "bin",
"relative path specified";

{
my $*SPEC = IO::Spec::Unix; # make sure we have Unix $*SPEC in here
is $relpath.absolute.IO.relative, "foo/bar",
"relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("/foo"),
"foo/bar","absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.IO.absolute.IO.resolve, "/foo/bar", "absolute inverts relative with resolve";
}
is $relpath.absolute.IO.relative, "foo/bar",
"relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("/foo"),
"foo/bar","absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.IO.absolute.IO.resolve, "/foo/bar", "absolute inverts relative with resolve";

is IO::Path::Unix.new("foo/bar").parent, "foo", "parent of 'foo/bar' is 'foo'";
is IO::Path::Unix.new("foo").parent, ".", "parent of 'foo' is '.'";
Expand All @@ -64,11 +65,3 @@ is $numfile.succ.succ, "foo/file03.txt", "succ x 2";
is $numfile.pred, "foo/file00.txt", "pred basic";
is IO::Path::Unix.new("foo/()").succ, "foo/()", "succ only effects basename";
is IO::Path::Unix.new("foo/()").succ, "foo/()", "pred only effects basename";

if IO::Spec.FSTYPE eq 'Unix' {
ok IO::Path::Unix.new(~$*CWD).e, "cwd exists, filetest inheritance ok";
ok IO::Path::Unix.new(~$*CWD).d, "cwd is a directory";
}
else {
skip "On-system tests for filetest inheritance", 2;
}
25 changes: 9 additions & 16 deletions S32-io/io-path-win.t
Expand Up @@ -2,7 +2,10 @@ use v6;
use Test;
# L<S32::IO/IO::Path>

plan 51;
plan 49;

my $*SPEC = IO::Spec::Win32; # .IO needs to have IO::Spec::Win32
my $*CWD = 'C:\\zip\\loc'.IO;

my $relpath = IO::Path::Win32.new('foo\\bar' );
my $abspath = IO::Path::Win32.new('\\foo\\bar');
Expand Down Expand Up @@ -55,13 +58,11 @@ ok IO::Path::Win32.new("A:b").is-relative, '"A:b" is relative';
is $relpath.absolute, IO::Spec::Win32.canonpath("$*CWD\\foo\\bar"), "absolute path from \$*CWD";
is $relpath.absolute("\\usr"), "\\usr\\foo\\bar", "absolute path specified";
is IO::Path::Win32.new("\\usr\\bin").relative("/usr"), "bin", "relative path specified";
{
my $*SPEC = IO::Spec::Win32; # .IO needs to have IO::Spec::Win32
is $relpath.absolute.IO.relative, "foo\\bar", "relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("\\foo"), "foo\\bar","absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.IO.absolute.IO.resolve, "\\foo\\bar", "absolute inverts relative with resolve";
}

is $relpath.absolute.IO.relative, "foo\\bar", "relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("\\foo"), "foo\\bar","absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.IO.absolute.IO.resolve, "\\foo\\bar", "absolute inverts relative with resolve";

is IO::Path::Win32.new("foo/bar").parent, "foo", "parent of 'foo/bar' is 'foo'";
is IO::Path::Win32.new("foo").parent, ".", "parent of 'foo' is '.'";
Expand All @@ -79,11 +80,3 @@ is $numfile.succ.succ, "foo\\file03.txt", "succ x 2";
is $numfile.pred, "foo\\file00.txt", "pred basic";
is IO::Path::Win32.new("foo\\()").succ, "foo\\()", "succ only effects basename";
is IO::Path::Win32.new("foo\\()").succ, "foo\\()", "pred only effects basename";

if IO::Spec.FSTYPE eq 'Win32' {
ok IO::Path::Win32.new(~$*CWD).e, "cwd exists, filetest inheritance ok";
ok IO::Path::Win32.new(~$*CWD).d, "cwd is a directory";
}
else {
skip "On-system tests for filetest inheritance", 2;
}

0 comments on commit d13c1a2

Please sign in to comment.