blob: a31e9b026d29da6ce81fc1f706627f15be272fe3 [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
17my $f = dirname(__FILE__);
18my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
19
20my $call = join(
21 ' ',
22 'perl', $script,
23 'archive'
24);
25
26unless (KorAP::XML::Archive::test_unzip) {
27 plan skip_all => 'unzip not found';
28};
29
30# Test without parameters
31stdout_like(
32 sub {
33 system($call);
34 },
35 qr!archive.+?\$ korapxml2krill!s,
36 $call
37);
38
39my $input = catfile($f, '..', 'corpus', 'archive.zip');
40ok(-f $input, 'Input archive found');
41
42my $output = File::Temp->new;
43
44ok(-f $output, 'Output directory exists');
45
46my $input_quotes = "'".catfile($f, '..', 'corpus', 'archives', 'wpd15*.zip') . "'";
47
Akron5fd2d8e2017-06-19 15:29:39 +020048my $cache = tmpnam();
49
Akron486f9ab2017-04-22 23:25:19 +020050$call = join(
51 ' ',
52 'perl', $script,
53 'archive',
54 '--input' => $input_quotes,
55 '--output' => $output . '.tar',
Akron5fd2d8e2017-06-19 15:29:39 +020056 '--cache' => $cache,
Akron486f9ab2017-04-22 23:25:19 +020057 '-t' => 'Base#tokens_aggr',
58 '--to-tar'
59);
60
61# Test without parameters
62my $combined = combined_from( sub { system($call) });
63
Akronda3097e2017-04-23 19:53:57 +020064like($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 +020065
Akronda3097e2017-04-23 19:53:57 +020066like($combined, qr!Writing to file .+?\.tar!, 'Write out');
67like($combined, qr!Wrote to tar archive!, 'Write out');
Akron486f9ab2017-04-22 23:25:19 +020068
69
70
71done_testing;
72__END__