Akron | 7d4cdd8 | 2016-08-17 21:39:45 +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/; |
| 6 | use File::Temp qw/tempdir/; |
| 7 | use Mojo::Util qw/slurp/; |
| 8 | use Mojo::JSON qw/decode_json/; |
| 9 | use IO::Uncompress::Gunzip; |
| 10 | use Test::More; |
| 11 | use Test::Output qw/:stdout :stderr :functions/; |
| 12 | use Data::Dumper; |
| 13 | use utf8; |
| 14 | |
| 15 | my $f = dirname(__FILE__); |
| 16 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 17 | |
| 18 | my $call = join( |
| 19 | ' ', |
| 20 | 'perl', $script, |
| 21 | 'archive' |
| 22 | ); |
| 23 | |
| 24 | # Test without parameters |
| 25 | stdout_like( |
| 26 | sub { |
| 27 | system($call); |
| 28 | }, |
| 29 | qr!archive.+?Process an!s, |
| 30 | $call |
| 31 | ); |
| 32 | |
| 33 | my $input = catfile($f, '..', 'corpus', 'archive.zip'); |
| 34 | ok(-f $input, 'Input archive found'); |
| 35 | |
| 36 | my $output = tempdir(CLEANUP => 1); |
| 37 | ok(-d $output, 'Output directory exists'); |
| 38 | |
| 39 | $call = join( |
| 40 | ' ', |
| 41 | 'perl', $script, |
| 42 | 'archive', |
| 43 | '--input' => $input, |
| 44 | '--output' => $output, |
| 45 | '-t' => 'Base#tokens_aggr', |
| 46 | '-m' => 'Sgbr' |
| 47 | ); |
| 48 | |
| 49 | # Test without compression |
| 50 | my $json; |
| 51 | { |
| 52 | local $SIG{__WARN__} = sub {}; |
| 53 | my $out = stdout_from(sub { system($call); }); |
| 54 | |
| 55 | like($out, qr!TEST-BSP-1\.json!s, $call); |
| 56 | |
| 57 | $out =~ m!Processed (.+?\.json)!; |
| 58 | $json = $1; |
| 59 | }; |
| 60 | |
| 61 | ok(-f $json, 'Json file exists'); |
| 62 | ok((my $file = slurp $json), 'Slurp data'); |
| 63 | ok(($json = decode_json $file), 'decode json'); |
| 64 | |
| 65 | is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title'); |
| 66 | is($json->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure sgbr sgbr/lemma sgbr/morpho', 'Foundries'); |
| 67 | is($json->{sgbrKodex}, 'M', 'Kodex meta data'); |
| 68 | |
| 69 | done_testing; |
| 70 | __END__ |