blob: 4429a086b338f528ce1bc033780963ec10a7803b [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
102
103done_testing;
104__END__
105
106
107
108
109
110# Test sigle!
111# Test multiple archives
112
113