diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-06-18 04:17:15 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-06-18 04:17:15 +0000 |
commit | b695f709e8a342e35e482b0437eb6cdacdc58b6b (patch) | |
tree | 2d16192636e6ba806ff7a907f682c74f7705a920 /lib/Exporter.t | |
parent | d780cd7a0195e946e636d3ee546f6ef4f21d6acc (diff) | |
download | perl-b695f709e8a342e35e482b0437eb6cdacdc58b6b.tar.gz |
The Grand Trek: move the *.t files from t/ to lib/ and ext/.
No doubt I made some mistakes like missed some files or
misnamed some files. The naming rules were more or less:
(1) if the module is from CPAN, follows its ways, be it
t/*.t or test.pl.
(2) otherwise if there are multiple tests for a module
put them in a t/
(3) otherwise if there's only one test put it in Module.t
(4) helper files go to module/ (locale, strict, warnings)
(5) use longer filenames now that we can (but e.g. the
compat-0.6.t and the Text::Balanced test files still
were renamed to be more civil against the 8.3 people)
installperl was updated appropriately not to install the
*.t files or the help files from under lib.
TODO: some helper files still remain under t/ that could
follow their 'masters'. UPDATE: On second thoughts, why
should they. They can continue to live under t/lib, and
in fact the locale/strict/warnings helpers that were moved
could be moved back. This way the amount of non-installable
stuff under lib/ stays smaller.
p4raw-id: //depot/perl@10676
Diffstat (limited to 'lib/Exporter.t')
-rw-r--r-- | lib/Exporter.t | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/lib/Exporter.t b/lib/Exporter.t new file mode 100644 index 0000000000..a0028feb23 --- /dev/null +++ b/lib/Exporter.t @@ -0,0 +1,145 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +# Utility testing functions. +my $test_num = 1; +sub ok ($;$) { + my($test, $name) = @_; + print "not " unless $test; + print "ok $test_num"; + print " - $name" if (defined $name && ! $^O eq 'VMS'); + print "\n"; + $test_num++; +} + + +my $loaded; +BEGIN { $| = 1; $^W = 1; } +END {print "not ok $test_num\n" unless $loaded;} +print "1..$Total_tests\n"; +use Exporter; +$loaded = 1; +ok(1, 'compile'); + + +BEGIN { + # Methods which Exporter says it implements. + @Exporter_Methods = qw(import + export_to_level + require_version + export_fail + ); +} + +BEGIN { $Total_tests = 14 + @Exporter_Methods } + +package Testing; +require Exporter; +@ISA = qw(Exporter); + +# Make sure Testing can do everything its supposed to. +foreach my $meth (@::Exporter_Methods) { + ::ok( Testing->can($meth), "subclass can $meth()" ); +} + +%EXPORT_TAGS = ( + This => [qw(stuff %left)], + That => [qw(Above the @wailing)], + tray => [qw(Fasten $seatbelt)], + ); +@EXPORT = qw(lifejacket); +@EXPORT_OK = qw(under &your $seat); +$VERSION = '1.05'; + +::ok( Testing->require_version(1.05), 'require_version()' ); +eval { Testing->require_version(1.11); 1 }; +::ok( $@, 'require_version() fail' ); +::ok( Testing->require_version(0), 'require_version(0)' ); + +sub lifejacket { 'lifejacket' } +sub stuff { 'stuff' } +sub Above { 'Above' } +sub the { 'the' } +sub Fasten { 'Fasten' } +sub your { 'your' } +sub under { 'under' } +use vars qw($seatbelt $seat @wailing %left); +$seatbelt = 'seatbelt'; +$seat = 'seat'; +@wailing = qw(AHHHHHH); +%left = ( left => "right" ); + + +Exporter::export_ok_tags; + +my %tags = map { $_ => 1 } map { @$_ } values %EXPORT_TAGS; +my %exportok = map { $_ => 1 } @EXPORT_OK; +my $ok = 1; +foreach my $tag (keys %tags) { + $ok = exists $exportok{$tag}; +} +::ok( $ok, 'export_ok_tags()' ); + + +package Foo; +Testing->import; + +::ok( defined &lifejacket, 'simple import' ); + + +package Bar; +my @imports = qw($seatbelt &Above stuff @wailing %left); +Testing->import(@imports); + +::ok( (!grep { eval "!defined $_" } map({ /^\w/ ? "&$_" : $_ } @imports)), + 'import by symbols' ); + + +package Yar; +my @tags = qw(:This :tray); +Testing->import(@tags); + +::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ } + map { @$_ } @{$Testing::EXPORT_TAGS{@tags}}), + 'import by tags' ); + + +package Arrr; +Testing->import(qw(!lifejacket)); + +::ok( !defined &lifejacket, 'deny import by !' ); + + +package Mars; +Testing->import('/e/'); + +::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ } + grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK), + 'import by regex'); + + +package Venus; +Testing->import('!/e/'); + +::ok( (!grep { eval "defined $_" } map { /^\w/ ? "&$_" : $_ } + grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK), + 'deny import by regex'); +::ok( !defined &lifejacket, 'further denial' ); + + +package More::Testing; +@ISA = qw(Exporter); +$VERSION = 0; +eval { More::Testing->require_version(0); 1 }; +::ok(!$@, 'require_version(0) and $VERSION = 0'); + + +package Yet::More::Testing; +@ISA = qw(Exporter); +$VERSION = 0; +eval { Yet::More::Testing->require_version(10); 1 }; +::ok($@ !~ /\(undef\)/, 'require_version(10) and $VERSION = 0'); |