From: Brandon L Black Date: Fri, 11 May 2007 16:30:52 +0000 (+0000) Subject: more tests X-Git-Tag: 0.02~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMRO-Compat.git;a=commitdiff_plain;h=763002b367ca10e928cb5fcd7e1f83f957b37cd8 more tests --- diff --git a/lib/MRO/Compat.pm b/lib/MRO/Compat.pm index 496dba0..2ae0a45 100644 --- a/lib/MRO/Compat.pm +++ b/lib/MRO/Compat.pm @@ -3,6 +3,8 @@ use strict; use warnings; require 5.006_000; +# Keep this < 1.00, so people can tell the fake +# mro.pm from the real one our $VERSION = '0.01'; BEGIN { @@ -20,6 +22,8 @@ BEGIN { *mro::method_changed_in = \&__method_changed_in; *mro::invalidate_all_method_caches = \&__invalidate_all_method_caches; + $mro::VERSION = $VERSION; + $INC{'mro.pm'} = 'Faked by MRO::Compat'; } # Provide no-op Class::C3::.*initialize() funcs for 5.9.5+ @@ -155,8 +159,7 @@ sub __set_mro { die q{Invalid mro type "$type"}; } - # In the dfs case, check whether we need to - # undo C3 + # In the dfs case, check whether we need to undo C3 if(defined $Class::C3::MRO{$classname}) { Class::C3::_remove_method_dispatch_table($classname); } diff --git a/t/20mros.t b/t/20mros.t new file mode 100644 index 0000000..702b19d --- /dev/null +++ b/t/20mros.t @@ -0,0 +1,62 @@ + +use strict; +use warnings; + +use Test::More tests => 8; + +BEGIN { + use_ok('MRO::Compat'); +} + +{ + package AAA; our @ISA = qw//; use mro 'dfs'; + package BBB; our @ISA = qw/AAA/; use mro 'dfs'; + package CCC; our @ISA = qw/AAA/; use mro 'dfs'; + package DDD; our @ISA = qw/AAA/; use mro 'dfs'; + package EEE; our @ISA = qw/BBB CCC DDD/; use mro 'dfs'; + package FFF; our @ISA = qw/EEE DDD/; use mro 'dfs'; + package GGG; our @ISA = qw/FFF/; use mro 'dfs'; + + package AAA3; our @ISA = qw//; + sub testsub { return $_[0] . '_first_in_dfs' } + package BBB3; our @ISA = qw/AAA3/; + package CCC3; our @ISA = qw/AAA3/; + sub testsub { return $_[0] . '_first_in_c3' } + package DDD3; our @ISA = qw/AAA3/; + package EEE3; our @ISA = qw/BBB3 CCC3 DDD3/; + package FFF3; our @ISA = qw/EEE3 DDD3/; use mro 'c3'; + package GGG3; our @ISA = qw/FFF3/; use mro 'c3'; +} + +is_deeply( + mro::get_linear_isa('GGG'), + [ 'GGG', 'FFF', 'EEE', 'BBB', 'AAA', 'CCC', 'DDD' ], + "get_linear_isa for GGG", +); + +is_deeply( + mro::get_linear_isa('GGG3'), + [ 'GGG3', 'FFF3', 'EEE3', 'BBB3', 'CCC3', 'DDD3', 'AAA3' ], + "get_linear_isa for GGG3", +); + +is(FFF3->testsub(), 'FFF3_first_in_dfs', 'dfs resolution pre-init'); + +Class::C3::initialize(); + +is(FFF3->testsub(), 'FFF3_first_in_c3', 'c3 resolution post-init'); + +mro::set_mro('FFF3', 'dfs'); +is_deeply( + mro::get_linear_isa('FFF3'), + [ 'FFF3', 'EEE3', 'BBB3', 'AAA3', 'CCC3', 'DDD3' ], + "get_linear_isa for FFF3 (dfs)", +); + +is(FFF3->testsub(), 'FFF3_first_in_dfs', 'dfs resolution post- setmro dfs'); + +is_deeply( + mro::get_linear_isa('GGG3'), + [ 'GGG3', 'FFF3', 'EEE3', 'BBB3', 'CCC3', 'DDD3', 'AAA3' ], + "get_linear_isa for GGG3 (still c3)", +);