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";
48 my $pathsep = $^O eq 'MSWin32' ? '\\' : '/';
53 if (defined $contents) {
54 open FILE, ">$file" or die "Can't open $file: $!";
56 close FILE or die "Can't close $file: $!";
59 # Assumption: no characters in arguments need escaping from the shell or perl
60 my $com = qq($runperl -e "use AutoSplit; autosplit (qw(@_))");
61 print "# command: $com\n";
62 # There may be a way to capture STDOUT without spawning a child process, but
63 # it's probably worthwhile spawning, as it ensures that nothing in AutoSplit
64 # can load functions from split modules into this perl.
66 warn "Exit status $? from running: >>$com<<" if $?;
70 # Brackets are valid in VMS filespecs and this test puts filespecs
73 sub _escape_brackets {
81 my $dir = File::Spec->catdir($incdir, 'auto');
83 $dir = VMS::Filespec::unixify($dir);
87 my $module = 'A' . $i . '_' . $$ . 'splittest';
88 my $file = File::Spec->catfile($incdir,"$module.pm");
92 s/\*PATHSEP\*/$pathsep/gm;
94 # Build a hash for this test.
95 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
96 ((?:[^\#]+ # Any number of characters not #
97 | \#(?!\#) # or a # character not followed by #
98 | (?<!\n)\# # or a # character not preceded by \n
100 foreach ($args{Name}, $args{Require}, $args{Extra}) {
101 chomp $_ if defined $_;
103 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
106 $body ="package $module;\n" . $args{File};
107 $output = split_a_file ($body, $file, $dir, @extra_args);
110 $output = split_a_file (undef, $file, $dir, @extra_args);
114 my ($filespec, $replacement);
115 while ($output =~ m/(\[.+\])/) {
117 $replacement = VMS::Filespec::unixify($filespec);
118 $filespec = _escape_brackets($filespec);
119 $replacement =~ s/\/$//;
120 $output =~ s/$filespec/$replacement/;
125 is ($output, $args{Get}, "Output from autosplit()ing $args{Name}");
128 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
130 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
131 foreach (split /\n/, $args{Files}) {
133 $_ = lc($_) if $^O eq 'VMS';
134 unless (delete $got{$_}) {
138 my @missing = keys %missing;
140 unless (ok (!@missing, "Are any expected files missing?")) {
141 print "# These files are missing\n";
142 print "# $_\n" foreach sort @missing;
144 my @extra = keys %got;
146 unless (ok (!@extra, "Are any extra files present?")) {
147 print "# These files are unexpectedly present:\n";
148 print "# $_\n" foreach sort @extra;
151 if ($args{Require}) {
152 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
153 $com =~ s{\\}{/}gm if ($^O eq 'MSWin32');
156 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
158 eval $body or die $@;
161 # match tests to check for prototypes
164 my $file = File::Spec->catfile($dir, $args{Require});
165 open IX, $file or die "Can't open '$file': $!";
167 close IX or die "Can't close '$file': $!";
168 foreach my $pat (split /\n/, $args{Match}) {
169 next if $pat =~ /^\#/;
170 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
173 # code tests contain eval{}ed ok()s etc
175 foreach my $code (split /\n/, $args{Tests}) {
176 next if $code =~ /^\#/;
177 $code =~ s/\[(File::Spec->catfile\(.*\))\]/[_escape_brackets($1)]/ if $^O eq 'VMS';
178 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
181 if (my $sleepfor = $args{Sleep}) {
182 # We need to sleep for a while
183 # Need the sleep hack else the next test is so fast that the timestamp
184 # compare routine in AutoSplit thinks that it shouldn't split the files.
186 my $until = $time + $sleepfor;
190 } while (time < $until && --$attempts > 0);
191 if ($attempts == 0) {
192 printf << "EOM", time;
193 # Attempted to sleep for $sleepfor second(s), started at $time, now %d.
194 # sleep attempt ppears to have failed; some tests may fail as a result.
198 unless ($args{SameAgain}) {
207 tests from the end of the AutoSplit module.
209 use AutoLoader 'AUTOLOAD';
210 {package Just::Another;
211 use AutoLoader 'AUTOLOAD';
213 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
216 sub test1 ($) { "test 1"; }
217 sub test2 ($$) { "test 2"; }
218 sub test3 ($$$) { "test 3"; }
219 sub testtesttesttest4_1 { "test 4"; }
220 sub testtesttesttest4_2 { "duplicate test 4"; }
221 sub Just::Another::test5 { "another test 5"; }
222 sub test6 { return join ":", __FILE__,__LINE__; }
223 package Yet::Another::AutoSplit;
224 sub testtesttesttest4_1 ($) { "another test 4"; }
225 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
226 package Yet::More::Attributes;
227 sub test_a1 ($) : locked :locked { 1; }
228 sub test_a2 : locked { 1; }
229 # And that was all it has. You were expected to manually inspect the output
231 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
232 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
233 *INC**PATHSEP**MOD*.pm: some names are not unique when truncated to 8 characters:
234 directory *DIR**PATHSEP**MOD*:
235 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
236 directory *DIR**PATHSEP*Yet*PATHSEP*Another*PATHSEP*AutoSplit:
237 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
239 *DIR*/*MOD*/autosplit.ix
243 *DIR*/*MOD*/testtesttesttest4_1.al
244 *DIR*/*MOD*/testtesttesttest4_2.al
245 *DIR*/Just/Another/test5.al
247 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
248 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
249 *DIR*/Yet/More/Attributes/test_a1.al
250 *DIR*/Yet/More/Attributes/test_a2.al
254 # Need to find these lines somewhere in the required file
256 sub test2\s*\(\$\$\);
257 sub test3\s*\(\$\$\$\);
258 sub testtesttesttest4_1\s*\(\$\);
259 sub testtesttesttest4_2\s*\(\$\$\);
260 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
261 sub test_a2\s*:\s*locked\s*;
263 is (*MOD*::test1 (1), 'test 1');
264 is (*MOD*::test2 (1,2), 'test 2');
265 is (*MOD*::test3 (1,2,3), 'test 3');
266 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
267 is (&*MOD*::testtesttesttest4_1, "test 4");
268 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
269 is (&Just::Another::test5, "another test 5");
270 # very messy way to interpolate function into regexp, but it's going to be
271 # needed to get : for Mac filespecs
272 like (&*MOD*::test6, qr!^\Q*INC**PATHSEP**MOD*\E\.pm \(autosplit into \Q@{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\E\):\d+$!);
273 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
274 ################################################################
276 missing use AutoLoader;
282 # There should be no files.
283 ################################################################
285 missing use AutoLoader; (but don't skip)
292 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
296 *DIR*/*MOD*/autosplit.ix
297 ################################################################
299 Split prior to checking whether obsolete files get deleted
301 use AutoLoader 'AUTOLOAD';
304 sub obsolete {my $a if 0; return $a++;}
305 sub gonner {warn "This gonner function should never get called"}
307 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
311 *DIR*/*MOD*/autosplit.ix
312 *DIR*/*MOD*/gonner.al
313 *DIR*/*MOD*/obsolete.al
315 is (&*MOD*::obsolete, 0);
316 is (&*MOD*::obsolete, 1);
320 True, so don't scrub this directory.
321 IIRC DOS FAT filesystems have only 2 second granularity.
322 ################################################################
324 Check whether obsolete files get deleted
326 use AutoLoader 'AUTOLOAD';
329 sub skeleton {"bones"};
330 sub ghost {"scream"}; # This definition gets overwritten with the one below
332 sub zombie {"You didn't use fire."};
333 sub flying_pig {"Oink oink flap flap"};
335 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
339 *DIR*/*MOD*/autosplit.ix
340 *DIR*/*MOD*/skeleton.al
341 *DIR*/*MOD*/zombie.al
344 *DIR*/*MOD*/flying_pig.al
346 is (&*MOD*::skeleton, "bones", "skeleton");
347 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
351 True, so don't scrub this directory.
352 ################################################################
354 Check whether obsolete files remain when keep is 1
358 use AutoLoader 'AUTOLOAD';
364 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
368 *DIR*/*MOD*/autosplit.ix
369 *DIR*/*MOD*/skeleton.al
370 *DIR*/*MOD*/zombie.al
373 *DIR*/*MOD*/wraith.al
374 *DIR*/*MOD*/flying_pig.al
376 is (&*MOD*::ghost, "bump");
377 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
381 True, so don't scrub this directory.
382 ################################################################
384 Without the the timestamp check make sure that nothing happens
390 *DIR*/*MOD*/autosplit.ix
391 *DIR*/*MOD*/skeleton.al
392 *DIR*/*MOD*/zombie.al
395 *DIR*/*MOD*/wraith.al
396 *DIR*/*MOD*/flying_pig.al
398 is (&*MOD*::ghoul, "wail", "still haunted");
399 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
403 True, so don't scrub this directory.
404 ################################################################
406 With the the timestamp check make sure that things happen (stuff gets deleted)
410 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
414 *DIR*/*MOD*/autosplit.ix
416 *DIR*/*MOD*/wraith.al
418 is (&*MOD*::wraith, 9);
419 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";