AutoSplit.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl -w
# AutoLoader.t runs before this test, so it seems safe to assume that it will
# work.
BEGIN {
chdir 't' if -d 't';
print "1..0 # This test is not 8.3-aware.\n";
exit 0;
}
} else {
}
}
use warnings;
use strict;
require AutoSplit; # Run time. Check it compiles.
END {
}
my @tests;
{
# local this else it buggers up the chomp() below.
# Hmm. Would be nice to have this as a regexp.
local $/
= "################################################################\n";
}
sub split_a_file {
my $contents = shift;
my $file = $_[0];
if (defined $contents) {
print FILE $contents;
}
# Assumption: no characters in arguments need escaping from the shell or perl
my $com = qq($runperl -e "use AutoSplit; autosplit (qw(@_))");
print "# command: $com\n";
# There may be a way to capture STDOUT without spawning a child process, but
# can load functions from split modules into this perl.
return $output;
}
my $i = 0;
$dir =~ s/\/$//;
$dir =~ s/:$//;
}
foreach (@tests) {
s/\*ENDPATHSEP\*/$endpathsep/gm;
s#//#/#gm;
# Build a hash for this test.
((?:[^\#]+ # Any number of characters not #
| \#(?!\#) # or a # character not followed by #
| (?<!\n)\# # or a # character not preceded by \n
}
} else {
# Repeat tests
}
$filespec = $1;
$replacement =~ s/\/$//;
$output =~ s/\Q$filespec\E/$replacement/;
}
}
# test n+1
next if /^#/;
$missing{$_}++;
}
}
# test n+2
print "# These files are missing\n";
}
# test n+3
print "# These files are unexpectedly present:\n";
}
}
eval $com;
# test n+3
}
}
# match tests to check for prototypes
local $/;
next if $pat =~ /^\#/;
}
}
# code tests contain eval{}ed ok()s etc
next if $code =~ /^\#/;
}
}
# We need to sleep for a while
# Need the sleep hack else the next test is so fast that the timestamp
# compare routine in AutoSplit thinks that it shouldn't split the files.
my $time = time;
my $attempts = 3;
do {
# Attempted to sleep for $sleepfor second(s), started at $time, now %d.
# sleep attempt ppears to have failed; some tests may fail as a result.
}
}
$i++;
}
}
## Name
## File
use AutoLoader 'AUTOLOAD';
use AutoLoader 'AUTOLOAD';
}
1;
# And that was all it has. You were expected to manually inspect the output
## Get
## Files
## Require
## Match
# Need to find these lines somewhere in the required file
sub test1\s*\(\$\);
sub test2\s*\(\$\$\);
sub test3\s*\(\$\$\$\);
sub testtesttesttest4_1\s*\(\$\);
sub testtesttesttest4_2\s*\(\$\$\);
## Tests
ok (!defined eval "*MOD*::test1 () eq 'test 1'" and $@ =~ /^Not enough arguments for *MOD*::test1/, "Check prototypes mismatch fails") or print "# \$\@='$@'";
# very messy way to interpolate function into regexp, but it's going to be
# needed to get : for Mac filespecs
like (&*MOD*::test6, qr!^\Q*INC**PATHSEP**MOD*\E\.pm \(autosplit into \Q@{[File::Spec->catfile('*DIR*','*MOD*', 'test6.al')]}\E\):\d+$!);
################################################################
## Name
missing use AutoLoader;
## File
1;
## Get
## Files
# There should be no files.
################################################################
## Name
## Extra
0, 0
## File
1;
__END__
## Get
AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
## Require
*MOD*/autosplit.ix
## Files
*DIR*/*MOD*/autosplit.ix
################################################################
## Name
Split prior to checking whether obsolete files get deleted
## File
1;
__END__
sub obsolete {our $hidden_a; return $hidden_a++;}
sub gonner {warn "This gonner function should never get called"}
## Get
AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
## Require
*MOD*/autosplit.ix
## Files
*DIR*/*MOD*/autosplit.ix
*DIR*/*MOD*/gonner.al
*DIR*/*MOD*/obsolete.al
## Tests
is (&*MOD*::obsolete, 0);
is (&*MOD*::obsolete, 1);
## Sleep
4
## SameAgain
################################################################
## Name
## File
1;
## Get
AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
## Require
## Files
*DIR*/*MOD*/autosplit.ix
*DIR*/*MOD*/skeleton.al
*DIR*/*MOD*/flying_pig.al
## Tests
eval {&*MOD*::gonner}; ok ($@ =~ m!^Can't locate auto/*MOD*/gonner.al in \@INC!, "Check &*MOD*::gonner is now a gonner") or print "# \$\@='$@'\n";
## Sleep
4
## SameAgain
################################################################
## Name
## Extra
1, 1
## File
1;
sub wraith {9};
## Get
AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
## Require
## Files
*DIR*/*MOD*/autosplit.ix
*DIR*/*MOD*/skeleton.al
*DIR*/*MOD*/flying_pig.al
## Tests
## Sleep
4
## SameAgain
################################################################
## Name
Without the timestamp check make sure that nothing happens
## Extra
0, 1, 1
## Require
*MOD*/autosplit.ix
## Files
*DIR*/*MOD*/autosplit.ix
*DIR*/*MOD*/skeleton.al
*DIR*/*MOD*/zombie.al
*DIR*/*MOD*/ghost.al
*DIR*/*MOD*/ghoul.al
*DIR*/*MOD*/wraith.al
*DIR*/*MOD*/flying_pig.al
## Tests
is (&*MOD*::ghoul, "wail", "still haunted");
## Sleep
4
## SameAgain
True, so don't scrub this directory.
################################################################
## Name
With the timestamp check make sure that things happen (stuff gets deleted)
## Extra
0, 1, 0
## Get
AutoSplitting *INC**PATHSEP**MOD*.pm (*DIR**PATHSEP**MOD**ENDPATHSEP*)
## Require
*MOD*/autosplit.ix
## Files
*DIR*/*MOD*/autosplit.ix
*DIR*/*MOD*/ghost.al
*DIR*/*MOD*/wraith.al
## Tests
is (&*MOD*::wraith, 9);
eval {&*MOD*::flying_pig}; ok ($@ =~ m!^Can't locate auto/*MOD*/flying_pig.al in \@INC!, "There are no flying pigs") or print "# \$\@='$@'\n";