3 # AutoLoader.t runs before this test, so it seems safe to assume that it will
10 print "1..0 # This test is not 8.3-aware.\n";
18 $lib = '"-I../lib"'; # ok on unix, nt, The extra \" are for VMS
23 my $runperl = "$^X $lib";
27 use Test::More tests => 58;
31 require AutoSplit; # Run time. Check it compiles.
32 ok (1, "AutoSplit loaded");
36 print "# $incdir being removed...\n";
44 # local this else it buggers up the chomp() below.
45 # Hmm. Would be nice to have this as a regexp.
47 = "################################################################\n";
52 my $pathsep = $^O eq 'MSWin32' ? '\\' : $^O eq 'MacOS' ? ':' : '/';
53 my $endpathsep = $^O eq 'MacOS' ? ':' : '';
58 if (defined $contents) {
59 open FILE, ">$file" or die "Can't open $file: $!";
61 close FILE or die "Can't close $file: $!";
64 # Assumption: no characters in arguments need escaping from the shell or perl
65 my $com = qq($runperl -e "use AutoSplit; autosplit (qw(@_))");
66 print "# command: $com\n";
67 # There may be a way to capture STDOUT without spawning a child process, but
68 # it's probably worthwhile spawning, as it ensures that nothing in AutoSplit
69 # can load functions from split modules into this perl.
71 warn "Exit status $? from running: >>$com<<" if $?;
76 my $dir = File::Spec->catdir($incdir, 'auto');
78 $dir = VMS::Filespec::unixify($dir);
80 } elsif ($^O eq 'MacOS') {
85 my $module = 'A' . $i . '_' . $$ . 'splittest';
86 my $file = File::Spec->catfile($incdir,"$module.pm");
90 s/\*PATHSEP\*/$pathsep/gm;
91 s/\*ENDPATHSEP\*/$endpathsep/gm;
93 # Build a hash for this test.
94 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
95 ((?:[^\#]+ # Any number of characters not #
96 | \#(?!\#) # or a # character not followed by #
97 | (?<!\n)\# # or a # character not preceded by \n
99 foreach ($args{Name}, $args{Require}, $args{Extra}) {
100 chomp $_ if defined $_;
102 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
105 $body ="package $module;\n" . $args{File};
106 $output = split_a_file ($body, $file, $dir, @extra_args);
109 $output = split_a_file (undef, $file, $dir, @extra_args);
113 my ($filespec, $replacement);
114 while ($output =~ m/(\[.+\])/) {
116 $replacement = VMS::Filespec::unixify($filespec);
117 $replacement =~ s/\/$//;
118 $output =~ s/\Q$filespec\E/$replacement/;
123 cmp_ok ($output, 'eq', $args{Get}, "Output from autosplit()ing $args{Name}");
126 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
128 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
129 foreach (split /\n/, $args{Files}) {
131 $_ = lc($_) if $^O eq 'VMS';
132 unless (delete $got{$_}) {
136 my @missing = keys %missing;
138 unless (ok (!@missing, "Are any expected files missing?")) {
139 print "# These files are missing\n";
140 print "# $_\n" foreach sort @missing;
142 my @extra = keys %got;
144 unless (ok (!@extra, "Are any extra files present?")) {
145 print "# These files are unexpectedly present:\n";
146 print "# $_\n" foreach sort @extra;
149 if ($args{Require}) {
150 $args{Require} =~ s|/|:|gm if $^O eq 'MacOS';
151 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
152 $com =~ s{\\}{/}gm if ($^O eq 'MSWin32');
155 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
157 eval $body or die $@;
160 # match tests to check for prototypes
163 my $file = File::Spec->catfile($dir, $args{Require});
164 open IX, $file or die "Can't open '$file': $!";
166 close IX or die "Can't close '$file': $!";
167 foreach my $pat (split /\n/, $args{Match}) {
168 next if $pat =~ /^\#/;
169 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
172 # code tests contain eval{}ed ok()s etc
174 foreach my $code (split /\n/, $args{Tests}) {
175 next if $code =~ /^\#/;
176 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
179 if (my $sleepfor = $args{Sleep}) {
180 # We need to sleep for a while
181 # Need the sleep hack else the next test is so fast that the timestamp
182 # compare routine in AutoSplit thinks that it shouldn't split the files.
184 my $until = $time + $sleepfor;
188 } while (time < $until && --$attempts > 0);
189 if ($attempts == 0) {
190 printf << "EOM", time;
191 # Attempted to sleep for $sleepfor second(s), started at $time, now %d.
192 # sleep attempt ppears to have failed; some tests may fail as a result.
196 unless ($args{SameAgain}) {
205 tests from the end of the AutoSplit module.
207 use AutoLoader 'AUTOLOAD';
208 {package Just::Another;
209 use AutoLoader 'AUTOLOAD';
211 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
214 sub test1 ($) { "test 1"; }
215 sub test2 ($$) { "test 2"; }
216 sub test3 ($$$) { "test 3"; }
217 sub testtesttesttest4_1 { "test 4"; }
218 sub testtesttesttest4_2 { "duplicate test 4"; }
219 sub Just::Another::test5 { "another test 5"; }
220 sub test6 { return join ":", __FILE__,__LINE__; }
221 package Yet::Another::AutoSplit;
222 sub testtesttesttest4_1 ($) { "another test 4"; }
223 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
224 package Yet::More::Attributes;
225 sub test_a1 ($) : locked :locked { 1; }
226 sub test_a2 : locked { 1; }
227 # And that was all it has. You were expected to manually inspect the output
229 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
230 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
231 *INC**PATHSEP**MOD*.pm: some names are not unique when truncated to 8 characters:
232 directory *DIR**PATHSEP**MOD**ENDPATHSEP*:
233 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
234 directory *DIR**PATHSEP*Yet*PATHSEP*Another*PATHSEP*AutoSplit*ENDPATHSEP*:
235 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
237 *DIR*/*MOD*/autosplit.ix
241 *DIR*/*MOD*/testtesttesttest4_1.al
242 *DIR*/*MOD*/testtesttesttest4_2.al
243 *DIR*/Just/Another/test5.al
245 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
246 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
247 *DIR*/Yet/More/Attributes/test_a1.al
248 *DIR*/Yet/More/Attributes/test_a2.al
252 # Need to find these lines somewhere in the required file
254 sub test2\s*\(\$\$\);
255 sub test3\s*\(\$\$\$\);
256 sub testtesttesttest4_1\s*\(\$\);
257 sub testtesttesttest4_2\s*\(\$\$\);
258 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
259 sub test_a2\s*:\s*locked\s*;
261 is (*MOD*::test1 (1), 'test 1');
262 is (*MOD*::test2 (1,2), 'test 2');
263 is (*MOD*::test3 (1,2,3), 'test 3');
264 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
265 is (&*MOD*::testtesttesttest4_1, "test 4");
266 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
267 is (&Just::Another::test5, "another test 5");
268 # very messy way to interpolate function into regexp, but it's going to be
269 # needed to get : for Mac filespecs
270 like (&*MOD*::test6, qr!^\Q*INC**PATHSEP**MOD*\E\.pm \(autosplit into \Q@{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\E\):\d+$!);
271 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
272 ################################################################
274 missing use AutoLoader;
280 # There should be no files.
281 ################################################################
283 missing use AutoLoader; (but don't skip)
290 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
294 *DIR*/*MOD*/autosplit.ix
295 ################################################################
297 Split prior to checking whether obsolete files get deleted
299 use AutoLoader 'AUTOLOAD';
302 sub obsolete {my $a if 0; return $a++;}
303 sub gonner {warn "This gonner function should never get called"}
305 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
309 *DIR*/*MOD*/autosplit.ix
310 *DIR*/*MOD*/gonner.al
311 *DIR*/*MOD*/obsolete.al
313 is (&*MOD*::obsolete, 0);
314 is (&*MOD*::obsolete, 1);
318 True, so don't scrub this directory.
319 IIRC DOS FAT filesystems have only 2 second granularity.
320 ################################################################
322 Check whether obsolete files get deleted
324 use AutoLoader 'AUTOLOAD';
327 sub skeleton {"bones"};
328 sub ghost {"scream"}; # This definition gets overwritten with the one below
330 sub zombie {"You didn't use fire."};
331 sub flying_pig {"Oink oink flap flap"};
333 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
337 *DIR*/*MOD*/autosplit.ix
338 *DIR*/*MOD*/skeleton.al
339 *DIR*/*MOD*/zombie.al
342 *DIR*/*MOD*/flying_pig.al
344 is (&*MOD*::skeleton, "bones", "skeleton");
345 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
349 True, so don't scrub this directory.
350 ################################################################
352 Check whether obsolete files remain when keep is 1
356 use AutoLoader 'AUTOLOAD';
362 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
366 *DIR*/*MOD*/autosplit.ix
367 *DIR*/*MOD*/skeleton.al
368 *DIR*/*MOD*/zombie.al
371 *DIR*/*MOD*/wraith.al
372 *DIR*/*MOD*/flying_pig.al
374 is (&*MOD*::ghost, "bump");
375 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
379 True, so don't scrub this directory.
380 ################################################################
382 Without the timestamp check make sure that nothing happens
388 *DIR*/*MOD*/autosplit.ix
389 *DIR*/*MOD*/skeleton.al
390 *DIR*/*MOD*/zombie.al
393 *DIR*/*MOD*/wraith.al
394 *DIR*/*MOD*/flying_pig.al
396 is (&*MOD*::ghoul, "wail", "still haunted");
397 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
401 True, so don't scrub this directory.
402 ################################################################
404 With the timestamp check make sure that things happen (stuff gets deleted)
408 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
412 *DIR*/*MOD*/autosplit.ix
414 *DIR*/*MOD*/wraith.al
416 is (&*MOD*::wraith, 9);
417 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";