summaryrefslogtreecommitdiff
path: root/t/SI_reinstall.t
blob: 887e077ef82c1dc0bc658e369e508b4560b471c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use Sub::Install;
Sub::Install::install_installers('UNIVERSAL');

# This test, from here on out, is the verbatim "reinstall.t" test from
# Sub::Installer 0.0.2

use Test::More 'no_plan';
use Scalar::Util qw/reftype/;
use warnings;

# Install a sub in a package...

my $sub_ref = main->reinstall_sub({ ok1 => \&ok });

is reftype $sub_ref, 'CODE'                  => 'reinstall returns code ref';

is_deeply \&ok, $sub_ref                 => 'reinstall returns correct code ref';

ok1(1                                    => 'reinstalled sub runs');


# Install the same sub in the same package...

$SIG{__WARN__} = sub { ok 0 => "warned unexpected: @_" if $_[0] =~ /redefined/ };

$sub_ref = main->reinstall_sub({ ok1 => \&is });

is reftype $sub_ref, 'CODE'                  => 'reinstall2 returns code ref';

is_deeply \&is, $sub_ref                 => 'reinstall2 returns correct code ref';

ok1(1,1                                  => 'reinstalled sub reruns');

# Install in another package...

$sub_ref = Other->reinstall_sub({ ok2 => \&ok });

is reftype $sub_ref, 'CODE'                  => 'reinstall2 returns code ref';

is_deeply \&ok, $sub_ref                 => 'reinstall2 returns correct code ref';

ok1(1,1                                  => 'reinstalled sub reruns');

package Other;

ok2(1                                    => 'remotely reinstalled sub runs');