Akron | 03b24db | 2016-08-16 20:54:32 +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; |
| 12 | use Data::Dumper; |
Nils Diewald | b3e9ccd | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 13 | use KorAP::XML::Archive; |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 14 | use utf8; |
| 15 | |
| 16 | my $f = dirname(__FILE__); |
| 17 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 18 | |
| 19 | my $call = join( |
| 20 | ' ', |
| 21 | 'perl', $script, |
| 22 | 'extract' |
| 23 | ); |
| 24 | |
Nils Diewald | b3e9ccd | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 25 | unless (KorAP::XML::Archive::test_unzip) { |
| 26 | plan skip_all => 'unzip not found'; |
| 27 | }; |
| 28 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 29 | # Test without parameters |
| 30 | stdout_like( |
| 31 | sub { |
| 32 | system($call); |
| 33 | }, |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 34 | qr!extract.+?\$ korapxml2krill!s, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 35 | $call |
| 36 | ); |
| 37 | |
| 38 | my $input = catfile($f, '..', 'corpus', 'archive.zip'); |
| 39 | ok(-f $input, 'Input archive found'); |
| 40 | |
| 41 | my $output = tempdir(CLEANUP => 1); |
| 42 | ok(-d $output, 'Output directory exists'); |
| 43 | |
| 44 | $call = join( |
| 45 | ' ', |
| 46 | 'perl', $script, |
| 47 | 'extract', |
| 48 | '--input' => $input, |
| 49 | '--output' => $output, |
| 50 | ); |
| 51 | |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 52 | my $sep = qr!\.\.\.[\n\r]+?\.\.\.!; |
| 53 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 54 | # Test without compression |
| 55 | stdout_like( |
| 56 | sub { |
| 57 | system($call); |
| 58 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 59 | qr!TEST/BSP/1 $sep extracted.!s, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 60 | $call |
| 61 | ); |
| 62 | |
| 63 | ok(-d catdir($output, 'TEST', 'BSP', '1'), 'Directory created'); |
| 64 | ok(-d catdir($output, 'TEST', 'BSP', '1', 'base'), 'Directory created'); |
| 65 | ok(-d catdir($output, 'TEST', 'BSP', '1', 'sgbr'), 'Directory created'); |
| 66 | ok(-d catdir($output, 'TEST', 'BSP', '1', 'struct'), 'Directory created'); |
| 67 | ok(-f catfile($output, 'TEST', 'BSP', '1', 'data.xml'), 'File created'); |
| 68 | ok(-f catfile($output, 'TEST', 'BSP', '1', 'header.xml'), 'File created'); |
| 69 | ok(-d catdir($output, 'TEST', 'BSP', '2'), 'Directory created'); |
| 70 | ok(-d catdir($output, 'TEST', 'BSP', '3'), 'Directory created'); |
| 71 | |
| 72 | # Check sigles |
| 73 | my $output2 = tempdir(CLEANUP => 1); |
| 74 | ok(-d $output2, 'Output directory exists'); |
| 75 | |
| 76 | $call = join( |
| 77 | ' ', |
| 78 | 'perl', $script, |
| 79 | 'extract', |
| 80 | '--input' => $input, |
| 81 | '--output' => $output2, |
| 82 | '-sg' => 'TEST/BSP/4' |
| 83 | ); |
| 84 | |
| 85 | # Test with sigle |
| 86 | stdout_like( |
| 87 | sub { |
| 88 | system($call); |
| 89 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 90 | qr!TEST/BSP/4 $sep extracted.!s, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 91 | $call |
| 92 | ); |
| 93 | |
| 94 | # Test with sigle |
| 95 | stdout_unlike( |
| 96 | sub { |
| 97 | system($call); |
| 98 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 99 | qr!TEST/BSP/5 $sep extracted.!s, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 100 | $call |
| 101 | ); |
| 102 | |
| 103 | ok(!-d catdir($output2, 'TEST', 'BSP', '1'), 'Directory created'); |
| 104 | ok(!-d catdir($output2, 'TEST', 'BSP', '2'), 'Directory created'); |
| 105 | ok(!-d catdir($output2, 'TEST', 'BSP', '3'), 'Directory created'); |
| 106 | ok(-d catdir($output2, 'TEST', 'BSP', '4'), 'Directory created'); |
| 107 | ok(!-d catdir($output2, 'TEST', 'BSP', '5'), 'Directory created'); |
| 108 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 109 | |
| 110 | # Test with document sigle |
| 111 | my $input_rei = catdir($f, '..', 'corpus', 'archive_rei.zip'); |
| 112 | ok(-f $input_rei, 'Input archive found'); |
| 113 | |
| 114 | $call = join( |
| 115 | ' ', |
| 116 | 'perl', $script, |
| 117 | 'extract', |
| 118 | '--input' => $input_rei, |
| 119 | '--output' => $output2, |
| 120 | '-sg' => 'REI/BNG' |
| 121 | ); |
| 122 | |
| 123 | # Test with sigle |
| 124 | stdout_like( |
| 125 | sub { |
| 126 | system($call); |
| 127 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 128 | qr!REI/BNG $sep extracted!s, |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 129 | $call |
| 130 | ); |
| 131 | |
| 132 | # Test with sigle |
| 133 | stdout_unlike( |
| 134 | sub { |
| 135 | system($call); |
| 136 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 137 | qr!REI/RBR $sep extracted!s, |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 138 | $call |
| 139 | ); |
| 140 | |
| 141 | ok(-d catdir($output2, 'REI', 'BNG', '00071'), 'Directory created'); |
| 142 | ok(-d catdir($output2, 'REI', 'BNG', '00128'), 'Directory created'); |
| 143 | ok(!-d catdir($output2, 'REI', 'RBR', '00610'), 'Directory not created'); |
| 144 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 145 | |
| 146 | # Test with document sigle |
| 147 | $output2 = undef; |
| 148 | $output2 = tempdir(CLEANUP => 1); |
| 149 | |
| 150 | $call = join( |
| 151 | ' ', |
| 152 | 'perl', $script, |
| 153 | 'extract', |
| 154 | '--input' => $input_rei, |
| 155 | '--output' => $output2, |
| 156 | '-sg' => 'REI/BN*' |
| 157 | ); |
| 158 | |
| 159 | # Test with sigle |
| 160 | stdout_like( |
| 161 | sub { |
| 162 | system($call); |
| 163 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 164 | qr!REI/BN\* $sep extracted!s, |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 165 | $call |
| 166 | ); |
| 167 | |
| 168 | # Test with sigle |
| 169 | stdout_unlike( |
| 170 | sub { |
| 171 | system($call); |
| 172 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 173 | qr!REI/RBR $sep extracted!s, |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 174 | $call |
| 175 | ); |
| 176 | |
| 177 | ok(-d catdir($output2, 'REI', 'BNG', '00071'), 'Directory created'); |
| 178 | ok(-d catdir($output2, 'REI', 'BNG', '00128'), 'Directory created'); |
| 179 | ok(!-d catdir($output2, 'REI', 'RBR', '00610'), 'Directory not created'); |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 187 | # Check multiple archives |
| 188 | $output = tempdir(CLEANUP => 1); |
| 189 | ok(-d $output, 'Output directory exists'); |
| 190 | |
| 191 | $call = join( |
| 192 | ' ', |
| 193 | 'perl', $script, |
| 194 | 'extract', |
| 195 | '-i' => catfile($f, '..', 'corpus', 'archives', 'wpd15-single.zip'), |
| 196 | '-i' => catfile($f, '..', 'corpus', 'archives', 'wpd15-single.tree_tagger.zip'), |
| 197 | '-i' => catfile($f, '..', 'corpus', 'archives', 'wpd15-single.opennlp.zip'), |
| 198 | '--output' => $output |
| 199 | ); |
| 200 | |
| 201 | # Test with sigle |
| 202 | stdout_like( |
| 203 | sub { |
| 204 | system($call); |
| 205 | }, |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame^] | 206 | qr!WPD15/A00/00081 $sep extracted.!s, |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 207 | $call |
| 208 | ); |
| 209 | |
| 210 | ok(-d catdir($output, 'WPD15', 'A00', '00081'), 'Directory created'); |
| 211 | ok(-f catfile($output, 'WPD15', 'A00', 'header.xml'), 'Header file created'); |
| 212 | ok(-d catdir($output, 'WPD15', 'A00', '00081', 'base'), 'Directory created'); |
| 213 | |
| 214 | ok(-f catfile($output, 'WPD15', 'A00', '00081', 'tree_tagger', 'morpho.xml'), 'New archive'); |
| 215 | ok(-f catfile($output, 'WPD15', 'A00', '00081', 'opennlp', 'morpho.xml'), 'New archive'); |
| 216 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 217 | |
| 218 | done_testing; |
| 219 | __END__ |