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
11 print "1..0 # This test is not 8.3-aware.\n";
16 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
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' ? '\\' : '/';
57 if (defined $contents) {
58 open FILE, ">$file" or die "Can't open $file: $!";
60 close FILE or die "Can't close $file: $!";
63 # Assumption: no characters in arguments need escaping from the shell or perl
64 my $com = qq($runperl -e "use AutoSplit; autosplit (qw(@_))");
65 print "# command: $com\n";
66 # There may be a way to capture STDOUT without spawning a child process, but
67 # it's probably worthwhile spawning, as it ensures that nothing in AutoSplit
68 # can load functions from split modules into this perl.
70 warn "Exit status $? from running: >>$com<<" if $?;
75 my $dir = File::Spec->catdir($incdir, 'auto');
77 $dir = VMS::Filespec::unixify($dir);
81 my $module = 'A' . $i . '_' . $$ . 'splittest';
82 my $file = File::Spec->catfile($incdir,"$module.pm");
86 s/\*PATHSEP\*/$pathsep/gm;
88 # Build a hash for this test.
89 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
90 ((?:[^\#]+ # Any number of characters not #
91 | \#(?!\#) # or a # character not followed by #
92 | (?<!\n)\# # or a # character not preceded by \n
94 foreach ($args{Name}, $args{Require}, $args{Extra}) {
95 chomp $_ if defined $_;
97 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
100 $body ="package $module;\n" . $args{File};
101 $output = split_a_file ($body, $file, $dir, @extra_args);
104 $output = split_a_file (undef, $file, $dir, @extra_args);
108 my ($filespec, $replacement);
109 while ($output =~ m/(\[.+\])/) {
111 $replacement = VMS::Filespec::unixify($filespec);
112 $replacement =~ s/\/$//;
113 $output =~ s/\Q$filespec\E/$replacement/;
118 cmp_ok ($output, 'eq', $args{Get}, "Output from autosplit()ing $args{Name}");
121 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
123 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
124 foreach (split /\n/, $args{Files}) {
126 $_ = lc($_) if $^O eq 'VMS';
127 unless (delete $got{$_}) {
131 my @missing = keys %missing;
133 unless (ok (!@missing, "Are any expected files missing?")) {
134 print "# These files are missing\n";
135 print "# $_\n" foreach sort @missing;
137 my @extra = keys %got;
139 unless (ok (!@extra, "Are any extra files present?")) {
140 print "# These files are unexpectedly present:\n";
141 print "# $_\n" foreach sort @extra;
144 if ($args{Require}) {
145 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
146 $com =~ s{\\}{/}gm if ($^O eq 'MSWin32');
149 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
151 eval $body or die $@;
154 # match tests to check for prototypes
157 my $file = File::Spec->catfile($dir, $args{Require});
158 open IX, $file or die "Can't open '$file': $!";
160 close IX or die "Can't close '$file': $!";
161 foreach my $pat (split /\n/, $args{Match}) {
162 next if $pat =~ /^\#/;
163 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
166 # code tests contain eval{}ed ok()s etc
168 foreach my $code (split /\n/, $args{Tests}) {
169 next if $code =~ /^\#/;
170 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
173 if (my $sleepfor = $args{Sleep}) {
174 # We need to sleep for a while
175 # Need the sleep hack else the next test is so fast that the timestamp
176 # compare routine in AutoSplit thinks that it shouldn't split the files.
178 my $until = $time + $sleepfor;
182 } while (time < $until && --$attempts > 0);
183 if ($attempts == 0) {
184 printf << "EOM", time;
185 # Attempted to sleep for $sleepfor second(s), started at $time, now %d.
186 # sleep attempt ppears to have failed; some tests may fail as a result.
190 unless ($args{SameAgain}) {
199 tests from the end of the AutoSplit module.
201 use AutoLoader 'AUTOLOAD';
202 {package Just::Another;
203 use AutoLoader 'AUTOLOAD';
205 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
208 sub test1 ($) { "test 1"; }
209 sub test2 ($$) { "test 2"; }
210 sub test3 ($$$) { "test 3"; }
211 sub testtesttesttest4_1 { "test 4"; }
212 sub testtesttesttest4_2 { "duplicate test 4"; }
213 sub Just::Another::test5 { "another test 5"; }
214 sub test6 { return join ":", __FILE__,__LINE__; }
215 package Yet::Another::AutoSplit;
216 sub testtesttesttest4_1 ($) { "another test 4"; }
217 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
218 package Yet::More::Attributes;
219 sub test_a1 ($) : locked :locked { 1; }
220 sub test_a2 : locked { 1; }
221 # And that was all it has. You were expected to manually inspect the output
223 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
224 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
225 *INC**PATHSEP**MOD*.pm: some names are not unique when truncated to 8 characters:
226 directory *DIR**PATHSEP**MOD*:
227 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
228 directory *DIR**PATHSEP*Yet*PATHSEP*Another*PATHSEP*AutoSplit:
229 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
231 *DIR*/*MOD*/autosplit.ix
235 *DIR*/*MOD*/testtesttesttest4_1.al
236 *DIR*/*MOD*/testtesttesttest4_2.al
237 *DIR*/Just/Another/test5.al
239 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
240 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
241 *DIR*/Yet/More/Attributes/test_a1.al
242 *DIR*/Yet/More/Attributes/test_a2.al
246 # Need to find these lines somewhere in the required file
248 sub test2\s*\(\$\$\);
249 sub test3\s*\(\$\$\$\);
250 sub testtesttesttest4_1\s*\(\$\);
251 sub testtesttesttest4_2\s*\(\$\$\);
252 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
253 sub test_a2\s*:\s*locked\s*;
255 is (*MOD*::test1 (1), 'test 1');
256 is (*MOD*::test2 (1,2), 'test 2');
257 is (*MOD*::test3 (1,2,3), 'test 3');
258 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
259 is (&*MOD*::testtesttesttest4_1, "test 4");
260 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
261 is (&Just::Another::test5, "another test 5");
262 # very messy way to interpolate function into regexp, but it's going to be
263 # needed to get : for Mac filespecs
264 like (&*MOD*::test6, qr!^\Q*INC**PATHSEP**MOD*\E\.pm \(autosplit into \Q@{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\E\):\d+$!);
265 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
266 ################################################################
268 missing use AutoLoader;
274 # There should be no files.
275 ################################################################
277 missing use AutoLoader; (but don't skip)
284 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
288 *DIR*/*MOD*/autosplit.ix
289 ################################################################
291 Split prior to checking whether obsolete files get deleted
293 use AutoLoader 'AUTOLOAD';
296 sub obsolete {my $a if 0; return $a++;}
297 sub gonner {warn "This gonner function should never get called"}
299 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
303 *DIR*/*MOD*/autosplit.ix
304 *DIR*/*MOD*/gonner.al
305 *DIR*/*MOD*/obsolete.al
307 is (&*MOD*::obsolete, 0);
308 is (&*MOD*::obsolete, 1);
312 True, so don't scrub this directory.
313 IIRC DOS FAT filesystems have only 2 second granularity.
314 ################################################################
316 Check whether obsolete files get deleted
318 use AutoLoader 'AUTOLOAD';
321 sub skeleton {"bones"};
322 sub ghost {"scream"}; # This definition gets overwritten with the one below
324 sub zombie {"You didn't use fire."};
325 sub flying_pig {"Oink oink flap flap"};
327 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
331 *DIR*/*MOD*/autosplit.ix
332 *DIR*/*MOD*/skeleton.al
333 *DIR*/*MOD*/zombie.al
336 *DIR*/*MOD*/flying_pig.al
338 is (&*MOD*::skeleton, "bones", "skeleton");
339 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
343 True, so don't scrub this directory.
344 ################################################################
346 Check whether obsolete files remain when keep is 1
350 use AutoLoader 'AUTOLOAD';
356 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
360 *DIR*/*MOD*/autosplit.ix
361 *DIR*/*MOD*/skeleton.al
362 *DIR*/*MOD*/zombie.al
365 *DIR*/*MOD*/wraith.al
366 *DIR*/*MOD*/flying_pig.al
368 is (&*MOD*::ghost, "bump");
369 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
373 True, so don't scrub this directory.
374 ################################################################
376 Without the timestamp check make sure that nothing happens
382 *DIR*/*MOD*/autosplit.ix
383 *DIR*/*MOD*/skeleton.al
384 *DIR*/*MOD*/zombie.al
387 *DIR*/*MOD*/wraith.al
388 *DIR*/*MOD*/flying_pig.al
390 is (&*MOD*::ghoul, "wail", "still haunted");
391 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
395 True, so don't scrub this directory.
396 ################################################################
398 With the timestamp check make sure that things happen (stuff gets deleted)
402 AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD*)
406 *DIR*/*MOD*/autosplit.ix
408 *DIR*/*MOD*/wraith.al
410 is (&*MOD*::wraith, 9);
411 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";