| 1 | BEGIN { |
| 2 | if ($ENVscip-perl cpan IO-Compress-Lzma 2.217 main/`%ENV`.{PERL_CORE}) { |
| 3 | chdirscip-perl cpan IO-Compress-Lzma 2.217 main/chdir(). 't' if -d 't'; |
| 4 | @INCscip-perl cpan IO-Compress-Lzma 2.217 main/`@INC`. = ("../lib", "lib/compress"); |
| 5 | } |
| 6 | } |
| 7 | |
| 8 | use libscip-perl cpan IO-Compress-Lzma 2.217 lib/ qw(t t/compress); |
| 9 | use strictscip-perl cpan IO-Compress-Lzma 2.217 strict/; |
| 10 | use warningsscip-perl cpan IO-Compress-Lzma 2.217 warnings/; |
| 11 | use bytesscip-perl cpan IO-Compress-Lzma 2.217 bytes/; |
| 12 | |
| 13 | use File::Specscip-perl cpan IO-Compress-Lzma 2.217 File/Spec/ ; |
| 14 | use Test::Morescip-perl cpan IO-Compress-Lzma 2.217 Test/More/ ; |
| 15 | use CompTestUtilsscip-perl cpan IO-Compress-Lzma 2.217 CompTestUtils/; |
| 16 | |
| 17 | my $XZ ; |
| 18 | |
| 19 | sub ExternalXzWorksscip-perl cpan IO-Compress-Lzma 2.217 main/ExternalXzWorks(). |
| 20 | { |
| 21 | my $lex = new LexFile my $outfile; |
| 22 | my $content = qq { |
| 23 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id |
| 24 | dolor. Camelus perlus. Larrius in lumen numen. Dolor en quiquum filia |
| 25 | est. Quintus cenum parat. |
| 26 | }; |
| 27 | |
| 28 | writeWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/writeWithXz().($outfile, $content) |
| 29 | or return 0; |
| 30 | |
| 31 | my $got ; |
| 32 | readWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/readWithXz().($outfile, $got) |
| 33 | or return 0; |
| 34 | |
| 35 | if ($content ne $got) |
| 36 | { |
| 37 | diagscip-perl cpan IO-Compress-Lzma 2.217 main/diag(). "Uncompressed content is wrong"; |
| 38 | return 0 ; |
| 39 | } |
| 40 | |
| 41 | return 1 ; |
| 42 | } |
| 43 | |
| 44 | sub readWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/readWithXz(). |
| 45 | { |
| 46 | my $file = shiftscip-perl cpan IO-Compress-Lzma 2.217 main/shift(). ; |
| 47 | |
| 48 | my $lex = new LexFile my $outfile; |
| 49 | |
| 50 | my $comp = "$XZ -dc" ; |
| 51 | |
| 52 | if (systemscip-perl cpan IO-Compress-Lzma 2.217 main/system().("$comp $file >$outfile") == 0 ) |
| 53 | { |
| 54 | $_scip-perl cpan IO-Compress-Lzma 2.217 main/`@_`.[0] = readFilescip-perl cpan IO-Compress-Lzma 2.217 main/readFile().($outfile); |
| 55 | return 1 ; |
| 56 | } |
| 57 | |
| 58 | diagscip-perl cpan IO-Compress-Lzma 2.217 main/diag(). "'$comp' failed: $?"; |
| 59 | return 0 ; |
| 60 | } |
| 61 | |
| 62 | sub getBzip2Infoscip-perl cpan IO-Compress-Lzma 2.217 main/getBzip2Info(). |
| 63 | { |
| 64 | my $file = shiftscip-perl cpan IO-Compress-Lzma 2.217 main/shift(). ; |
| 65 | } |
| 66 | |
| 67 | sub writeWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/writeWithXz(). |
| 68 | { |
| 69 | my $file = shiftscip-perl cpan IO-Compress-Lzma 2.217 main/shift(). ; |
| 70 | my $content = shiftscip-perl cpan IO-Compress-Lzma 2.217 main/shift(). ; |
| 71 | my $options = shiftscip-perl cpan IO-Compress-Lzma 2.217 main/shift(). || ''; |
| 72 | |
| 73 | my $lex = new LexFile my $infile; |
| 74 | writeFilescip-perl cpan IO-Compress-Lzma 2.217 main/writeFile().($infile, $content); |
| 75 | |
| 76 | unlinkscip-perl cpan IO-Compress-Lzma 2.217 main/unlink(). $file ; |
| 77 | my $comp = "$XZ -c $options $infile >$file" ; |
| 78 | |
| 79 | return 1 |
| 80 | if systemscip-perl cpan IO-Compress-Lzma 2.217 main/system().($comp) == 0 ; |
| 81 | |
| 82 | diagscip-perl cpan IO-Compress-Lzma 2.217 main/diag(). "'$comp' failed: $?"; |
| 83 | return 0 ; |
| 84 | } |
| 85 | |
| 86 | BEGIN |
| 87 | { |
| 88 | |
| 89 | # Check external xz is available |
| 90 | my $name = $^Oscip-perl cpan IO-Compress-Lzma 2.217 main/`$^O`. =~ /mswin/i ? 'xz.exe' : 'xz'; |
| 91 | my $split = $^Oscip-perl cpan IO-Compress-Lzma 2.217 main/`$^O`. =~ /mswin/i ? ";" : ":"; |
| 92 | |
| 93 | for my $dir (reversescip-perl cpan IO-Compress-Lzma 2.217 main/reverse(). splitscip-perl cpan IO-Compress-Lzma 2.217 main/split(). $split, $ENVscip-perl cpan IO-Compress-Lzma 2.217 main/`%ENV`.{PATH}) |
| 94 | { |
| 95 | $XZ = File::Spec->catfilescip-perl cpan IO-Compress-Lzma 2.217 File/Spec/catfile().($dir,$name) |
| 96 | if -x File::Spec->catfilescip-perl cpan IO-Compress-Lzma 2.217 File/Spec/catfile().($dir,$name); |
| 97 | } |
| 98 | |
| 99 | # Handle spaces in path to xz |
| 100 | $XZ = "\"$XZ\"" if definedscip-perl cpan IO-Compress-Lzma 2.217 main/defined(). $XZ && $XZ =~ /\s/; |
| 101 | |
| 102 | planscip-perl cpan IO-Compress-Lzma 2.217 main/plan().(skip_all => "Cannot find $name") |
| 103 | if ! $XZ ; |
| 104 | |
| 105 | planscip-perl cpan IO-Compress-Lzma 2.217 main/plan().(skip_all => "$name doesn't work as expected") |
| 106 | if ! ExternalXzWorksscip-perl cpan IO-Compress-Lzma 2.217 main/ExternalXzWorks().(); |
| 107 | |
| 108 | # use Test::NoWarnings, if available |
| 109 | my $extra = 0 ; |
| 110 | $extra = 1 |
| 111 | if eval { requirescip-perl cpan IO-Compress-Lzma 2.217 main/require(). Test::NoWarnings ; import Test::NoWarnings; 1 }; |
| 112 | |
| 113 | planscip-perl cpan IO-Compress-Lzma 2.217 main/plan(). tests => 12 + $extra ; |
| 114 | |
| 115 | use_okscip-perl cpan IO-Compress-Lzma 2.217 main/use_ok().('IO::Compress::Xz', ':all') ; |
| 116 | use_okscip-perl cpan IO-Compress-Lzma 2.217 main/use_ok().('IO::Uncompress::UnXz', ':all') ; |
| 117 | |
| 118 | } |
| 119 | |
| 120 | { |
| 121 | # Delete environment variables used by xz that could impact the running of the test |
| 122 | for my $var (qw( XZ_DEFAULTS XZ_OPT )) |
| 123 | { |
| 124 | deletescip-perl cpan IO-Compress-Lzma 2.217 main/delete(). $ENVscip-perl cpan IO-Compress-Lzma 2.217 main/`%ENV`.{$var}; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | { |
| 129 | titlescip-perl cpan IO-Compress-Lzma 2.217 main/title(). "Test interop with $XZ" ; |
| 130 | |
| 131 | my ($file, $file1); |
| 132 | my $lex = new LexFile $file, $file1; |
| 133 | my $content = "hello world\n" ; |
| 134 | my $got; |
| 135 | |
| 136 | okscip-perl cpan IO-Compress-Lzma 2.217 main/ok(). writeWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/writeWithXz().($file, $content), "writeWithXz ok"; |
| 137 | |
| 138 | unxzscip-perl cpan IO-Compress-Lzma 2.217 main/unxz(). $file => \$got ; |
| 139 | isscip-perl cpan IO-Compress-Lzma 2.217 main/is(). $got, $content; |
| 140 | |
| 141 | |
| 142 | xz \$content => $file1; |
| 143 | $got = ''; |
| 144 | okscip-perl cpan IO-Compress-Lzma 2.217 main/ok(). readWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/readWithXz().($file1, $got), "readWithXz returns 0"; |
| 145 | isscip-perl cpan IO-Compress-Lzma 2.217 main/is(). $got, $content, "got content"; |
| 146 | } |
| 147 | |
| 148 | { |
| 149 | titlescip-perl cpan IO-Compress-Lzma 2.217 main/title(). "Test interop with $XZ - empty file" ; |
| 150 | |
| 151 | my ($file, $file1); |
| 152 | my $lex = new LexFile $file, $file1; |
| 153 | my $content = "" ; |
| 154 | my $got; |
| 155 | |
| 156 | okscip-perl cpan IO-Compress-Lzma 2.217 main/ok(). writeWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/writeWithXz().($file, $content), "writeWithXz ok"; |
| 157 | |
| 158 | unxzscip-perl cpan IO-Compress-Lzma 2.217 main/unxz(). $file => \$got ; |
| 159 | isscip-perl cpan IO-Compress-Lzma 2.217 main/is(). $got, $content; |
| 160 | |
| 161 | |
| 162 | xz \$content => $file1; |
| 163 | $got = ''; |
| 164 | okscip-perl cpan IO-Compress-Lzma 2.217 main/ok(). readWithXzscip-perl cpan IO-Compress-Lzma 2.217 main/readWithXz().($file1, $got), "readWithXz returns 0"; |
| 165 | isscip-perl cpan IO-Compress-Lzma 2.217 main/is(). $got, $content, "got content"; |
| 166 | } |