summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorCraig A. Berry <craigberry@mac.com>2014-11-08 21:16:12 -0600
committerCraig A. Berry <craigberry@mac.com>2014-11-09 08:41:46 -0600
commita0dc9691937ad77060951167326f14e544e5cc97 (patch)
tree764c2a3ff61b23bad88cf72f517c234190e43a90 /dist
parent44480951b76939c88af4b5ca1569a41062065177 (diff)
downloadperl-a0dc9691937ad77060951167326f14e544e5cc97.tar.gz
Simplify abs2rel.t.
Factor out all the things that were common for the different test cases (which was everything except the filename). And use made-up names that indicate what's being tested rather than special system filenames commonly found on Unix systems. Otherwise, if, for example, a test for "'init.d' is a directory" fails, you'd be wondering whether something is wrong with your system rather than looking for problems in File::Spec, which is what we're testing.
Diffstat (limited to 'dist')
-rw-r--r--dist/PathTools/t/abs2rel.t69
1 files changed, 19 insertions, 50 deletions
diff --git a/dist/PathTools/t/abs2rel.t b/dist/PathTools/t/abs2rel.t
index 008498d823..5e33ab6cdf 100644
--- a/dist/PathTools/t/abs2rel.t
+++ b/dist/PathTools/t/abs2rel.t
@@ -9,71 +9,40 @@ use File::Temp qw(tempdir);
use File::Path qw(make_path);
my $startdir = cwd();
+my @files = ( 'anyfile', './anyfile', '../first_sub_dir/anyfile', '../second_sub_dir/second_file' );
-test_rel2abs( {
- startdir => $startdir,
- first_sub_dir => 'etc',
- sub_sub_dir => 'init.d',
- first_file => 'passwd',
- second_sub_dir => 'dev',
- second_file => 'null',
-} );
-
-test_rel2abs( {
- startdir => $startdir,
- first_sub_dir => 'etc',
- sub_sub_dir => 'init.d',
- first_file => './passwd',
- second_sub_dir => 'dev',
- second_file => 'null',
-} );
-
-test_rel2abs( {
- startdir => $startdir,
- first_sub_dir => 'etc',
- sub_sub_dir => 'init.d',
- first_file => '../etc/passwd',
- second_sub_dir => 'dev',
- second_file => 'null',
-} );
-
-test_rel2abs( {
- startdir => $startdir,
- first_sub_dir => 'etc',
- sub_sub_dir => 'init.d',
- first_file => '../dev/null',
- second_sub_dir => 'dev',
- second_file => 'null',
-} );
+for my $file (@files) {
+ test_rel2abs($file);
+}
sub test_rel2abs {
- my $args = shift;
+ my $first_file = shift;
my $tdir = tempdir( CLEANUP => 1 );
chdir $tdir or die "Unable to change to $tdir: $!";
my @subdirs = (
- $args->{first_sub_dir},
- File::Spec->catdir($args->{first_sub_dir}, $args->{sub_sub_dir}),
- $args->{second_sub_dir}
+ 'first_sub_dir',
+ File::Spec->catdir('first_sub_dir', 'sub_sub_dir'),
+ 'second_sub_dir'
);
make_path(@subdirs, { mode => 0711 })
or die "Unable to make_path: $!";
open my $OUT2, '>',
- File::Spec->catfile($args->{second_sub_dir}, $args->{second_file})
- or die "Unable to open $args->{second_file} for writing: $!";
+ File::Spec->catfile('second_sub_dir', 'second_file')
+ or die "Unable to open 'second_file' for writing: $!";
print $OUT2 "Attempting to resolve RT #121360\n";
- close $OUT2 or die "Unable to close $args->{second_file} after writing: $!";
+ close $OUT2 or die "Unable to close 'second_file' after writing: $!";
- chdir $args->{first_sub_dir}
- or die "Unable to change to '$args->{first_sub_dir}': $!";
- open my $OUT1, '>', $args->{first_file}
- or die "Unable to open $args->{first_file} for writing: $!";
+ chdir 'first_sub_dir'
+ or die "Unable to change to 'first_sub_dir': $!";
+ open my $OUT1, '>', $first_file
+ or die "Unable to open $first_file for writing: $!";
print $OUT1 "Attempting to resolve RT #121360\n";
- close $OUT1 or die "Unable to close $args->{first_file} after writing: $!";
+ close $OUT1 or die "Unable to close $first_file after writing: $!";
- my $rel_path = $args->{first_file};
- my $rel_base = $args->{sub_sub_dir};
+ my $rel_path = $first_file;
+ my $rel_base = File::Spec->catdir(File::Spec->curdir(), 'sub_sub_dir');
my $abs_path = File::Spec->rel2abs($rel_path);
my $abs_base = File::Spec->rel2abs($rel_base);
ok(-f $rel_path, "'$rel_path' is readable by effective uid/gid");
@@ -101,7 +70,7 @@ sub test_rel2abs {
is($rr_link, $aa_link,
"rel_path-rel_base '$rr_link' = abs_path-abs_base '$aa_link'");
- chdir $args->{startdir} or die "Unable to change back to $args->{startdir}: $!";
+ chdir $startdir or die "Unable to change back to $startdir: $!";
}
done_testing();