1#!/usr/bin/perl -w
2
3use strict;
4use warnings;
5
6use lib 't/lib';
7use Test::More;
8
9note "Basic use_ok"; {
10    package Foo::one;
11    ::use_ok("Symbol");
12    ::ok( defined &gensym,        'use_ok() no args exports defaults' );
13}
14
15
16note "With one arg"; {
17    package Foo::two;
18    ::use_ok("Symbol", qw(qualify));
19    ::ok( !defined &gensym,       '  one arg, defaults overridden' );
20    ::ok( defined &qualify,       '  right function exported' );
21}
22
23
24note "Multiple args"; {
25    package Foo::three;
26    ::use_ok("Symbol", qw(gensym ungensym));
27    ::ok( defined &gensym && defined &ungensym,   '  multiple args' );
28}
29
30
31note "Defining constants"; {
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}
38
39
40note "use Module VERSION"; {
41    package Foo::five;
42    ::use_ok("Symbol", 1.02);
43}
44
45
46note "use Module VERSION does not call import"; {
47    package Foo::six;
48    ::use_ok("NoExporter", 1.02);
49}
50
51
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}
60
61
62note "Signals are preserved"; {
63    package Foo::eight;
64    local $SIG{__DIE__};
65    ::use_ok("SigDie");
66    ::ok(defined $SIG{__DIE__}, '  SIG{__DIE__} preserved');
67}
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;
104