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 { eval "!defined $_" } map({ /^\w/ ? "&$_" : $_ } @imports)),
123 'import by symbols' );
127 my @tags = qw(:This :tray);
128 Testing->import(@tags);
130 ::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ }
131 map { @$_ } @{$Testing::EXPORT_TAGS{@tags}}),
136 Testing->import(qw(!lifejacket));
138 ::ok( !defined &lifejacket, 'deny import by !' );
142 Testing->import('/e/');
144 ::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ }
145 grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK),
150 Testing->import('!/e/');
152 ::ok( (!grep { eval "defined $_" } map { /^\w/ ? "&$_" : $_ }
153 grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK),
154 'deny import by regex');
155 ::ok( !defined &lifejacket, 'further denial' );
158 package More::Testing;
161 eval { More::Testing->require_version(0); 1 };
162 ::ok(!$@, 'require_version(0) and $VERSION = 0');
165 package Yet::More::Testing;
168 eval { Yet::More::Testing->require_version(10); 1 };
169 ::ok($@ !~ /\(undef\)/, 'require_version(10) and $VERSION = 0');
174 local $SIG{__WARN__} = sub { $warnings = join '', @_ };
175 package Testing::Unused::Vars;
177 @EXPORT = qw(this $TODO that);
180 Testing::Unused::Vars->import;
183 ::ok( !$warnings, 'Unused variables can be exported without warning' ) ||
184 print "# $warnings\n";
186 package Moving::Target;
188 @EXPORT_OK = qw (foo);
190 sub foo {"This is foo"};
191 sub bar {"This is bar"};
193 package Moving::Target::Test;
195 Moving::Target->import ('foo');
197 ::ok (foo() eq "This is foo", "imported foo before EXPORT_OK changed");
199 push @Moving::Target::EXPORT_OK, 'bar';
201 Moving::Target->import ('bar');
203 ::ok (bar() eq "This is bar", "imported bar after EXPORT_OK changed");
207 use Exporter 'import';
209 ::ok(\&import == \&Exporter::import, "imported the import routine");
211 @EXPORT = qw( wibble );
212 sub wibble {return "wobble"};
214 package Use::The::Import;
218 my $val = eval { wibble() };
219 ::ok($val eq "wobble", "exported importer worked");