-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undef tests and docs for undef/non-numeric arg handling #54
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ use warnings; | |
use Scalar::Util (); | ||
use Test::More (grep { /dualvar/ } @Scalar::Util::EXPORT_FAIL) | ||
? (skip_all => 'dualvar requires XS version') | ||
: (tests => 41); | ||
: (tests => 55); | ||
use Config; | ||
|
||
Scalar::Util->import('dualvar'); | ||
|
@@ -131,3 +131,28 @@ SKIP: { | |
ok(isdual($ary[2]), 'Is a dualvar'); | ||
} | ||
|
||
ok !eval { dualvar() }, "arg count gets checked"; | ||
ok !eval { dualvar(2, "a", "meep") }, "arg count gets checked"; | ||
|
||
{ | ||
my $warning; | ||
local $SIG{__WARN__} = sub { $warning = shift }; | ||
|
||
my $var = dualvar(undef, undef); | ||
like($warning, qr/Use of uninitialized value in subroutine entry/, 'undef arg warning'); | ||
ok( isdual($var), 'Is a dualvar'); | ||
ok( $var == undef, 'Numeric value'); | ||
ok( $var eq undef, 'String value'); | ||
|
||
my $var2 = dualvar(2.2, undef); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to
just before each additional test block to ensure that it's not just remaining from the previous |
||
like($warning, qr/Use of uninitialized value in subroutine entry/, 'undef arg warning'); | ||
ok( isdual($var2), 'Is a dualvar'); | ||
ok( $var2 == 2.2, 'Numeric value'); | ||
ok( $var2 eq undef, 'String value'); | ||
|
||
my $var3 = dualvar(undef, "string"); | ||
like($warning, qr/Use of uninitialized value in subroutine entry/, 'undef arg warning'); | ||
ok( isdual($var3), 'Is a dualvar'); | ||
ok( $var3 == undef, 'Numeric value'); | ||
ok( $var3 eq "string", 'String value'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use strict; | |
use warnings; | ||
|
||
use Sub::Util qw( prototype set_prototype ); | ||
use Test::More tests => 13; | ||
use Test::More tests => 17; | ||
|
||
sub f { } | ||
is( prototype('f'), undef, 'no prototype'); | ||
|
@@ -38,3 +38,16 @@ is( prototype('f_decl'), '$$$$', 'forward declaration'); | |
|
||
set_prototype('\%', \&f_decl); | ||
is( prototype('f_decl'), '\%', 'change forward declaration'); | ||
|
||
{ | ||
my $warning; | ||
local $SIG{__WARN__} = sub { $warning = shift }; | ||
|
||
my @c = prototype(); | ||
is( scalar @c, 0, 'no arg results in empty list'); # XXX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent whitespacing - probably wants to be
|
||
like($warning, qr/Use of uninitialized value in subroutine prototype/, 'no arg results in undef arg warning'); | ||
undef $warning; | ||
|
||
is( prototype(undef), undef, 'undef arg'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
like($warning, qr/Use of uninitialized value in subroutine prototype/, 'undef arg warning'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these warnings localised to different languages? Or am I being confused about
$!
?