4 if( $ENV{PERL_CORE} ) {
10 # Can't use Test::Simple/More, they depend on Exporter.
15 # You have to do it this way or VMS will get confused.
16 printf "%sok %d%s\n", ($ok ? '' : 'not '), $test,
17 (defined $name ? " - $name" : '');
19 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
30 ok( 1, 'Exporter compiled' );
35 # Methods which Exporter says it implements.
36 @Exporter_Methods = qw(import
48 # Make sure Testing can do everything its supposed to.
49 foreach my $meth (@::Exporter_Methods) {
50 ::ok( Testing->can($meth), "subclass can $meth()" );
54 This => [qw(stuff %left)],
55 That => [qw(Above the @wailing)],
56 tray => [qw(Fasten $seatbelt)],
58 @EXPORT = qw(lifejacket is);
59 @EXPORT_OK = qw(under &your $seat);
62 ::ok( Testing->require_version(1.05), 'require_version()' );
63 eval { Testing->require_version(1.11); 1 };
64 ::ok( $@, 'require_version() fail' );
65 ::ok( Testing->require_version(0), 'require_version(0)' );
67 sub lifejacket { 'lifejacket' }
71 sub Fasten { 'Fasten' }
74 use vars qw($seatbelt $seat @wailing %left);
75 $seatbelt = 'seatbelt';
77 @wailing = qw(AHHHHHH);
78 %left = ( left => "right" );
83 Exporter::export_ok_tags();
85 my %tags = map { $_ => 1 } map { @$_ } values %EXPORT_TAGS;
86 my %exportok = map { $_ => 1 } @EXPORT_OK;
88 foreach my $tag (keys %tags) {
89 $ok = exists $exportok{$tag};
91 ::ok( $ok, 'export_ok_tags()' );
97 ::ok( defined &lifejacket, 'simple import' );
99 my $got = eval {&lifejacket};
100 ::ok ( $@ eq "", 'check we can call the imported subroutine')
101 or print STDERR "# \$\@ is $@\n";
102 ::ok ( $got eq 'lifejacket', 'and that it gave the correct result')
103 or print STDERR "# expected 'lifejacket', got " .
104 (defined $got ? "'$got'" : "undef") . "\n";
106 # The string eval is important. It stops $Foo::{is} existing when
107 # Testing->import is called.
108 ::ok( eval "defined &is",
109 "Import a subroutine where exporter must create the typeglob" );
111 ::ok ( $@ eq "", 'check we can call the imported autoloaded subroutine')
112 or chomp ($@), print STDERR "# \$\@ is $@\n";
113 ::ok ( $got eq 'Is', 'and that it gave the correct result')
114 or print STDERR "# expected 'Is', got " .
115 (defined $got ? "'$got'" : "undef") . "\n";
119 my @imports = qw($seatbelt &Above stuff @wailing %left);
120 Testing->import(@imports);
122 ::ok( (! grep { my ($s, $n) = @$_; eval "\\$s$n != \\${s}Testing::$n" }
123 map { /^(\W)(\w+)/ ? [$1, $2] : ['&', $_] }
125 'import by symbols' );
129 my @tags = qw(:This :tray);
130 Testing->import(@tags);
132 ::ok( (! grep { my ($s, $n) = @$_; eval "\\$s$n != \\${s}Testing::$n" }
133 map { /^(\W)(\w+)/ ? [$1, $2] : ['&', $_] }
135 @{$Testing::EXPORT_TAGS{@tags}}),
140 Testing->import(qw(!lifejacket));
142 ::ok( !defined &lifejacket, 'deny import by !' );
146 Testing->import('/e/');
148 ::ok( (! grep { my ($s, $n) = @$_; eval "\\$s$n != \\${s}Testing::$n" }
149 map { /^(\W)(\w+)/ ? [$1, $2] : ['&', $_] }
151 @Testing::EXPORT, @Testing::EXPORT_OK),
156 Testing->import('!/e/');
158 ::ok( (! grep { my ($s, $n) = @$_; eval "\\$s$n == \\${s}Testing::$n" }
159 map { /^(\W)(\w+)/ ? [$1, $2] : ['&', $_] }
161 @Testing::EXPORT, @Testing::EXPORT_OK),
162 'deny import by regex');
164 ::ok( !defined &lifejacket, 'further denial' );
167 package More::Testing;
170 eval { More::Testing->require_version(0); 1 };
171 ::ok(!$@, 'require_version(0) and $VERSION = 0');
174 package Yet::More::Testing;
177 eval { Yet::More::Testing->require_version(10); 1 };
178 ::ok($@ !~ /\(undef\)/, 'require_version(10) and $VERSION = 0');
183 local $SIG{__WARN__} = sub { $warnings = join '', @_ };
184 package Testing::Unused::Vars;
186 @EXPORT = qw(this $TODO that);
189 Testing::Unused::Vars->import;
192 ::ok( !$warnings, 'Unused variables can be exported without warning' ) ||
193 print "# $warnings\n";
195 package Moving::Target;
197 @EXPORT_OK = qw (foo);
199 sub foo {"This is foo"};
200 sub bar {"This is bar"};
202 package Moving::Target::Test;
204 Moving::Target->import ('foo');
206 ::ok (foo() eq "This is foo", "imported foo before EXPORT_OK changed");
208 push @Moving::Target::EXPORT_OK, 'bar';
210 Moving::Target->import ('bar');
212 ::ok (bar() eq "This is bar", "imported bar after EXPORT_OK changed");
216 use Exporter 'import';
218 ::ok(\&import == \&Exporter::import, "imported the import routine");
220 @EXPORT = qw( wibble );
221 sub wibble {return "wobble"};
223 package Use::The::Import;
227 my $val = eval { wibble() };
228 ::ok($val eq "wobble", "exported importer worked");
230 # Check that Carp recognizes Exporter as internal to Perl
232 eval { Carp::croak() };
233 ::ok($Carp::Internal{Exporter}, "Carp recognizes Exporter");
234 ::ok($Carp::Internal{'Exporter::Heavy'}, "Carp recognizes Exporter::Heavy");