blob: 20321807488e8827f05e22c6c37f2370e17be402 [file] [log] [blame]
Akron7d4cdd82016-08-17 21:39:45 +02001#/usr/bin/env perl
2use strict;
3use warnings;
4use File::Basename 'dirname';
5use File::Spec::Functions qw/catdir catfile/;
6use File::Temp qw/tempdir/;
7use Mojo::Util qw/slurp/;
8use Mojo::JSON qw/decode_json/;
9use IO::Uncompress::Gunzip;
10use Test::More;
11use Test::Output qw/:stdout :stderr :functions/;
12use Data::Dumper;
13use utf8;
14
15my $f = dirname(__FILE__);
16my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
17
18my $call = join(
19 ' ',
20 'perl', $script,
21 'archive'
22);
23
24# Test without parameters
25stdout_like(
26 sub {
27 system($call);
28 },
29 qr!archive.+?Process an!s,
30 $call
31);
32
33my $input = catfile($f, '..', 'corpus', 'archive.zip');
34ok(-f $input, 'Input archive found');
35
36my $output = tempdir(CLEANUP => 1);
37ok(-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
50my $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
61ok(-f $json, 'Json file exists');
62ok((my $file = slurp $json), 'Slurp data');
63ok(($json = decode_json $file), 'decode json');
64
65is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title');
66is($json->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure sgbr sgbr/lemma sgbr/morpho', 'Foundries');
67is($json->{sgbrKodex}, 'M', 'Kodex meta data');
68
69done_testing;
70__END__