From: Benjamin Sugars Date: Tue, 27 Mar 2001 17:37:05 +0000 (-0500) Subject: cwd.t (was: Cwd has no tests?) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed4a5f9986e389ab30cb5ae84d8409ef8d4dcaec;p=p5sagit%2Fp5-mst-13.2.git cwd.t (was: Cwd has no tests?) Message-ID: p4raw-id: //depot/perl@9406 --- diff --git a/MANIFEST b/MANIFEST index 3ce8daa..61346fb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1433,6 +1433,7 @@ t/lib/checktree.t See if File::CheckTree works t/lib/class-struct.t See if Class::Struct works t/lib/complex.t See if Math::Complex works t/lib/compmod.pl Helper for 1_compile.t +t/lib/cwd.t See if Cwd works t/lib/db-btree.t See if DB_File works t/lib/db-hash.t See if DB_File works t/lib/db-recno.t See if DB_File works diff --git a/t/lib/cwd.t b/t/lib/cwd.t new file mode 100644 index 0000000..adc57f6 --- /dev/null +++ b/t/lib/cwd.t @@ -0,0 +1,88 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Config; +use Cwd; +use strict; +use warnings; + +print "1..14\n"; + +# check imports +print +(defined(&cwd) && + defined(&getcwd) && + defined(&fastcwd) && + defined(&fastgetcwd) ? + "" : "not "), "ok 1\n"; +print +(!defined(&chdir) && + !defined(&abs_path) && + !defined(&fast_abs_path) ? + "" : "not "), "ok 2\n"; + +# XXX these tests rely on a working pwd program or shell command +chomp(my $start = `pwd 2>/dev/null`); +if ($?) { + print "ok 3 # skipped\n"; + print "ok 4 # skipped\n"; + print "ok 5 # skipped\n"; + print "ok 6 # skipped\n"; +} else { + my $cwd = cwd; + my $getcwd = getcwd; + my $fastcwd = fastcwd; + my $fastgetcwd = fastgetcwd; + print +($cwd eq $start ? "" : "not "), "ok 3\n"; + print +($getcwd eq $start ? "" : "not "), "ok 4\n"; + print +($fastcwd eq $start ? "" : "not "), "ok 5\n"; + print +($fastgetcwd eq $start ? "" : "not "), "ok 6\n"; +} + +mkdir "pteerslt", 0777; +mkdir "pteerslt/path", 0777; +mkdir "pteerslt/path/to", 0777; +mkdir "pteerslt/path/to/a", 0777; +mkdir "pteerslt/path/to/a/dir", 0777; +Cwd::chdir "pteerslt/path/to/a/dir"; +my $cwd = cwd; +my $getcwd = getcwd; +my $fastcwd = fastcwd; +my $fastgetcwd = fastgetcwd; +my $want = "t/pteerslt/path/to/a/dir"; +print +($cwd =~ m|$want$| ? "" : "not "), "ok 7\n"; +print +($getcwd =~ m|$want$| ? "" : "not "), "ok 8\n"; +print +($fastcwd =~ m|$want$| ? "" : "not "), "ok 9\n"; +print +($fastgetcwd =~ m|$want$| ? "" : "not "), "ok 10\n"; + +# Cwd::chdir should also update $ENV{PWD} +print +($ENV{PWD} =~ m|$want$| ? "" : "not "), "ok 11\n"; +Cwd::chdir ".."; rmdir "dir"; +Cwd::chdir ".."; rmdir "a"; +Cwd::chdir ".."; rmdir "to"; +Cwd::chdir ".."; rmdir "path"; +Cwd::chdir ".."; rmdir "pteerslt"; +print +($ENV{PWD} =~ m|\bt$| ? "" : "not "), "ok 12\n"; + +if ($Config{d_symlink}) { + my @dirs = split " " => $Config{libpth}; + my $target = pop @dirs; + symlink $target => "linktest"; + mkdir "pteerslt"; + chdir "pteerslt"; + my $rel = "../../t/linktest"; + + my $abs_path = Cwd::abs_path($rel); + my $fast_abs_path = Cwd::fast_abs_path($rel); + print +($abs_path eq $target ? "" : "not "), "ok 13\n"; + print +($fast_abs_path eq $target ? "" : "not "), "ok 14\n"; + + chdir ".."; + rmdir "pteerslt"; + unlink "linktest"; +} else { + print "ok 13 # skipped\n"; + print "ok 14 # skipped\n"; +}