blob: 2ea1e13f3644e2a8bfb1d52467eba181d1642b38 [file] [log] [blame]
Akron03b24db2016-08-16 20:54:32 +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;
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 'extract'
22);
23
24# Test without parameters
25stdout_like(
26 sub {
27 system($call);
28 },
29 qr!extract.+?Extract KorAP-XML files!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 'extract',
43 '--input' => $input,
44 '--output' => $output,
45);
46
47# Test without compression
48stdout_like(
49 sub {
50 system($call);
51 },
52 qr!TEST/BSP/1 extracted.!s,
53 $call
54);
55
56ok(-d catdir($output, 'TEST', 'BSP', '1'), 'Directory created');
57ok(-d catdir($output, 'TEST', 'BSP', '1', 'base'), 'Directory created');
58ok(-d catdir($output, 'TEST', 'BSP', '1', 'sgbr'), 'Directory created');
59ok(-d catdir($output, 'TEST', 'BSP', '1', 'struct'), 'Directory created');
60ok(-f catfile($output, 'TEST', 'BSP', '1', 'data.xml'), 'File created');
61ok(-f catfile($output, 'TEST', 'BSP', '1', 'header.xml'), 'File created');
62ok(-d catdir($output, 'TEST', 'BSP', '2'), 'Directory created');
63ok(-d catdir($output, 'TEST', 'BSP', '3'), 'Directory created');
64
65# Check sigles
66my $output2 = tempdir(CLEANUP => 1);
67ok(-d $output2, 'Output directory exists');
68
69$call = join(
70 ' ',
71 'perl', $script,
72 'extract',
73 '--input' => $input,
74 '--output' => $output2,
75 '-sg' => 'TEST/BSP/4'
76);
77
78# Test with sigle
79stdout_like(
80 sub {
81 system($call);
82 },
83 qr!TEST/BSP/4 extracted.!s,
84 $call
85);
86
87# Test with sigle
88stdout_unlike(
89 sub {
90 system($call);
91 },
92 qr!TEST/BSP/5 extracted.!s,
93 $call
94);
95
96ok(!-d catdir($output2, 'TEST', 'BSP', '1'), 'Directory created');
97ok(!-d catdir($output2, 'TEST', 'BSP', '2'), 'Directory created');
98ok(!-d catdir($output2, 'TEST', 'BSP', '3'), 'Directory created');
99ok(-d catdir($output2, 'TEST', 'BSP', '4'), 'Directory created');
100ok(!-d catdir($output2, 'TEST', 'BSP', '5'), 'Directory created');
101
Akron651cb8d2016-08-16 21:44:49 +0200102# Check multiple archives
103$output = tempdir(CLEANUP => 1);
104ok(-d $output, 'Output directory exists');
105
106$call = join(
107 ' ',
108 'perl', $script,
109 'extract',
110 '-i' => catfile($f, '..', 'corpus', 'archives', 'wpd15-single.zip'),
111 '-i' => catfile($f, '..', 'corpus', 'archives', 'wpd15-single.tree_tagger.zip'),
112 '-i' => catfile($f, '..', 'corpus', 'archives', 'wpd15-single.opennlp.zip'),
113 '--output' => $output
114);
115
116# Test with sigle
117stdout_like(
118 sub {
119 system($call);
120 },
121 qr!WPD15/A00/00081 extracted.!s,
122 $call
123);
124
125ok(-d catdir($output, 'WPD15', 'A00', '00081'), 'Directory created');
126ok(-f catfile($output, 'WPD15', 'A00', 'header.xml'), 'Header file created');
127ok(-d catdir($output, 'WPD15', 'A00', '00081', 'base'), 'Directory created');
128
129ok(-f catfile($output, 'WPD15', 'A00', '00081', 'tree_tagger', 'morpho.xml'), 'New archive');
130ok(-f catfile($output, 'WPD15', 'A00', '00081', 'opennlp', 'morpho.xml'), 'New archive');
131
Akron03b24db2016-08-16 20:54:32 +0200132
133done_testing;
134__END__