3 # AutoLoader.t runs before this test, so it seems safe to assume that it will
7 my $lib = '"-I../lib"'; # ok on unix, nt, The extra \" are for VMS
12 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
19 my $runperl = "$^X $lib";
23 use Test::More tests => 58;
27 require AutoSplit; # Run time. Check it compiles.
28 ok (1, "AutoSplit loaded");
32 print "# $incdir being removed...\n";
40 # local this else it buggers up the chomp() below.
41 # Hmm. Would be nice to have this as a regexp.
43 = "################################################################\n";
51 if (defined $contents) {
52 open FILE, ">$file" or die "Can't open $file: $!";
54 close FILE or die "Can't close $file: $!";
57 # Assumption: no characters in arguments need escaping from the shell or perl
58 my $com = qq($runperl -e "use AutoSplit; autosplit (qw(@_))");
60 # There may be a way to capture STDOUT without spawning a child process, but
61 # it's probably worthwhile spawning, as it ensures that nothing in AutoSplit
62 # can load functions from split modules into this perl.
64 warn "Exit status $? from running: >>$com<<" if $?;
69 my $dir = File::Spec->catfile($incdir, 'auto');
71 my $module = 'A' . $i . '_' . $$ . 'splittest';
72 my $file = File::Spec->catfile($incdir,"$module.pm");
76 # Build a hash for this test.
77 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
78 ((?:[^\#]+ # Any number of characters not #
79 | \#(?!\#) # or a # character not followed by #
80 | (?<!\n)\# # or a # character not preceded by \n
82 foreach ($args{Name}, $args{Require}) {
83 chomp $_ if defined $_;
85 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
88 $body ="package $module;\n" . $args{File};
89 $output = split_a_file ($body, $file, $dir, @extra_args);
92 $output = split_a_file (undef, $file, $dir, @extra_args);
96 is ($output, $args{Get}, "Output from autosplit()ing $args{Name}");
99 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
101 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
102 foreach (split /\n/, $args{Files}) {
104 unless (delete $got{$_}) {
108 my @missing = keys %missing;
110 unless (ok (!@missing, "Are any expected files missing?")) {
111 print "# These files are missing\n";
112 print "# $_\n" foreach sort @missing;
114 my @extra = keys %got;
116 unless (ok (!@extra, "Are any extra files present?")) {
117 print "# These files are unexpectedly present:\n";
118 print "# $_\n" foreach sort @extra;
121 if ($args{Require}) {
122 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
125 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
127 eval $body or die $@;
130 # match tests to check for prototypes
133 my $file = File::Spec->catfile($dir, $args{Require});
134 open IX, $file or die "Can't open '$file': $!";
136 close IX or die "Can't close '$file': $!";
137 foreach my $pat (split /\n/, $args{Match}) {
138 next if $pat =~ /^\#/;
139 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
142 # code tests contain eval{}ed ok()s etc
144 foreach my $code (split /\n/, $args{Tests}) {
145 next if $code =~ /^\#/;
146 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
149 unless ($args{SameAgain}) {
158 tests from the end of the AutoSplit module.
160 use AutoLoader 'AUTOLOAD';
161 {package Just::Another;
162 use AutoLoader 'AUTOLOAD';
164 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
167 sub test1 ($) { "test 1"; }
168 sub test2 ($$) { "test 2"; }
169 sub test3 ($$$) { "test 3"; }
170 sub testtesttesttest4_1 { "test 4"; }
171 sub testtesttesttest4_2 { "duplicate test 4"; }
172 sub Just::Another::test5 { "another test 5"; }
173 sub test6 { return join ":", __FILE__,__LINE__; }
174 package Yet::Another::AutoSplit;
175 sub testtesttesttest4_1 ($) { "another test 4"; }
176 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
177 package Yet::More::Attributes;
178 sub test_a1 ($) : locked :locked { 1; }
179 sub test_a2 : locked { 1; }
180 # And that was all it has. You were expected to manually inspect the output
182 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
183 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
184 *INC*/*MOD*.pm: some names are not unique when truncated to 8 characters:
185 directory *DIR*/*MOD*:
186 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
187 directory *DIR*/Yet/Another/AutoSplit:
188 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
190 *DIR*/*MOD*/autosplit.ix
194 *DIR*/*MOD*/testtesttesttest4_1.al
195 *DIR*/*MOD*/testtesttesttest4_2.al
196 *DIR*/Just/Another/test5.al
198 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
199 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
200 *DIR*/Yet/More/Attributes/test_a1.al
201 *DIR*/Yet/More/Attributes/test_a2.al
205 # Need to find these lines somewhere in the required file
207 sub test2\s*\(\$\$\);
208 sub test3\s*\(\$\$\$\);
209 sub testtesttesttest4_1\s*\(\$\);
210 sub testtesttesttest4_2\s*\(\$\$\);
211 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
212 sub test_a2\s*:\s*locked\s*;
214 is (*MOD*::test1 (1), 'test 1');
215 is (*MOD*::test2 (1,2), 'test 2');
216 is (*MOD*::test3 (1,2,3), 'test 3');
217 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
218 is (&*MOD*::testtesttesttest4_1, "test 4");
219 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
220 is (&Just::Another::test5, "another test 5");
221 # very messy way to interpolate function into regexp, but it's going to be
222 # needed to get : for Mac filespecs
223 like (&*MOD*::test6, qr!^*INC*/*MOD*.pm \(autosplit into @{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\):\d+$!);
224 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
225 ################################################################
227 missing use AutoLoader;
233 # There should be no files.
234 ################################################################
236 missing use AutoLoader; (but don't skip)
243 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
247 *DIR*/*MOD*/autosplit.ix
248 ################################################################
250 Split prior to checking whether obsolete files get deleted
252 use AutoLoader 'AUTOLOAD';
255 sub obsolete {my $a if 0; return $a++;}
256 sub gonner {warn "This gonner function should never get called"}
258 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
262 *DIR*/*MOD*/autosplit.ix
263 *DIR*/*MOD*/gonner.al
264 *DIR*/*MOD*/obsolete.al
266 is (&*MOD*::obsolete, 0);
267 is (&*MOD*::obsolete, 1);
268 {my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
269 printf "# time is %d (hopefully >=2 seconds later)\n", time;
271 True, so don't scrub this directory.
272 Need the sleep hack else the next test is so fast that the timestamp compare
273 routine in AutoSplit thinks that it shouldn't split the files.
274 IIRC DOS FAT filesystems have only 2 second granularity.
275 ################################################################
277 Check whether obsolete files get deleted
279 use AutoLoader 'AUTOLOAD';
282 sub skeleton {"bones"};
283 sub ghost {"scream"}; # This definition gets overwritten with the one below
285 sub zombie {"You didn't use fire."};
286 sub flying_pig {"Oink oink flap flap"};
288 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
292 *DIR*/*MOD*/autosplit.ix
293 *DIR*/*MOD*/skeleton.al
294 *DIR*/*MOD*/zombie.al
297 *DIR*/*MOD*/flying_pig.al
299 is (&*MOD*::skeleton, "bones", "skeleton");
300 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
301 {my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
302 printf "# time is %d (hopefully >=2 seconds later)\n", time;
304 True, so don't scrub this directory.
305 ################################################################
307 Check whether obsolete files remain when keep is 1
311 use AutoLoader 'AUTOLOAD';
317 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
321 *DIR*/*MOD*/autosplit.ix
322 *DIR*/*MOD*/skeleton.al
323 *DIR*/*MOD*/zombie.al
326 *DIR*/*MOD*/wraith.al
327 *DIR*/*MOD*/flying_pig.al
329 is (&*MOD*::ghost, "bump");
330 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
331 {my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
332 printf "# time is %d (hopefully >=2 seconds later)\n", time;
334 True, so don't scrub this directory.
335 ################################################################
337 Without the the timestamp check make sure that nothing happens
343 *DIR*/*MOD*/autosplit.ix
344 *DIR*/*MOD*/skeleton.al
345 *DIR*/*MOD*/zombie.al
348 *DIR*/*MOD*/wraith.al
349 *DIR*/*MOD*/flying_pig.al
351 is (&*MOD*::ghoul, "wail", "still haunted");
352 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
353 {my $time = time; print "# time is $time\n"; sleep (2); sleep (2) unless time > $time + 1}
354 printf "# time is %d (hopefully >=2 seconds later)\n", time;
356 True, so don't scrub this directory.
357 ################################################################
359 With the the timestamp check make sure that things happen (stuff gets deleted)
363 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
367 *DIR*/*MOD*/autosplit.ix
369 *DIR*/*MOD*/wraith.al
371 is (&*MOD*::wraith, 9);
372 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";