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 $?;
69 my $dir = File::Spec->catfile($incdir, 'auto');
71 my $module = 'A' . $i . '_' . $$ . 'splittest';
72 my $file = File::Spec->catfile($incdir,"$module.pm");
76 # Build a hash for this test.
77 my %args = /^\#\#\ ([^\n]*)\n # Key is on a line starting ##
78 ((?:[^\#]+ # Any number of characters not #
79 | \#(?!\#) # or a # character not followed by #
80 | (?<!\n)\# # or a # character not preceded by \n
82 foreach ($args{Name}, $args{Require}, $args{Extra}) {
83 chomp $_ if defined $_;
85 my @extra_args = !defined $args{Extra} ? () : split /,/, $args{Extra};
88 $body ="package $module;\n" . $args{File};
89 $output = split_a_file ($body, $file, $dir, @extra_args);
92 $output = split_a_file (undef, $file, $dir, @extra_args);
96 is ($output, $args{Get}, "Output from autosplit()ing $args{Name}");
99 $args{Files} =~ s!/!:!gs if $^O eq 'MacOS';
101 find (sub {$got{$File::Find::name}++ unless -d $_}, $dir);
102 foreach (split /\n/, $args{Files}) {
104 unless (delete $got{$_}) {
108 my @missing = keys %missing;
110 unless (ok (!@missing, "Are any expected files missing?")) {
111 print "# These files are missing\n";
112 print "# $_\n" foreach sort @missing;
114 my @extra = keys %got;
116 unless (ok (!@extra, "Are any extra files present?")) {
117 print "# These files are unexpectedly present:\n";
118 print "# $_\n" foreach sort @extra;
121 if ($args{Require}) {
122 my $com = 'require "' . File::Spec->catfile ('auto', $args{Require}) . '"';
125 ok ($@ eq '', $com) or print "# \$\@ = '$@'\n";
127 eval $body or die $@;
130 # match tests to check for prototypes
133 my $file = File::Spec->catfile($dir, $args{Require});
134 open IX, $file or die "Can't open '$file': $!";
136 close IX or die "Can't close '$file': $!";
137 foreach my $pat (split /\n/, $args{Match}) {
138 next if $pat =~ /^\#/;
139 like ($ix, qr/^\s*$pat\s*$/m, "match $pat");
142 # code tests contain eval{}ed ok()s etc
144 foreach my $code (split /\n/, $args{Tests}) {
145 next if $code =~ /^\#/;
146 defined eval $code or fail(), print "# Code: $code\n# Error: $@";
149 if (my $sleepfor = $args{Sleep}) {
150 # We need to sleep for a while
151 # Need the sleep hack else the next test is so fast that the timestamp
152 # compare routine in AutoSplit thinks that it shouldn't split the files.
154 my $until = $time + $sleepfor;
158 } while (time < $until && --$attempts > 0);
159 if ($attempts == 0) {
160 printf << "EOM", time;
161 # Attempted to sleep for $sleepfor second(s), started at $time, now %d.
162 # sleep attempt ppears to have failed; some tests may fail as a result.
166 unless ($args{SameAgain}) {
175 tests from the end of the AutoSplit module.
177 use AutoLoader 'AUTOLOAD';
178 {package Just::Another;
179 use AutoLoader 'AUTOLOAD';
181 @Yet::Another::AutoSplit::ISA = 'AutoLoader';
184 sub test1 ($) { "test 1"; }
185 sub test2 ($$) { "test 2"; }
186 sub test3 ($$$) { "test 3"; }
187 sub testtesttesttest4_1 { "test 4"; }
188 sub testtesttesttest4_2 { "duplicate test 4"; }
189 sub Just::Another::test5 { "another test 5"; }
190 sub test6 { return join ":", __FILE__,__LINE__; }
191 package Yet::Another::AutoSplit;
192 sub testtesttesttest4_1 ($) { "another test 4"; }
193 sub testtesttesttest4_2 ($$) { "another duplicate test 4"; }
194 package Yet::More::Attributes;
195 sub test_a1 ($) : locked :locked { 1; }
196 sub test_a2 : locked { 1; }
197 # And that was all it has. You were expected to manually inspect the output
199 Warning: AutoSplit had to create top-level *DIR* unexpectedly.
200 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
201 *INC*/*MOD*.pm: some names are not unique when truncated to 8 characters:
202 directory *DIR*/*MOD*:
203 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
204 directory *DIR*/Yet/Another/AutoSplit:
205 testtesttesttest4_1.al, testtesttesttest4_2.al truncate to testtest
207 *DIR*/*MOD*/autosplit.ix
211 *DIR*/*MOD*/testtesttesttest4_1.al
212 *DIR*/*MOD*/testtesttesttest4_2.al
213 *DIR*/Just/Another/test5.al
215 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_1.al
216 *DIR*/Yet/Another/AutoSplit/testtesttesttest4_2.al
217 *DIR*/Yet/More/Attributes/test_a1.al
218 *DIR*/Yet/More/Attributes/test_a2.al
222 # Need to find these lines somewhere in the required file
224 sub test2\s*\(\$\$\);
225 sub test3\s*\(\$\$\$\);
226 sub testtesttesttest4_1\s*\(\$\);
227 sub testtesttesttest4_2\s*\(\$\$\);
228 sub test_a1\s*\(\$\)\s*:\s*locked\s*:\s*locked\s*;
229 sub test_a2\s*:\s*locked\s*;
231 is (*MOD*::test1 (1), 'test 1');
232 is (*MOD*::test2 (1,2), 'test 2');
233 is (*MOD*::test3 (1,2,3), 'test 3');
234 ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
235 is (&*MOD*::testtesttesttest4_1, "test 4");
236 is (&*MOD*::testtesttesttest4_2, "duplicate test 4");
237 is (&Just::Another::test5, "another test 5");
238 # very messy way to interpolate function into regexp, but it's going to be
239 # needed to get : for Mac filespecs
240 like (&*MOD*::test6, qr!^*INC*/*MOD*.pm \(autosplit into @{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\):\d+$!);
241 ok (Yet::Another::AutoSplit->testtesttesttest4_1 eq "another test 4");
242 ################################################################
244 missing use AutoLoader;
250 # There should be no files.
251 ################################################################
253 missing use AutoLoader; (but don't skip)
260 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
264 *DIR*/*MOD*/autosplit.ix
265 ################################################################
267 Split prior to checking whether obsolete files get deleted
269 use AutoLoader 'AUTOLOAD';
272 sub obsolete {my $a if 0; return $a++;}
273 sub gonner {warn "This gonner function should never get called"}
275 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
279 *DIR*/*MOD*/autosplit.ix
280 *DIR*/*MOD*/gonner.al
281 *DIR*/*MOD*/obsolete.al
283 is (&*MOD*::obsolete, 0);
284 is (&*MOD*::obsolete, 1);
288 True, so don't scrub this directory.
289 IIRC DOS FAT filesystems have only 2 second granularity.
290 ################################################################
292 Check whether obsolete files get deleted
294 use AutoLoader 'AUTOLOAD';
297 sub skeleton {"bones"};
298 sub ghost {"scream"}; # This definition gets overwritten with the one below
300 sub zombie {"You didn't use fire."};
301 sub flying_pig {"Oink oink flap flap"};
303 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
307 *DIR*/*MOD*/autosplit.ix
308 *DIR*/*MOD*/skeleton.al
309 *DIR*/*MOD*/zombie.al
312 *DIR*/*MOD*/flying_pig.al
314 is (&*MOD*::skeleton, "bones", "skeleton");
315 eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
319 True, so don't scrub this directory.
320 ################################################################
322 Check whether obsolete files remain when keep is 1
326 use AutoLoader 'AUTOLOAD';
332 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
336 *DIR*/*MOD*/autosplit.ix
337 *DIR*/*MOD*/skeleton.al
338 *DIR*/*MOD*/zombie.al
341 *DIR*/*MOD*/wraith.al
342 *DIR*/*MOD*/flying_pig.al
344 is (&*MOD*::ghost, "bump");
345 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies undead?");
349 True, so don't scrub this directory.
350 ################################################################
352 Without the the timestamp check make sure that nothing happens
358 *DIR*/*MOD*/autosplit.ix
359 *DIR*/*MOD*/skeleton.al
360 *DIR*/*MOD*/zombie.al
363 *DIR*/*MOD*/wraith.al
364 *DIR*/*MOD*/flying_pig.al
366 is (&*MOD*::ghoul, "wail", "still haunted");
367 is (&*MOD*::zombie, "You didn't use fire.", "Are our zombies still undead?");
371 True, so don't scrub this directory.
372 ################################################################
374 With the the timestamp check make sure that things happen (stuff gets deleted)
378 AutoSplitting *INC*/*MOD*.pm (*DIR*/*MOD*)
382 *DIR*/*MOD*/autosplit.ix
384 *DIR*/*MOD*/wraith.al
386 is (&*MOD*::wraith, 9);
387 eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";