Akron | 486f9ab | 2017-04-22 23:25:19 +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/; |
Akron | 5fd2d8e | 2017-06-19 15:29:39 +0200 | [diff] [blame] | 6 | use File::Temp qw/:POSIX tempdir/; |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 7 | use Mojo::File; |
| 8 | use Mojo::Util qw/quote/; |
| 9 | use Mojo::JSON qw/decode_json/; |
| 10 | use IO::Uncompress::Gunzip; |
| 11 | use Test::More; |
| 12 | use Test::Output qw/:stdout :stderr :functions/; |
| 13 | use Data::Dumper; |
| 14 | use KorAP::XML::Archive; |
| 15 | use utf8; |
| 16 | |
| 17 | my $f = dirname(__FILE__); |
| 18 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 19 | |
| 20 | my $call = join( |
| 21 | ' ', |
| 22 | 'perl', $script, |
| 23 | 'archive' |
| 24 | ); |
| 25 | |
| 26 | unless (KorAP::XML::Archive::test_unzip) { |
| 27 | plan skip_all => 'unzip not found'; |
| 28 | }; |
| 29 | |
| 30 | # Test without parameters |
| 31 | stdout_like( |
| 32 | sub { |
| 33 | system($call); |
| 34 | }, |
| 35 | qr!archive.+?\$ korapxml2krill!s, |
| 36 | $call |
| 37 | ); |
| 38 | |
| 39 | my $input = catfile($f, '..', 'corpus', 'archive.zip'); |
| 40 | ok(-f $input, 'Input archive found'); |
| 41 | |
| 42 | my $output = File::Temp->new; |
| 43 | |
| 44 | ok(-f $output, 'Output directory exists'); |
| 45 | |
| 46 | my $input_quotes = "'".catfile($f, '..', 'corpus', 'archives', 'wpd15*.zip') . "'"; |
| 47 | |
Akron | 5fd2d8e | 2017-06-19 15:29:39 +0200 | [diff] [blame] | 48 | my $cache = tmpnam(); |
| 49 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 50 | $call = join( |
| 51 | ' ', |
| 52 | 'perl', $script, |
| 53 | 'archive', |
| 54 | '--input' => $input_quotes, |
| 55 | '--output' => $output . '.tar', |
Akron | 5fd2d8e | 2017-06-19 15:29:39 +0200 | [diff] [blame] | 56 | '--cache' => $cache, |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 57 | '-t' => 'Base#tokens_aggr', |
| 58 | '--to-tar' |
| 59 | ); |
| 60 | |
| 61 | # Test without parameters |
| 62 | my $combined = combined_from( sub { system($call) }); |
| 63 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 64 | like($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'); |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 65 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 66 | like($combined, qr!Writing to file .+?\.tar!, 'Write out'); |
| 67 | like($combined, qr!Wrote to tar archive!, 'Write out'); |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 68 | |
| 69 | |
| 70 | |
| 71 | done_testing; |
| 72 | __END__ |