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);
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" );
76 Exporter::export_ok_tags;
78 my %tags = map { $_ => 1 } map { @$_ } values %EXPORT_TAGS;
79 my %exportok = map { $_ => 1 } @EXPORT_OK;
81 foreach my $tag (keys %tags) {
82 $ok = exists $exportok{$tag};
84 ::ok( $ok, 'export_ok_tags()' );
90 ::ok( defined &lifejacket, 'simple import' );
94 my @imports = qw($seatbelt &Above stuff @wailing %left);
95 Testing->import(@imports);
97 ::ok( (!grep { eval "!defined $_" } map({ /^\w/ ? "&$_" : $_ } @imports)),
98 'import by symbols' );
102 my @tags = qw(:This :tray);
103 Testing->import(@tags);
105 ::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ }
106 map { @$_ } @{$Testing::EXPORT_TAGS{@tags}}),
111 Testing->import(qw(!lifejacket));
113 ::ok( !defined &lifejacket, 'deny import by !' );
117 Testing->import('/e/');
119 ::ok( (!grep { eval "!defined $_" } map { /^\w/ ? "&$_" : $_ }
120 grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK),
125 Testing->import('!/e/');
127 ::ok( (!grep { eval "defined $_" } map { /^\w/ ? "&$_" : $_ }
128 grep { /e/ } @Testing::EXPORT, @Testing::EXPORT_OK),
129 'deny import by regex');
130 ::ok( !defined &lifejacket, 'further denial' );
133 package More::Testing;
136 eval { More::Testing->require_version(0); 1 };
137 ::ok(!$@, 'require_version(0) and $VERSION = 0');
140 package Yet::More::Testing;
143 eval { Yet::More::Testing->require_version(10); 1 };
144 ::ok($@ !~ /\(undef\)/, 'require_version(10) and $VERSION = 0');
149 $SIG{__WARN__} = sub { $warnings = join '', @_ };
150 package Testing::Unused::Vars;
152 @EXPORT = qw(this $TODO that);
155 Testing::Unused::Vars->import;
158 ::ok( !$warnings, 'Unused variables can be exported without warning' ) ||
159 print "# $warnings\n";