1#!/usr/bin/perl -T
2
3use Test::More tests => 12;
4use Paranoid;
5use Paranoid::Debug;
6use Paranoid::Filesystem qw(:all);
7use Paranoid::Glob;
8
9#PDEBUG = 20;
10
11psecureEnv();
12
13use strict;
14use warnings;
15
16no warnings qw(qw);
17
18my $rv;
19
20# Test pcleanPath
21$rv = pcleanPath('/usr/sbin/../ccs/share/../../local/bin');
22is( $rv, '/usr/local/bin', 'pcleanPath 1' );
23$rv = pcleanPath('t/../foo/bar');
24is( $rv, 'foo/bar', 'pcleanPath 2' );
25$rv = pcleanPath('../t/../foo/bar');
26is( $rv, '../foo/bar', 'pcleanPath 3' );
27$rv = pcleanPath('../t/../foo/bar/..');
28is( $rv, '../foo', 'pcleanPath 4' );
29$rv = pcleanPath('../t/../foo/bar/.');
30is( $rv, '../foo/bar', 'pcleanPath 5' );
31$rv = pcleanPath('/../.././../t/../foo/bar/.');
32is( $rv, '/foo/bar', 'pcleanPath 6' );
33ok( !eval '$rv = pcleanPath(undef)', 'pcleanPath 7' );
34
35# Test ptranslateLink
36mkdir './t/test_fs';
37mkdir './t/test_fs/subdir';
38symlink '../test_fs/link', './t/test_fs/link';
39symlink 'subdir',          './t/test_fs/ldir';
40
41$rv = ptranslateLink('./t/test_fs/ldir');
42is( $rv, './t/test_fs/subdir', 'ptranslateLink 1' );
43$rv = ptranslateLink('t/test_fs/ldir');
44is( $rv, 't/test_fs/subdir', 'ptranslateLink 2' );
45
46# TODO:  test with optional boolean
47
48# Test pwhich
49my $filename = pwhich('ls');
50isnt( $filename, undef, 'pwhich 1' );
51ok( $filename =~ m#/ls$#sm, 'pwhich 2' );
52$filename = pwhich('lslslslslslslslslslsl');
53is( $filename, undef, 'pwhich 3' );
54
55system('rm -rf ./t/test_fs*');
56
57