File: destroy.pl

package info (click to toggle)
libio-compress-lzma-perl 2.213-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 848 kB
  • sloc: perl: 7,361; makefile: 13
file content (115 lines) | stat: -rw-r--r-- 2,229 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

use lib 't';
use strict;
use warnings;
use bytes;

use Test::More ;
use CompTestUtils;

BEGIN
{
    plan(skip_all => "Destroy not supported in Perl $]")
        if $] == 5.008 || ( $] >= 5.005 && $] < 5.006) ;

    # use Test::NoWarnings, if available
    my $extra = 0 ;
    $extra = 1
        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };

    plan tests => 15 + $extra ;

    use_ok('IO::File') ;
}

sub run
{

    my $CompressClass   = identify();
    my $UncompressClass = getInverse($CompressClass);
    my $Error           = getErrorRef($CompressClass);
    my $UnError         = getErrorRef($UncompressClass);

    title "Testing $CompressClass";

    {
        # Check that the class destructor will call close

        my $lex = new LexFile my $name ;

        my $hello = <<EOM ;
hello world
this is a test
EOM


        {
          ok my $x = new $CompressClass $name, -AutoClose => 1  ;

          ok $x->write($hello) ;
        }

        is anyUncompress($name), $hello ;
    }

    {
        # Tied filehandle destructor


        my $lex = new LexFile my $name ;

        my $hello = <<EOM ;
hello world
this is a test
EOM

        my $fh = new IO::File "> $name" ;

        {
          ok my $x = new $CompressClass $fh, -AutoClose => 1  ;

          $x->write($hello) ;
        }

        ok anyUncompress($name) eq $hello ;
    }

    {
        title "Testing DESTROY doesn't clobber \$! etc ";

        my $lex = new LexFile my $name ;

        my $out;
        my $result;

        {
            ok my $z = new $CompressClass($name);
            $z->write("abc") ;
            $! = 22 ;

            cmp_ok $!, '==', 22, '  $! is 22';
        }

        cmp_ok $!, '==', 22, "  \$! has not been changed by $CompressClass destructor";


        {
                my $uncomp;
                ok my $x = new $UncompressClass($name, -Append => 1)  ;

                my $len ;
                1 while ($len = $x->read($result)) > 0 ;

                $! = 22 ;

                cmp_ok $!, '==', 22, '  $! is 22';
        }

        cmp_ok $!, '==', 22, "  \$! has not been changed by $UncompressClass destructor";

        is $result, "abc", "  Got uncompressed content ok";

    }
}

1;