8 use Test::More 'no_plan';
10 BEGIN { use_ok 'File::Basename' }
13 can_ok( __PACKAGE__, qw( basename fileparse dirname fileparse_set_fstype ) );
17 ok length fileparse_set_fstype('unix'), 'set fstype to unix';
19 my($base,$path,$type) = fileparse('/virgil/aeneid/draft.book7',
22 is($path, '/virgil/aeneid/');
25 is(basename('/arma/virumque.cano'), 'virumque.cano');
26 is(dirname ('/arma/virumque.cano'), '/arma');
27 is(dirname('arma/'), '.');
28 is(dirname('/'), '/');
34 is(fileparse_set_fstype('VMS'), 'unix', 'set fstype to VMS');
36 my($base,$path,$type) = fileparse('virgil:[aeneid]draft.book7',
39 is($path, 'virgil:[aeneid]');
42 is(basename('arma:[virumque]cano.trojae'), 'cano.trojae');
43 is(dirname('arma:[virumque]cano.trojae'), 'arma:[virumque]');
44 is(dirname('arma:<virumque>cano.trojae'), 'arma:<virumque>');
45 is(dirname('arma:virumque.cano'), 'arma:');
48 local $ENV{DEFAULT} = '' unless exists $ENV{DEFAULT};
49 is(dirname('virumque.cano'), $ENV{DEFAULT});
50 is(dirname('arma/'), '.');
57 is(fileparse_set_fstype('MSDOS'), 'VMS', 'set fstype to MSDOS');
59 my($base,$path,$type) = fileparse('C:\\virgil\\aeneid\\draft.book7',
62 is($path, 'C:\\virgil\\aeneid\\');
65 is(basename('A:virumque\\cano.trojae'), 'cano.trojae');
66 is(dirname('A:\\virumque\\cano.trojae'), 'A:\\virumque');
67 is(dirname('A:\\'), 'A:\\');
68 is(dirname('arma\\'), '.');
70 # Yes "/" is a legal path separator under MSDOS
71 is(basename("lib/File/Basename.pm"), "Basename.pm");
77 is(fileparse_set_fstype('MacOS'), 'MSDOS', 'set fstype to MacOS');
79 my($base,$path,$type) = fileparse('virgil:aeneid:draft.book7',
82 is($path, 'virgil:aeneid:');
85 is(basename(':arma:virumque:cano.trojae'), 'cano.trojae');
86 is(dirname(':arma:virumque:cano.trojae'), ':arma:virumque:');
87 is(dirname(':arma:virumque:'), ':arma:');
88 is(dirname(':arma:virumque'), ':arma:');
89 is(dirname(':arma:'), ':');
90 is(dirname(':arma'), ':');
91 is(dirname('arma:'), 'arma:');
92 is(dirname('arma'), ':');
93 is(dirname(':'), ':');
96 # Check quoting of metacharacters in suffix arg by basename()
97 is(basename(':arma:virumque:cano.trojae','.trojae'), 'cano');
98 is(basename(':arma:virumque:cano_trojae','.trojae'), 'cano_trojae');
102 ### extra tests for a few specific bugs
104 fileparse_set_fstype 'MSDOS';
105 # perl5.003_18 gives C:/perl/.\
106 is((fileparse 'C:/perl/lib')[1], 'C:/perl/');
107 # perl5.003_18 gives C:\perl\
108 is(dirname('C:\\perl\\lib\\'), 'C:\\perl');
110 fileparse_set_fstype 'UNIX';
111 # perl5.003_18 gives '.'
112 is(dirname('/perl/'), '/');
113 # perl5.003_18 gives '/perl/lib'
114 is(dirname('/perl/lib//'), '/perl');
120 # The empty tainted value, for tainting strings
121 my $TAINT = substr($^X, 0, 0);
123 # How to identify taint when you see it
124 sub any_tainted (@) {
125 return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
132 sub all_tainted (@) {
133 for (@_) { return 0 unless tainted $_ }
137 ok tainted(dirname($TAINT.'/perl/lib//'));
138 ok all_tainted(fileparse($TAINT.'/dir/draft.book7','\.book\d+'));