blob: 60c2eac99fdebaece26d1ff2167fe58ed6544650 [file] [log] [blame]
Akron9a062ce2017-07-04 19:12:05 +02001#/usr/bin/env perl
2use strict;
3use warnings;
4use File::Basename 'dirname';
5use File::Spec::Functions qw/catdir catfile/;
6use File::Temp qw/:POSIX tempdir/;
7use Mojo::File;
8use Mojo::Util qw/quote/;
9use Mojo::JSON qw/decode_json/;
10use Archive::Tar;
11use IO::Uncompress::Gunzip;
12use Test::More;
13use Test::Output qw/:stdout :stderr :functions/;
14use Data::Dumper;
15use KorAP::XML::Archive;
16use utf8;
17
Akronfab17d32020-07-31 14:38:29 +020018if ($ENV{SKIP_SCRIPT}) {
19 plan skip_all => 'Skip script tests';
20};
21
Akron2d401662021-03-17 11:32:18 +010022unless (KorAP::XML::Archive::test_unzip) {
23 plan skip_all => 'unzip not found';
24};
25
Akron9a062ce2017-07-04 19:12:05 +020026my $f = dirname(__FILE__);
27my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
28
29my $input_base = catdir($f, '..', 'corpus');
30
31# Temporary output
32my $output = File::Temp->newdir(CLEANUP => 0);
33my $temp_ex = File::Temp->newdir(CLEANUP => 0);
34
35my $cache = tmpnam();
36
37my $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
54my $stdout = stdout_from(sub { system($call) });
55
56my $wpd_archive = catfile($output, 'archives-wpd15.tar');
57my $bsp_archive = catfile($output, 'archive.tar');
58
59ok(-e $wpd_archive, 'Archive exists');
60ok(-e $bsp_archive, 'Archive exists');
61
62my $tar = Archive::Tar->new;
63$tar->read($bsp_archive);
64ok($tar->contains_file('TEST-BSP-1.json.gz'), 'File found');
65
66$tar->read($wpd_archive);
67ok($tar->contains_file('WPD15-A00-00081.json.gz'), 'File found');
68
69done_testing;