From 754c00caaffe2ec6497277e111c662069a7bff5c Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Wed, 17 Mar 2004 15:48:03 +0000 Subject: [PATCH] Add regression tests for the auto-require of STORABLE_thaw p4raw-id: //depot/perl@22515 --- MANIFEST | 1 + ext/Storable/ChangeLog | 4 ++++ ext/Storable/MANIFEST | 1 + ext/Storable/t/HAS_HOOK.pm | 9 +++++++++ ext/Storable/t/blessed.t | 42 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 ext/Storable/t/HAS_HOOK.pm diff --git a/MANIFEST b/MANIFEST index 6122742..1bd188d 100644 --- a/MANIFEST +++ b/MANIFEST @@ -650,6 +650,7 @@ ext/Storable/MANIFEST Storable extension ext/Storable/README Storable extension ext/Storable/Storable.pm Storable extension ext/Storable/Storable.xs Storable extension +ext/Storable/t/HAS_HOOK.pm For auto-requiring of modules for STORABLE_thaw ext/Storable/t/blessed.t See if Storable works ext/Storable/t/canonical.t See if Storable works ext/Storable/t/code.t See if Storable works diff --git a/ext/Storable/ChangeLog b/ext/Storable/ChangeLog index 38450ff..e4479ba 100644 --- a/ext/Storable/ChangeLog +++ b/ext/Storable/ChangeLog @@ -1,3 +1,7 @@ +Wed Mar 17 15:40:29 GMT 2004 Nicholas Clark + + 1. Add regression tests for the auto-require of STORABLE_thaw + Sat Mar 13 20:11:03 GMT 2004 Nicholas Clark Version 2.11 diff --git a/ext/Storable/MANIFEST b/ext/Storable/MANIFEST index d9b2d0d..3b70842 100644 --- a/ext/Storable/MANIFEST +++ b/ext/Storable/MANIFEST @@ -5,6 +5,7 @@ Storable.pm The perl side of Storable Storable.xs The C side of Storable ChangeLog Changes since baseline hints/linux.pl Hint file to drop gcc to -O2 +t/HAS_HOOK.pm For auto-requiring of modules for STORABLE_thaw t/blessed.t See if Storable works t/canonical.t See if Storable works t/code.t Test (de)serialization of code references diff --git a/ext/Storable/t/HAS_HOOK.pm b/ext/Storable/t/HAS_HOOK.pm new file mode 100644 index 0000000..979a6a2 --- /dev/null +++ b/ext/Storable/t/HAS_HOOK.pm @@ -0,0 +1,9 @@ +package HAS_HOOK; + +sub STORABLE_thaw { + ++$thawed_count; +} + +++$loaded_count; + +1; diff --git a/ext/Storable/t/blessed.t b/ext/Storable/t/blessed.t index 5b971c2..842674f 100644 --- a/ext/Storable/t/blessed.t +++ b/ext/Storable/t/blessed.t @@ -32,7 +32,7 @@ use Storable qw(freeze thaw); ); my $test = 12; -my $tests = $test + 2 * 6 * keys %::immortals; +my $tests = $test + 6 + 2 * 6 * keys %::immortals; print "1..$tests\n"; package SHORT_NAME; @@ -158,3 +158,43 @@ foreach $count (1..3) { ok ++$test, 1; } } + +# Test automatic require of packages to find thaw hook. + +package HAS_HOOK; + +$loaded_count = 0; +$thawed_count = 0; + +sub make { + bless []; +} + +sub STORABLE_freeze { + my $self = shift; + return ''; +} + +package main; + +my $f = freeze (HAS_HOOK->make); + +ok ++$test, $HAS_HOOK::loaded_count == 0; +ok ++$test, $HAS_HOOK::thawed_count == 0; + +my $t = thaw $f; +ok ++$test, $HAS_HOOK::loaded_count == 1; +ok ++$test, $HAS_HOOK::thawed_count == 1; +ok ++$test, $t; +ok ++$test, ref $t eq 'HAS_HOOK'; + +# Can't do this because the method is still cached by UNIVERSAL::can +# delete $INC{"HAS_HOOK.pm"}; +# undef &HAS_HOOK::STORABLE_thaw; +# +# warn HAS_HOOK->can('STORABLE_thaw'); +# $t = thaw $f; +# ok ++$test, $HAS_HOOK::loaded_count == 2; +# ok ++$test, $HAS_HOOK::thawed_count == 2; +# ok ++$test, $t; +# ok ++$test, ref $t eq 'HAS_HOOK'; -- 2.7.4