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 | |
Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame] | 17 | if ($ENV{SKIP_SCRIPT}) { |
| 18 | plan skip_all => 'Skip script tests'; |
| 19 | }; |
| 20 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 21 | my $f = dirname(__FILE__); |
| 22 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 23 | |
| 24 | my $call = join( |
| 25 | ' ', |
| 26 | 'perl', $script, |
| 27 | 'archive' |
| 28 | ); |
| 29 | |
| 30 | unless (KorAP::XML::Archive::test_unzip) { |
| 31 | plan skip_all => 'unzip not found'; |
| 32 | }; |
| 33 | |
| 34 | # Test without parameters |
| 35 | stdout_like( |
| 36 | sub { |
| 37 | system($call); |
| 38 | }, |
| 39 | qr!archive.+?\$ korapxml2krill!s, |
| 40 | $call |
| 41 | ); |
| 42 | |
| 43 | my $input = catfile($f, '..', 'corpus', 'archive.zip'); |
| 44 | ok(-f $input, 'Input archive found'); |
| 45 | |
| 46 | my $output = File::Temp->new; |
| 47 | |
| 48 | ok(-f $output, 'Output directory exists'); |
| 49 | |
| 50 | my $input_quotes = "'".catfile($f, '..', 'corpus', 'archives', 'wpd15*.zip') . "'"; |
| 51 | |
Akron | 5fd2d8e | 2017-06-19 15:29:39 +0200 | [diff] [blame] | 52 | my $cache = tmpnam(); |
| 53 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 54 | $call = join( |
| 55 | ' ', |
| 56 | 'perl', $script, |
| 57 | 'archive', |
| 58 | '--input' => $input_quotes, |
| 59 | '--output' => $output . '.tar', |
Akron | 5fd2d8e | 2017-06-19 15:29:39 +0200 | [diff] [blame] | 60 | '--cache' => $cache, |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 61 | '-t' => 'Base#tokens_aggr', |
| 62 | '--to-tar' |
| 63 | ); |
| 64 | |
| 65 | # Test without parameters |
| 66 | my $combined = combined_from( sub { system($call) }); |
| 67 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 68 | 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] | 69 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 70 | like($combined, qr!Writing to file .+?\.tar!, 'Write out'); |
| 71 | like($combined, qr!Wrote to tar archive!, 'Write out'); |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 72 | |
| 73 | |
| 74 | |
| 75 | done_testing; |
| 76 | __END__ |