This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update to the latest Test-Simple cpan dist
[perl5.git] / cpan / Test-Simple / t / Legacy / use_ok.t
CommitLineData
89c1e84a
MS
1#!/usr/bin/perl -w
2
411e93ce
SH
3use strict;
4use warnings;
33459055 5
411e93ce
SH
6use lib 't/lib';
7use Test::More;
33459055 8
411e93ce 9note "Basic use_ok"; {
33459055
MS
10 package Foo::one;
11 ::use_ok("Symbol");
12 ::ok( defined &gensym, 'use_ok() no args exports defaults' );
13}
14
411e93ce
SH
15
16note "With one arg"; {
33459055
MS
17 package Foo::two;
18 ::use_ok("Symbol", qw(qualify));
809046db 19 ::ok( !defined &gensym, ' one arg, defaults overridden' );
33459055
MS
20 ::ok( defined &qualify, ' right function exported' );
21}
22
411e93ce
SH
23
24note "Multiple args"; {
33459055
MS
25 package Foo::three;
26 ::use_ok("Symbol", qw(gensym ungensym));
27 ::ok( defined &gensym && defined &ungensym, ' multiple args' );
28}
89c1e84a 29
411e93ce
SH
30
31note "Defining constants"; {
89c1e84a
MS
32 package Foo::four;
33 my $warn; local $SIG{__WARN__} = sub { $warn .= shift; };
34 ::use_ok("constant", qw(foo bar));
35 ::ok( defined &foo, 'constant' );
36 ::is( $warn, undef, 'no warning');
37}
30e302f8 38
411e93ce
SH
39
40note "use Module VERSION"; {
30e302f8
NC
41 package Foo::five;
42 ::use_ok("Symbol", 1.02);
43}
44
411e93ce
SH
45
46note "use Module VERSION does not call import"; {
30e302f8
NC
47 package Foo::six;
48 ::use_ok("NoExporter", 1.02);
49}
50
411e93ce 51
30e302f8
NC
52{
53 package Foo::seven;
54 local $SIG{__WARN__} = sub {
55 # Old perls will warn on X.YY_ZZ style versions. Not our problem
56 warn @_ unless $_[0] =~ /^Argument "\d+\.\d+_\d+" isn't numeric/;
57 };
58 ::use_ok("Test::More", 0.47);
59}
ccbd73a4 60
411e93ce
SH
61
62note "Signals are preserved"; {
ccbd73a4
SP
63 package Foo::eight;
64 local $SIG{__DIE__};
65 ::use_ok("SigDie");
66 ::ok(defined $SIG{__DIE__}, ' SIG{__DIE__} preserved');
67}
411e93ce
SH
68
69
70note "Line numbers preserved"; {
71 my $package = "that_cares_about_line_numbers";
72
73 # Store the output of caller.
74 my @caller;
75 {
76 package that_cares_about_line_numbers;
77
78 sub import {
79 @caller = caller;
80 return;
81 }
82
83 $INC{"$package.pm"} = 1; # fool use into thinking it's already loaded
84 }
85
86 ::use_ok($package);
87 my $line = __LINE__-1;
88 ::is( $caller[0], __PACKAGE__, "caller package preserved" );
89 ::is( $caller[1], __FILE__, " file" );
90 ::is( $caller[2], $line, " line" );
91}
92
93
94note "not confused by functions vs class names"; {
95 $INC{"ok.pm"} = 1;
96 use_ok("ok"); # ok is a function inside Test::More
97
98 $INC{"Foo/bar.pm"} = 1;
99 sub Foo::bar { 42 }
100 use_ok("Foo::bar"); # Confusing a class name with a function name
101}
102
103done_testing;