| Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 1 | #/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use File::Basename 'dirname'; |
| 5 | use File::Spec::Functions qw/catdir catfile/; |
| 6 | use File::Temp qw/:POSIX tempdir/; |
| 7 | use Mojo::File; |
| 8 | use Mojo::Util qw/quote/; |
| 9 | use Mojo::JSON qw/decode_json/; |
| 10 | use Archive::Tar; |
| 11 | use IO::Uncompress::Gunzip; |
| 12 | use Test::More; |
| 13 | use Test::Output qw/:stdout :stderr :functions/; |
| 14 | use Data::Dumper; |
| 15 | use KorAP::XML::Archive; |
| 16 | use utf8; |
| 17 | |
| Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame] | 18 | if ($ENV{SKIP_SCRIPT}) { |
| 19 | plan skip_all => 'Skip script tests'; |
| 20 | }; |
| 21 | |
| Akron | 2d40166 | 2021-03-17 11:32:18 +0100 | [diff] [blame] | 22 | unless (KorAP::XML::Archive::test_unzip) { |
| 23 | plan skip_all => 'unzip not found'; |
| 24 | }; |
| 25 | |
| Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 26 | my $f = dirname(__FILE__); |
| 27 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 28 | |
| 29 | my $input_base = catdir($f, '..', 'corpus'); |
| 30 | |
| 31 | # Temporary output |
| 32 | my $output = File::Temp->newdir(CLEANUP => 0); |
| 33 | my $temp_ex = File::Temp->newdir(CLEANUP => 0); |
| 34 | |
| 35 | my $cache = tmpnam(); |
| 36 | |
| 37 | my $call = join( |
| 38 | ' ', |
| 39 | 'perl', $script, |
| 40 | 'serial', |
| 41 | '-t' => 'Base#tokens_aggr', |
| 42 | '-i' => '"archive.zip"', |
| 43 | '-i' => '"archives/wpd15*.zip"', |
| 44 | '--cache' => $cache, |
| 45 | '-ib' => $input_base, |
| 46 | '-o' => $output, |
| 47 | '--to-tar' => 1, |
| 48 | '-temporary-extract' => $temp_ex, |
| 49 | '-sequential-extraction' => 1, |
| 50 | '--gzip' => 1 |
| 51 | ); |
| 52 | |
| 53 | # Test without parameters |
| 54 | my $stdout = stdout_from(sub { system($call) }); |
| 55 | |
| 56 | my $wpd_archive = catfile($output, 'archives-wpd15.tar'); |
| 57 | my $bsp_archive = catfile($output, 'archive.tar'); |
| 58 | |
| 59 | ok(-e $wpd_archive, 'Archive exists'); |
| 60 | ok(-e $bsp_archive, 'Archive exists'); |
| 61 | |
| 62 | my $tar = Archive::Tar->new; |
| 63 | $tar->read($bsp_archive); |
| 64 | ok($tar->contains_file('TEST-BSP-1.json.gz'), 'File found'); |
| 65 | |
| 66 | $tar->read($wpd_archive); |
| 67 | ok($tar->contains_file('WPD15-A00-00081.json.gz'), 'File found'); |
| 68 | |
| 69 | done_testing; |