#!/usr/bin/perl -w
note
"Basic use_ok"
; {
::use_ok(
"Symbol"
);
::ok(
defined
&gensym
,
'use_ok() no args exports defaults'
);
}
note
"With one arg"
; {
::use_ok(
"Symbol"
,
qw(qualify)
);
::ok( !
defined
&gensym
,
' one arg, defaults overridden'
);
::ok(
defined
&qualify
,
' right function exported'
);
}
note
"Multiple args"
; {
::use_ok(
"Symbol"
,
qw(gensym ungensym)
);
::ok(
defined
&gensym
&&
defined
&ungensym
,
' multiple args'
);
}
note
"Defining constants"
; {
my
$warn
;
local
$SIG
{__WARN__} =
sub
{
$warn
.=
shift
; };
::use_ok(
"constant"
,
qw(foo bar)
);
::ok(
defined
&foo
,
'constant'
);
::is(
$warn
,
undef
,
'no warning'
);
}
note
"use Module VERSION"
; {
::use_ok(
"Symbol"
, 1.02);
}
note
"use Module VERSION does not call import"
; {
::use_ok(
"NoExporter"
, 1.02);
}
{
local
$SIG
{__WARN__} =
sub
{
warn
@_
unless
$_
[0] =~ /^Argument
"\d+\.\d+_\d+"
isn't numeric/;
};
::use_ok(
"Test::More"
, 0.47);
}
note
"Signals are preserved"
; {
local
$SIG
{__DIE__};
::use_ok(
"SigDie"
);
::ok(
defined
$SIG
{__DIE__},
' SIG{__DIE__} preserved'
);
}
note
"Line numbers preserved"
; {
my
$package
=
"that_cares_about_line_numbers"
;
my
@caller
;
{
sub
import
{
@caller
=
caller
;
return
;
}
$INC
{
"$package.pm"
} = 1;
}
::use_ok(
$package
);
my
$line
= __LINE__-1;
::is(
$caller
[0], __PACKAGE__,
"caller package preserved"
);
::is(
$caller
[1], __FILE__,
" file"
);
::is(
$caller
[2],
$line
,
" line"
);
}
note
"not confused by functions vs class names"
; {
$INC
{
"ok.pm"
} = 1;
use_ok(
"ok"
);
$INC
{
"Foo/bar.pm"
} = 1;
sub
Foo::bar { 42 }
use_ok(
"Foo::bar"
);
}
done_testing;