This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Tweak to make it clearer what to do if your working space is dirty
[perl5.git] / cpan / Compress-Raw-Zlib / t / 18lvalue.t
1 BEGIN {
2     if ($ENV{PERL_CORE}) {
3         chdir 't' if -d 't';
4         @INC = ("../lib", "lib/compress");
5     }
6 }
7
8 use lib qw(t t/compress);
9 use strict;
10 use warnings;
11 use bytes;
12
13 use Test::More ;
14 use CompTestUtils;
15
16 BEGIN 
17
18     plan(skip_all => "lvalue sub tests need Perl ??")
19         if $] < 5.006 ; 
20
21     # use Test::NoWarnings, if available
22     my $extra = 0 ;
23     $extra = 1
24         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
25
26     plan tests => 10 + $extra ;
27
28     use_ok('Compress::Raw::Zlib', 2) ;
29 }
30  
31
32
33 my $hello = <<EOM ;
34 hello world
35 this is a test
36 EOM
37
38 my $len   = length $hello ;
39
40 # Check zlib_version and ZLIB_VERSION are the same.
41 SKIP: {
42     skip "TEST_SKIP_VERSION_CHECK is set", 1 
43         if $ENV{TEST_SKIP_VERSION_CHECK};
44     is Compress::Raw::Zlib::zlib_version, ZLIB_VERSION,
45         "ZLIB_VERSION matches Compress::Raw::Zlib::zlib_version" ;
46 }
47
48
49 {
50     title 'deflate/inflate with lvalue sub';
51
52     my $hello = "I am a HAL 9000 computer" ;
53     my $data = $hello ;
54
55     my($X, $Z);
56     sub getData : lvalue { $data }
57     sub getX    : lvalue { $X }
58     sub getZ    : lvalue { $Z }
59
60     ok my $x = new Compress::Raw::Zlib::Deflate ( -AppendOutput => 1 );
61
62     cmp_ok $x->deflate(getData, getX), '==',  Z_OK ;
63
64     cmp_ok $x->flush(getX), '==', Z_OK ;
65      
66     my $append = "Appended" ;
67     $X .= $append ;
68      
69     ok my $k = new Compress::Raw::Zlib::Inflate ( -AppendOutput => 1 ) ;
70      
71     cmp_ok $k->inflate(getX, getZ), '==', Z_STREAM_END ; ;
72      
73     ok $hello eq $Z ;
74     is $X, $append;
75     
76 }
77
78