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 $?;
68 # Brackets are valid in VMS filespecs and this test puts filespecs
71 sub _escape_brackets {
79 my $dir = File::Spec->catdir($incdir, 'auto');
81 $dir = VMS::Filespec::unixify($dir);
85 my $module = 'A' . $i . '_' . $$ . 'splittest';
86 my $file = File::Spec->catfile($incdir,"$module.pm");
91 # Build a hash for this test.
92 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
93 ((?:[^\#]+ # Any number of characters not #
94 | \#(?!\#) # or a # character not followed by #
95 | (?<!\n)\# # or a # character not preceded by \n
97 foreach ($args{Name}, $args{Require}, $args{Extra}) {
98 chomp $_ if defined $_;
100 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
103 $body ="package $module;\n" . $args{File};
104 $output = split_a_file ($body, $file, $dir, @extra_args);
107 $output = split_a_file (undef, $file, $dir, @extra_args);
111 my ($filespec, $replacement);
112 while ($output =~ m/(\[.+\])/) {
114 $replacement = VMS::Filespec::unixify($filespec);
115 $filespec = _escape_brackets($filespec);
116 $replacement =~ s/\/$//;
117 $output =~ s/$filespec/$replacement/;
122 is ($output, $args{Get}, "Output from autosplit()ing $args{Name}");
125 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
127 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
128 foreach (split /\n/, $args{Files}) {
130 $_ = lc($_) if $^O eq 'VMS';
131 unless (delete $got{$_}) {
135 my @missing = keys %missing;
137 unless (ok (!@missing, "Are any expected files missing?")) {
138 print "# These files are missing\n";
139 print "# $_\n" foreach sort @missing;
141 my @extra = keys %got;
143 unless (ok (!@extra, "Are any extra files present?")) {
144 print "# These files are unexpectedly present:\n";
145 print "# $_\n" foreach sort @extra;
148 if ($args{Require}) {
149 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
152 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
154 eval $body or die $@;
157 # match tests to check for prototypes
160 my $file = File::Spec->catfile($dir, $args{Require});
161 open IX, $file or die "Can't open '$file': $!";
163 close IX or die "Can't close '$file': $!";
164 foreach my $pat (split /\n/, $args{Match}) {
165 next if $pat =~ /^\#/;
166 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
169 # code tests contain eval{}ed ok()s etc
171 foreach my $code (split /\n/, $args{Tests}) {
172 next if $code =~ /^\#/;
173 $code =~ s/\[(File::Spec->catfile\(.*\))\]/[_escape_brackets($1)]/ if $^O eq 'VMS';
174 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
177 if (my $sleepfor = $args{Sleep}) {
178 # We need to sleep for a while
179 # Need the sleep hack else the next test is so fast that the timestamp
180 # compare routine in AutoSplit thinks that it shouldn't split the files.
182 my $until = $time + $sleepfor;
186 } while (time < $until && --$attempts > 0);
187 if ($attempts == 0) {
188 printf << "EOM", time;
189 # Attempted to sleep for $sleepfor second(s), started at $time, now %d.
190 # sleep attempt ppears to have failed; some tests may fail as a result.
194 unless ($args{SameAgain}) {
203 tests from the end of the AutoSplit module.
205 use AutoLoader 'AUTOLOAD';
206 {package Just::Another;
207 use AutoLoader 'AUTOLOAD';
209 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
212 sub test1 ($) { "test 1"; }
213 sub test2 ($$) { "test 2"; }
214 sub test3 ($$$) { "test 3"; }
215 sub testtesttesttest4_1 { "test 4"; }
216 sub testtesttesttest4_2 { "duplicate test 4"; }
217 sub Just::Another::test5 { "another test 5"; }
218 sub test6 { return join ":", __FILE__,__LINE__; }
219 package Yet::Another::AutoSplit;
220 sub testtesttesttest4_1 ($) { "another test 4"; }
221 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
222 package Yet::More::Attributes;
223 sub test_a1 ($) : locked :locked { 1; }
224 sub test_a2 : locked { 1; }
225 # And that was all it has. You were expected to manually inspect the output
227 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
228 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
229 *INC*/*MOD*.pm: some names are not unique when truncated to 8 characters:
230 directory *DIR*/*MOD*:
231 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
232 directory *DIR*/Yet/Another/AutoSplit:
233 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
235 *DIR*/*MOD*/autosplit.ix
239 *DIR*/*MOD*/testtesttesttest4_1.al
240 *DIR*/*MOD*/testtesttesttest4_2.al
241 *DIR*/Just/Another/test5.al
243 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
244 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
245 *DIR*/Yet/More/Attributes/test_a1.al
246 *DIR*/Yet/More/Attributes/test_a2.al
250 # Need to find these lines somewhere in the required file
252 sub test2\s*\(\$\$\);
253 sub test3\s*\(\$\$\$\);
254 sub testtesttesttest4_1\s*\(\$\);
255 sub testtesttesttest4_2\s*\(\$\$\);
256 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
257 sub test_a2\s*:\s*locked\s*;
259 is (*MOD*::test1 (1), 'test 1');
260 is (*MOD*::test2 (1,2), 'test 2');
261 is (*MOD*::test3 (1,2,3), 'test 3');
262 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
263 is (&*MOD*::testtesttesttest4_1, "test 4");
264 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
265 is (&Just::Another::test5, "another test 5");
266 # very messy way to interpolate function into regexp, but it's going to be
267 # needed to get : for Mac filespecs
268 like (&*MOD*::test6, qr!^*INC*/*MOD*.pm \(autosplit into @{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\):\d+$!);
269 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
270 ################################################################
272 missing use AutoLoader;
278 # There should be no files.
279 ################################################################
281 missing use AutoLoader; (but don't skip)
288 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
292 *DIR*/*MOD*/autosplit.ix
293 ################################################################
295 Split prior to checking whether obsolete files get deleted
297 use AutoLoader 'AUTOLOAD';
300 sub obsolete {my $a if 0; return $a++;}
301 sub gonner {warn "This gonner function should never get called"}
303 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
307 *DIR*/*MOD*/autosplit.ix
308 *DIR*/*MOD*/gonner.al
309 *DIR*/*MOD*/obsolete.al
311 is (&*MOD*::obsolete, 0);
312 is (&*MOD*::obsolete, 1);
316 True, so don't scrub this directory.
317 IIRC DOS FAT filesystems have only 2 second granularity.
318 ################################################################
320 Check whether obsolete files get deleted
322 use AutoLoader 'AUTOLOAD';
325 sub skeleton {"bones"};
326 sub ghost {"scream"}; # This definition gets overwritten with the one below
328 sub zombie {"You didn't use fire."};
329 sub flying_pig {"Oink oink flap flap"};
331 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
335 *DIR*/*MOD*/autosplit.ix
336 *DIR*/*MOD*/skeleton.al
337 *DIR*/*MOD*/zombie.al
340 *DIR*/*MOD*/flying_pig.al
342 is (&*MOD*::skeleton, "bones", "skeleton");
343 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
347 True, so don't scrub this directory.
348 ################################################################
350 Check whether obsolete files remain when keep is 1
354 use AutoLoader 'AUTOLOAD';
360 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
364 *DIR*/*MOD*/autosplit.ix
365 *DIR*/*MOD*/skeleton.al
366 *DIR*/*MOD*/zombie.al
369 *DIR*/*MOD*/wraith.al
370 *DIR*/*MOD*/flying_pig.al
372 is (&*MOD*::ghost, "bump");
373 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
377 True, so don't scrub this directory.
378 ################################################################
380 Without the the timestamp check make sure that nothing happens
386 *DIR*/*MOD*/autosplit.ix
387 *DIR*/*MOD*/skeleton.al
388 *DIR*/*MOD*/zombie.al
391 *DIR*/*MOD*/wraith.al
392 *DIR*/*MOD*/flying_pig.al
394 is (&*MOD*::ghoul, "wail", "still haunted");
395 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
399 True, so don't scrub this directory.
400 ################################################################
402 With the the timestamp check make sure that things happen (stuff gets deleted)
406 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
410 *DIR*/*MOD*/autosplit.ix
412 *DIR*/*MOD*/wraith.al
414 is (&*MOD*::wraith, 9);
415 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";