This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Removed cpan/Text-Soundex
[perl5.git] / cpan / File-CheckTree / t / CheckTree.t
CommitLineData
849d5e34 1#!./perl -w
1a3850a5 2
3d47529a 3use Test::More tests => 23;
849d5e34
JH
4
5use strict;
1a3850a5 6
69113548 7require overload;
cf2f24a4 8
1a3850a5 9use File::CheckTree;
849d5e34
JH
10use File::Spec; # used to get absolute paths
11
d6f31ecf
FR
12# We assume that we start from the dist/File-CheckTree in the perl repository,
13# or the dist root directory for the CPAN version.
849d5e34
JH
14
15
16#### TEST 1 -- No warnings ####
17# usings both relative and full paths, indented comments
18
19{
d6f31ecf
FR
20 my ($num_warnings, $path_to_libFileCheckTree);
21 $path_to_libFileCheckTree = File::Spec->rel2abs(
22 File::Spec->catfile('lib', 'File', 'CheckTree.pm'),
23 );
849d5e34
JH
24
25 my @warnings;
26 local $SIG{__WARN__} = sub { push @warnings, "@_" };
27
28 eval {
29 $num_warnings = validate qq{
30 lib -d
31# comment, followed "blank" line (w/ whitespace):
d6f31ecf 32
849d5e34
JH
33 # indented comment, followed blank line (w/o whitespace):
34
d6f31ecf
FR
35 lib/File/CheckTree.pm -f
36 '$path_to_libFileCheckTree' -e || warn
849d5e34
JH
37 };
38 };
39
3d47529a
NC
40 diag($_) for @warnings;
41 is( $@, '' );
42 is( scalar @warnings, 0 );
43 is( $num_warnings, 0 );
849d5e34
JH
44}
45
46
47#### TEST 2 -- One warning ####
48
49{
50 my ($num_warnings, @warnings);
51
52 local $SIG{__WARN__} = sub { push @warnings, "@_" };
53
54 eval {
55 $num_warnings = validate qq{
56 lib -f
d6f31ecf 57 lib/File/CheckTree.pm -f
849d5e34
JH
58 };
59 };
60
3d47529a
NC
61 is( $@, '' );
62 is( scalar @warnings, 1 );
63 like( $warnings[0], qr/lib is not a plain file/);
64 is( $num_warnings, 1 );
849d5e34
JH
65}
66
1a3850a5 67
849d5e34
JH
68#### TEST 3 -- Multiple warnings ####
69# including first warning only from a bundle of tests,
70# generic "|| warn", default "|| warn" and "|| warn '...' "
1a3850a5 71
849d5e34
JH
72{
73 my ($num_warnings, @warnings);
1a3850a5 74
849d5e34
JH
75 local $SIG{__WARN__} = sub { push @warnings, "@_" };
76
77 eval {
78 $num_warnings = validate q{
79 lib -effd
d6f31ecf
FR
80 lib/File/CheckTree.pm -f || die
81 lib/File/CheckTree.pm -d || warn
849d5e34
JH
82 lib -f || warn "my warning: $file\n"
83 };
84 };
85
3d47529a
NC
86 is( $@, '' );
87 is( scalar @warnings, 3 );
88 like( $warnings[0], qr/lib is not a plain file/);
d6f31ecf 89 like( $warnings[1], qr{lib/File/CheckTree.pm is not a directory});
3d47529a
NC
90 like( $warnings[2], qr/my warning: lib/);
91 is( $num_warnings, 3 );
849d5e34
JH
92}
93
94
95#### TEST 4 -- cd directive ####
96# cd directive followed by relative paths, followed by full paths
97{
d6f31ecf
FR
98 my ($num_warnings, @warnings, $path_to_lib, $path_to_dist);
99 $path_to_lib = File::Spec->rel2abs(File::Spec->catdir('lib'));
100 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
849d5e34
JH
101
102 local $SIG{__WARN__} = sub { push @warnings, "@_" };
103
104 eval {
105 $num_warnings = validate qq{
d6f31ecf
FR
106 lib -d || die
107 '$path_to_lib' cd
108 File -e
109 File -f
110 '$path_to_dist' cd
111 lib/File/CheckTree.pm -ef
112 lib/File/CheckTree.pm -d || warn
113 '$path_to_lib' -d || die
849d5e34
JH
114 };
115 };
116
3d47529a
NC
117 is( $@, '' );
118 is( scalar @warnings, 2 );
d6f31ecf
FR
119 like( $warnings[0], qr/File is not a plain file/);
120 like( $warnings[1], qr/CheckTree\.pm is not a directory/);
3d47529a 121 is( $num_warnings, 2 );
849d5e34
JH
122}
123
124
125#### TEST 5 -- Exception ####
126# test with generic "|| die"
127{
128 my $num_warnings;
129
130 eval {
131 $num_warnings = validate q{
d6f31ecf
FR
132 lib -ef || die
133 lib/File/CheckTree.pm -d
849d5e34
JH
134 };
135 };
136
3d47529a 137 like($@, qr/lib is not a plain file/);
849d5e34
JH
138}
139
140
141#### TEST 6 -- Exception ####
142# test with "|| die 'my error message'"
143{
144 my $num_warnings;
145
146 eval {
147 $num_warnings = validate q{
d6f31ecf
FR
148 lib -ef || die "yadda $file yadda...\n"
149 lib/File/CheckTree.pm -d
849d5e34
JH
150 };
151 };
152
3d47529a
NC
153 like($@, qr/yadda lib yadda/);
154 is( $num_warnings, undef );
849d5e34 155}
96dbb1e1
MM
156
157#### TEST 7 -- Quoted file names ####
158{
159 my $num_warnings;
160 eval {
161 $num_warnings = validate q{
162 "a file with whitespace" !-ef
163 'a file with whitespace' !-ef
164 };
165 };
166
3d47529a 167 is ( $@, '', 'No errors mean we compile correctly');
96dbb1e1
MM
168}
169
170#### TEST 8 -- Malformed query ####
171{
172 my $num_warnings;
173 eval {
174 $num_warnings = validate q{
175 a file with whitespace !-ef
176 };
177 };
178
d6f31ecf
FR
179 like( $@, qr/syntax error/,
180 'We got a syntax error for a malformed file query' );
96dbb1e1 181}