8 # Can't use Test::Simple/More, they depend on Exporter.
13 # You have to do it this way or VMS will get confused.
14 printf "%sok %d%s\n", ($ok ? '' : 'not '), $test,
15 (defined $name ? " - $name" : '');
17 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
26 ok( 1, 'Exporter compiled' );
30 # Methods which Exporter says it implements.
31 @Exporter_Methods = qw(import
43 # Make sure Testing can do everything its supposed to.
44 foreach my $meth (@::Exporter_Methods) {
45 ::ok( Testing->can($meth), "subclass can $meth()" );
49 This => [qw(stuff %left)],
50 That => [qw(Above the @wailing)],
51 tray => [qw(Fasten $seatbelt)],
53 @EXPORT = qw(lifejacket is);
54 @EXPORT_OK = qw(under &your $seat);
57 ::ok( Testing->require_version(1.05), 'require_version()' );
58 eval { Testing->require_version(1.11); 1 };
59 ::ok( $@, 'require_version() fail' );
60 ::ok( Testing->require_version(0), 'require_version(0)' );
62 sub lifejacket { 'lifejacket' }
66 sub Fasten { 'Fasten' }
69 use vars qw($seatbelt $seat @wailing %left);
70 $seatbelt = 'seatbelt';
72 @wailing = qw(AHHHHHH);
73 %left = ( left => "right" );
78 Exporter::export_ok_tags();
80 my %tags = map { $_ => 1 } map { @$_ } values %EXPORT_TAGS;
81 my %exportok = map { $_ => 1 } @EXPORT_OK;
83 foreach my $tag (keys %tags) {
84 $ok = exists $exportok{$tag};
86 ::ok( $ok, 'export_ok_tags()' );
92 ::ok( defined &lifejacket, 'simple import' );
94 my $got = eval {&lifejacket};
95 ::ok ( $@ eq "", 'check we can call the imported subroutine')
96 or print STDERR "# \$\@ is $@\n";
97 ::ok ( $got eq 'lifejacket', 'and that it gave the correct result')
98 or print STDERR "# expected 'lifejacket', got " .
99 (defined $got ? "'$got'" : "undef") . "\n";
101 # The string eval is important. It stops $Foo::{is} existing when
102 # Testing->import is called.
103 ::ok( eval "defined &is",
104 "Import a subroutine where exporter must create the typeglob" );
105 my $got = eval "&is";
106 ::ok ( $@ eq "", 'check we can call the imported autoloaded subroutine')
107 or chomp ($@), print STDERR "# \$\@ is $@\n";
108 ::ok ( $got eq 'Is', 'and that it gave the correct result')
109 or print STDERR "# expected 'Is', got " .
110 (defined $got ? "'$got'" : "undef") . "\n";
114 my @imports = qw($seatbelt &Above stuff @wailing %left);
115 Testing->import(@imports);
117 ::ok( (!grep { eval "!defined $_" } map({ /^\w/ ? "&$_" : $_ } @imports)),
118 'import by symbols' );
122 my @tags = qw(:This :tray);
123 Testing->import(@tags);
125 ::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ }
126 map { @$_ } @{$Testing::EXPORT_TAGS{@tags}}),
131 Testing->import(qw(!lifejacket));
133 ::ok( !defined &lifejacket, 'deny import by !' );
137 Testing->import('/e/');
139 ::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ }
140 grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK),
145 Testing->import('!/e/');
147 ::ok( (!grep { eval "defined $_" } map { /^\w/ ? "&$_" : $_ }
148 grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK),
149 'deny import by regex');
150 ::ok( !defined &lifejacket, 'further denial' );
153 package More::Testing;
156 eval { More::Testing->require_version(0); 1 };
157 ::ok(!$@, 'require_version(0) and $VERSION = 0');
160 package Yet::More::Testing;
163 eval { Yet::More::Testing->require_version(10); 1 };
164 ::ok($@ !~ /\(undef\)/, 'require_version(10) and $VERSION = 0');
169 $SIG{__WARN__} = sub { $warnings = join '', @_ };
170 package Testing::Unused::Vars;
172 @EXPORT = qw(this $TODO that);
175 Testing::Unused::Vars->import;
178 ::ok( !$warnings, 'Unused variables can be exported without warning' ) ||
179 print "# $warnings\n";
181 package Moving::Target;
183 @EXPORT_OK = qw (foo);
188 package Moving::Target::Test;
190 Moving::Target->import (foo);
192 ::ok (foo eq "foo", "imported foo before EXPORT_OK changed");
194 push @Moving::Target::EXPORT_OK, 'bar';
196 Moving::Target->import (bar);
198 ::ok (bar eq "bar", "imported bar after EXPORT_OK changed");
202 use Exporter 'import';
205 ::ok(\&import == \&Exporter::import, "imported the import routine");
207 @EXPORT = qw( wibble );
208 sub wibble {return "wobble"};
210 package Use::The::Import;
214 my $val = eval { wibble() };
215 ::ok($val eq "wobble", "exported importer worked");