blob: 1dfd19587dac7969ab5acd8a9a502fc81dd5299b [file] [log] [blame]
Akron486f9ab2017-04-22 23:25:19 +02001#/usr/bin/env perl
2use strict;
3use warnings;
4use File::Basename 'dirname';
5use File::Spec::Functions qw/catdir catfile/;
Akron5fd2d8e2017-06-19 15:29:39 +02006use File::Temp qw/:POSIX tempdir/;
Akron486f9ab2017-04-22 23:25:19 +02007use Mojo::File;
8use Mojo::Util qw/quote/;
9use Mojo::JSON qw/decode_json/;
10use IO::Uncompress::Gunzip;
11use Test::More;
12use Test::Output qw/:stdout :stderr :functions/;
13use Data::Dumper;
14use KorAP::XML::Archive;
15use utf8;
16
Akronfab17d32020-07-31 14:38:29 +020017if ($ENV{SKIP_SCRIPT}) {
18 plan skip_all => 'Skip script tests';
19};
20
Akron486f9ab2017-04-22 23:25:19 +020021my $f = dirname(__FILE__);
22my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
23
24my $call = join(
25 ' ',
26 'perl', $script,
27 'archive'
28);
29
30unless (KorAP::XML::Archive::test_unzip) {
31 plan skip_all => 'unzip not found';
32};
33
34# Test without parameters
35stdout_like(
36 sub {
37 system($call);
38 },
39 qr!archive.+?\$ korapxml2krill!s,
40 $call
41);
42
43my $input = catfile($f, '..', 'corpus', 'archive.zip');
44ok(-f $input, 'Input archive found');
45
46my $output = File::Temp->new;
47
48ok(-f $output, 'Output directory exists');
49
50my $input_quotes = "'".catfile($f, '..', 'corpus', 'archives', 'wpd15*.zip') . "'";
51
Akron5fd2d8e2017-06-19 15:29:39 +020052my $cache = tmpnam();
53
Akron486f9ab2017-04-22 23:25:19 +020054$call = join(
55 ' ',
56 'perl', $script,
57 'archive',
58 '--input' => $input_quotes,
59 '--output' => $output . '.tar',
Akron5fd2d8e2017-06-19 15:29:39 +020060 '--cache' => $cache,
Akron486f9ab2017-04-22 23:25:19 +020061 '-t' => 'Base#tokens_aggr',
62 '--to-tar'
63);
64
65# Test without parameters
66my $combined = combined_from( sub { system($call) });
67
Akronda3097e2017-04-23 19:53:57 +020068like($combined, qr!Input is .+?wpd15-single\.zip,.+?wpd15-single\.malt\.zip,.+?wpd15-single\.corenlp\.zip,.+?wpd15-single\.opennlp\.zip,.+?wpd15-single\.mdparser\.zip,.+?wpd15-single\.tree_tagger\.zip!is, 'Input is fine');
Akron486f9ab2017-04-22 23:25:19 +020069
Akronda3097e2017-04-23 19:53:57 +020070like($combined, qr!Writing to file .+?\.tar!, 'Write out');
71like($combined, qr!Wrote to tar archive!, 'Write out');
Akron486f9ab2017-04-22 23:25:19 +020072
73
74
75done_testing;
76__END__