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 $?;
71 my $dir = File::Spec->catdir($incdir, 'auto');
73 $dir = VMS::Filespec::unixify($dir);
77 my $module = 'A' . $i . '_' . $$ . 'splittest';
78 my $file = File::Spec->catfile($incdir,"$module.pm");
82 s/\*PATHSEP\*/$pathsep/gm;
84 # Build a hash for this test.
85 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
86 ((?:[^\#]+ # Any number of characters not #
87 | \#(?!\#) # or a # character not followed by #
88 | (?<!\n)\# # or a # character not preceded by \n
90 foreach ($args{Name}, $args{Require}, $args{Extra}) {
91 chomp $_ if defined $_;
93 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
96 $body ="package $module;\n" . $args{File};
97 $output = split_a_file ($body, $file, $dir, @extra_args);
100 $output = split_a_file (undef, $file, $dir, @extra_args);
104 my ($filespec, $replacement);
105 while ($output =~ m/(\[.+\])/) {
107 $replacement = VMS::Filespec::unixify($filespec);
108 $replacement =~ s/\/$//;
109 $output =~ s/\Q$filespec\E/$replacement/;
114 is ($output, $args{Get}, "Output from autosplit()ing $args{Name}");
117 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
119 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
120 foreach (split /\n/, $args{Files}) {
122 $_ = lc($_) if $^O eq 'VMS';
123 unless (delete $got{$_}) {
127 my @missing = keys %missing;
129 unless (ok (!@missing, "Are any expected files missing?")) {
130 print "# These files are missing\n";
131 print "# $_\n" foreach sort @missing;
133 my @extra = keys %got;
135 unless (ok (!@extra, "Are any extra files present?")) {
136 print "# These files are unexpectedly present:\n";
137 print "# $_\n" foreach sort @extra;
140 if ($args{Require}) {
141 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
142 $com =~ s{\\}{/}gm if ($^O eq 'MSWin32');
145 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
147 eval $body or die $@;
150 # match tests to check for prototypes
153 my $file = File::Spec->catfile($dir, $args{Require});
154 open IX, $file or die "Can't open '$file': $!";
156 close IX or die "Can't close '$file': $!";
157 foreach my $pat (split /\n/, $args{Match}) {
158 next if $pat =~ /^\#/;
159 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
162 # code tests contain eval{}ed ok()s etc
164 foreach my $code (split /\n/, $args{Tests}) {
165 next if $code =~ /^\#/;
166 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
169 if (my $sleepfor = $args{Sleep}) {
170 # We need to sleep for a while
171 # Need the sleep hack else the next test is so fast that the timestamp
172 # compare routine in AutoSplit thinks that it shouldn't split the files.
174 my $until = $time + $sleepfor;
178 } while (time < $until && --$attempts > 0);
179 if ($attempts == 0) {
180 printf << "EOM", time;
181 # Attempted to sleep for $sleepfor second(s), started at $time, now %d.
182 # sleep attempt ppears to have failed; some tests may fail as a result.
186 unless ($args{SameAgain}) {
195 tests from the end of the AutoSplit module.
197 use AutoLoader 'AUTOLOAD';
198 {package Just::Another;
199 use AutoLoader 'AUTOLOAD';
201 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
204 sub test1 ($) { "test 1"; }
205 sub test2 ($$) { "test 2"; }
206 sub test3 ($$$) { "test 3"; }
207 sub testtesttesttest4_1 { "test 4"; }
208 sub testtesttesttest4_2 { "duplicate test 4"; }
209 sub Just::Another::test5 { "another test 5"; }
210 sub test6 { return join ":", __FILE__,__LINE__; }
211 package Yet::Another::AutoSplit;
212 sub testtesttesttest4_1 ($) { "another test 4"; }
213 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
214 package Yet::More::Attributes;
215 sub test_a1 ($) : locked :locked { 1; }
216 sub test_a2 : locked { 1; }
217 # And that was all it has. You were expected to manually inspect the output
219 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
220 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
221 *INC**PATHSEP**MOD*.pm: some names are not unique when truncated to 8 characters:
222 directory *DIR**PATHSEP**MOD*:
223 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
224 directory *DIR**PATHSEP*Yet*PATHSEP*Another*PATHSEP*AutoSplit:
225 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
227 *DIR*/*MOD*/autosplit.ix
231 *DIR*/*MOD*/testtesttesttest4_1.al
232 *DIR*/*MOD*/testtesttesttest4_2.al
233 *DIR*/Just/Another/test5.al
235 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
236 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
237 *DIR*/Yet/More/Attributes/test_a1.al
238 *DIR*/Yet/More/Attributes/test_a2.al
242 # Need to find these lines somewhere in the required file
244 sub test2\s*\(\$\$\);
245 sub test3\s*\(\$\$\$\);
246 sub testtesttesttest4_1\s*\(\$\);
247 sub testtesttesttest4_2\s*\(\$\$\);
248 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
249 sub test_a2\s*:\s*locked\s*;
251 is (*MOD*::test1 (1), 'test 1');
252 is (*MOD*::test2 (1,2), 'test 2');
253 is (*MOD*::test3 (1,2,3), 'test 3');
254 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
255 is (&*MOD*::testtesttesttest4_1, "test 4");
256 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
257 is (&Just::Another::test5, "another test 5");
258 # very messy way to interpolate function into regexp, but it's going to be
259 # needed to get : for Mac filespecs
260 like (&*MOD*::test6, qr!^\Q*INC**PATHSEP**MOD*\E\.pm \(autosplit into \Q@{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\E\):\d+$!);
261 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
262 ################################################################
264 missing use AutoLoader;
270 # There should be no files.
271 ################################################################
273 missing use AutoLoader; (but don't skip)
280 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
284 *DIR*/*MOD*/autosplit.ix
285 ################################################################
287 Split prior to checking whether obsolete files get deleted
289 use AutoLoader 'AUTOLOAD';
292 sub obsolete {my $a if 0; return $a++;}
293 sub gonner {warn "This gonner function should never get called"}
295 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
299 *DIR*/*MOD*/autosplit.ix
300 *DIR*/*MOD*/gonner.al
301 *DIR*/*MOD*/obsolete.al
303 is (&*MOD*::obsolete, 0);
304 is (&*MOD*::obsolete, 1);
308 True, so don't scrub this directory.
309 IIRC DOS FAT filesystems have only 2 second granularity.
310 ################################################################
312 Check whether obsolete files get deleted
314 use AutoLoader 'AUTOLOAD';
317 sub skeleton {"bones"};
318 sub ghost {"scream"}; # This definition gets overwritten with the one below
320 sub zombie {"You didn't use fire."};
321 sub flying_pig {"Oink oink flap flap"};
323 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
327 *DIR*/*MOD*/autosplit.ix
328 *DIR*/*MOD*/skeleton.al
329 *DIR*/*MOD*/zombie.al
332 *DIR*/*MOD*/flying_pig.al
334 is (&*MOD*::skeleton, "bones", "skeleton");
335 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
339 True, so don't scrub this directory.
340 ################################################################
342 Check whether obsolete files remain when keep is 1
346 use AutoLoader 'AUTOLOAD';
352 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
356 *DIR*/*MOD*/autosplit.ix
357 *DIR*/*MOD*/skeleton.al
358 *DIR*/*MOD*/zombie.al
361 *DIR*/*MOD*/wraith.al
362 *DIR*/*MOD*/flying_pig.al
364 is (&*MOD*::ghost, "bump");
365 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
369 True, so don't scrub this directory.
370 ################################################################
372 Without the the timestamp check make sure that nothing happens
378 *DIR*/*MOD*/autosplit.ix
379 *DIR*/*MOD*/skeleton.al
380 *DIR*/*MOD*/zombie.al
383 *DIR*/*MOD*/wraith.al
384 *DIR*/*MOD*/flying_pig.al
386 is (&*MOD*::ghoul, "wail", "still haunted");
387 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
391 True, so don't scrub this directory.
392 ################################################################
394 With the the timestamp check make sure that things happen (stuff gets deleted)
398 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
402 *DIR*/*MOD*/autosplit.ix
404 *DIR*/*MOD*/wraith.al
406 is (&*MOD*::wraith, 9);
407 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";