Subject: | Patch: Error in test for Win32: prototype mismatch & unexpected warning |
Test::Output 0.09
perl v5.8.7 built for MSWin32-x86-multi-thread
Binary build 813
Reason of error is different slashes.
Pathed tests are attached.
t\install.........1..17
ok 1 - return value of first install_sub isa CODE
ok 2 - it returns the correct code ref
ok 3 - installed sub runs
# Failed test in t\install.t at line 32.
# STDERR is:
# Subroutine main::tmp_ok redefined at t\install.t line 31
# Prototype mismatch: sub main::tmp_ok ($;$) vs ($$;$) at t\install.t
line 31
#
# not:
# Subroutine main::tmp_ok redefined at t/install.t line 31
# Prototype mismatch: sub main::tmp_ok ($;$) vs ($$;$) at t/install.t
line 31
#
# as expected
unexpected warning: Subroutine main::ok1 redefined at t\install.t line 48
not ok 4
# Looks like you planned 17 tests but only ran 4.
# Looks like you failed 1 test of 4 run.
# Looks like your test died just after 4.
-------
Alexandr Ciornii, http://chorny.net
Subject: | reinstall.t |
use Sub::Install qw(reinstall_sub);
use Test::More tests => 15;
use strict;
use warnings;
# These tests largely copied from Damian Conway's Sub::Installer tests.
{ # Install a sub in a package...
my $sub_ref = reinstall_sub({ code => \&ok, as => 'ok1' });
isa_ok($sub_ref, 'CODE', 'return value of first install_sub');
is_deeply($sub_ref, \&Test::More::ok, 'it returned the right coderef');
$sub_ref->(1, 'returned code ref runs');
ok1(1, "reinstalled sub runs");
}
{
my $to_avail = eval "use Test::Output; 1";
SKIP: {
skip "can't run this test without Test::Output", 1 unless $to_avail;
Sub::Install::reinstall_sub({ code => \&ok, as => 'tmp_ok' });
my $expected_warning = <<'END_WARNING';
Prototype mismatch: sub main::tmp_ok ($;$) vs ($$;$) at t/reinstall.t line 33
END_WARNING
$expected_warning=~s#/#\\#g if $^O eq 'MSWin32';
stderr_is(
sub { Sub::Install::reinstall_sub({ code => \&is, as => 'tmp_ok' }) },
$expected_warning,
"correct warnings went out STDERR",
);
}
}
{ # Install the same sub in the same package...
my $proto = 0;
local $SIG{__WARN__} = sub {
return ($proto = 1) if $_[0] =~ m{Prototype mismatch.+t[/\\]reinstall.t};
die "unexpected warning: @_";
};
my $sub_ref = reinstall_sub({ code => \&is, as => 'ok1' });
ok($proto, 'correct warning went to $SIG{__WARN__}');
isa_ok($sub_ref, 'CODE', 'return value of second install_sub');
is_deeply($sub_ref, \&Test::More::is, 'it returned the right coderef');
$sub_ref->(1, 1, 'returned code ref runs');
ok1(1,1, 'reinstalled sub reruns');
}
{ # Install in another package...
my $new_code = sub { ok(1, "remotely installed sub runs") };
my $sub_ref = reinstall_sub({
code => $new_code,
into => 'Other',
as => 'ok1',
});
isa_ok($sub_ref, 'CODE', 'return value of third install_sub');
is_deeply($sub_ref, $new_code, 'it returned the right coderef');
ok1(1,1, 'reinstalled sub reruns');
package Other;
ok1();
}
eval {
my $arg = { code => sub {}, into => 'Other', as => 'ok1' };
Sub::Install::_build_public_installer(\&Sub::Install::_install_fatal)->($arg);
};
like($@, qr/redefine/, "(experimental fatal installer should croak)");
Subject: | install.t |
use Sub::Install;
use Test::More tests => 17;
use strict;
use warnings;
# These tests largely copied from Damian Conway's Sub::Installer tests.
{ # Install a sub in a package...
my $sub_ref = Sub::Install::install_sub({ code => \&ok, as => 'ok1' });
isa_ok($sub_ref, 'CODE', 'return value of first install_sub');
is_deeply($sub_ref, \&ok, 'it returns the correct code ref');
ok1(1, 'installed sub runs');
}
{
my $to_avail = eval "use Test::Output; 1";
SKIP: {
skip "can't run this test without Test::Output", 1 unless $to_avail;
Sub::Install::install_sub({ code => \&ok, as => 'tmp_ok' });
my $expected_warning = <<'END_WARNING';
Subroutine main::tmp_ok redefined at t/install.t line 32
Prototype mismatch: sub main::tmp_ok ($;$) vs ($$;$) at t/install.t line 32
END_WARNING
$expected_warning=~s#/#\\#g if $^O eq 'MSWin32';
stderr_is(
sub { Sub::Install::install_sub({ code => \&is, as => 'tmp_ok' }) },
$expected_warning,
);
}
}
{ # Install the same sub in the same package...
my $redef = 0;
my $proto = 0;
local $SIG{__WARN__} = sub {
return ($redef = 1) if $_[0] =~ m{Subroutine \S+ redef.+t[/\\]install.t};
return ($proto = 1) if $_[0] =~ m{Prototype mismatch.+t[/\\]install.t};
# pass("warned as expected: $_[0]") if $_[0] =~ /redefined/;
die "unexpected warning: @_";
};
my $sub_ref = Sub::Install::install_sub({ code => \&is, as => 'ok1' });
ok($redef, 'correct redefinition warning went to $SIG{__WARN__}');
ok($proto, 'correct prototype warning went to $SIG{__WARN__}');
isa_ok($sub_ref, 'CODE', 'return value of second install_sub');
is_deeply($sub_ref, \&is, 'install2 returns correct code ref');
ok1(1,1, 'installed sub runs (with new arguments)');
}
{ # Install in another package...
my $sub_ref = Sub::Install::install_sub({
code => \&ok,
into => 'Other',
as => 'ok1'
});
isa_ok($sub_ref, 'CODE', 'return value of third install_sub');
is_deeply($sub_ref, \&ok, 'it returns the correct code ref');
ok1(1,1, 'sub previously installed into main still runs properly');
package Other;
ok1(1, 'remotely installed sub runs properly');
}
{ # cross-package installation
sub Other::Another::foo { return $_[0] }
my $sub_ref = Sub::Install::install_sub({
code => 'foo',
from => 'Other::Another',
into => 'Other::YetAnother',
as => 'return_lhs'
});
isa_ok($sub_ref, 'CODE', 'return value of fourth install_sub');
is_deeply(
$sub_ref,
\&Other::Another::foo,
'it returns the correct code ref'
);
is(
Other::Another->foo,
'Other::Another',
'the original code does what we want',
);
is(
Other::YetAnother->return_lhs,
'Other::YetAnother',
'and the installed code works, too',
);
}