remove extraneous garbage from tests
[gitmo/Class-C3.git] / t / 22_uninitialize.t
CommitLineData
5dd9299c 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
ef29cd70 6use Test::More tests => 11;
5dd9299c 7
8=pod
9
10 <A>
11 / \
12<B> <C>
13 \ /
14 <D>
15
16=cut
17
18{
19 package Diamond_A;
20 use Class::C3;
21 sub hello { 'Diamond_A::hello' }
22}
23{
24 package Diamond_B;
25 use base 'Diamond_A';
26 use Class::C3;
27}
28{
29 package Diamond_C;
30 use Class::C3;
31 use base 'Diamond_A';
32 sub goodbye { 'Diamond_C::goodbye' }
33 sub hello { 'Diamond_C::hello' }
34}
35{
36 package Diamond_D;
37 use base ('Diamond_B', 'Diamond_C');
38 use Class::C3;
39
40 our @hello = qw(h e l l o);
41 our $hello = 'hello';
42 our %hello = (h => 1, e => 2, l => "3 & 4", o => 5)
43}
44
2ffffc6d 45Class::C3::initialize();
46
5dd9299c 47is(Diamond_D->hello, 'Diamond_C::hello', '... method resolves with the correct MRO');
48is(Diamond_D->goodbye, 'Diamond_C::goodbye', '... method resolves with the correct MRO');
49
50{
51 no warnings 'redefine';
52 no strict 'refs';
53 *{"Diamond_D::goodbye"} = sub { 'Diamond_D::goodbye' };
54}
55
56is(Diamond_D->goodbye, 'Diamond_D::goodbye', '... method overwritten');
57
58is($Diamond_D::hello, 'hello', '... our SCALAR package vars are here');
59is_deeply(
60 \@Diamond_D::hello,
61 [ qw(h e l l o) ],
62 '... our ARRAY package vars are here');
63is_deeply(
64 \%Diamond_D::hello,
65 { h => 1, e => 2, l => "3 & 4", o => 5 },
66 '... our HASH package vars are here');
67
68Class::C3::uninitialize();
69
70is(Diamond_D->hello, 'Diamond_A::hello', '... method resolves with reinitialized MRO');
71is(Diamond_D->goodbye, 'Diamond_D::goodbye', '... uninitialize does not mess with the manually changed method');
72
73is($Diamond_D::hello, 'hello', '... our SCALAR package vars are still here');
74is_deeply(
75 \@Diamond_D::hello,
76 [ qw(h e l l o) ],
77 '... our ARRAY package vars are still here');
78is_deeply(
79 \%Diamond_D::hello,
80 { h => 1, e => 2, l => "3 & 4", o => 5 },
81 '... our HASH package vars are still here');
82