From: Nicholas Clark Date: Wed, 4 May 2011 19:14:43 +0000 (+0200) Subject: Add tests for sizing magic. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=72e2658d6b79549c2318c52724ff39fd6357c359;p=p5sagit%2FDevel-Size.git Add tests for sizing magic. --- diff --git a/MANIFEST b/MANIFEST index b8aa6f7..6328f74 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,6 +10,7 @@ ppport.h t/basic.t t/code.t t/globs.t +t/magic.t t/pod.t t/pod_cov.t t/pvbm.t diff --git a/t/magic.t b/t/magic.t new file mode 100644 index 0000000..d0f5b73 --- /dev/null +++ b/t/magic.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More tests => 7; +use Devel::Size ':all'; +require Tie::Scalar; + +{ + my $string = 'Perl Rules'; + my $before_size = total_size($string); + is($string =~ /Perl/g, 1, 'It had better match'); + cmp_ok($before_size, '>', length $string, + 'Our string has a non-zero length'); + cmp_ok(total_size($string), '>', $before_size, + 'size increases due to magic'); +} + +{ + my $string = 'Perl Rules'; + my $before_size = total_size($string); + formline $string; + my $compiled_size = total_size($string); + cmp_ok($before_size, '>', length $string, + 'Our string has a non-zero length'); + cmp_ok($compiled_size, '>', $before_size, + 'size increases due to magic (and the compiled state)'); + # Not fully sure why (didn't go grovelling) but need to use a temporary to + # avoid the magic being copied. + $string = '' . $string; + my $after_size = total_size($string); + cmp_ok($after_size, '>', $before_size, 'Still larger than initial size'); + cmp_ok($after_size, '<', $compiled_size, 'size decreases due to unmagic'); +}