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; |
| 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 | 'extract' |
| 22 | ); |
| 23 | |
| 24 | # Test without parameters |
| 25 | stdout_like( |
| 26 | sub { |
| 27 | system($call); |
| 28 | }, |
| 29 | qr!extract.+?Extract KorAP-XML files!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 | 'extract', |
| 43 | '--input' => $input, |
| 44 | '--output' => $output, |
| 45 | ); |
| 46 | |
| 47 | # Test without compression |
| 48 | stdout_like( |
| 49 | sub { |
| 50 | system($call); |
| 51 | }, |
| 52 | qr!TEST/BSP/1 extracted.!s, |
| 53 | $call |
| 54 | ); |
| 55 | |
| 56 | ok(-d catdir($output, 'TEST', 'BSP', '1'), 'Directory created'); |
| 57 | ok(-d catdir($output, 'TEST', 'BSP', '1', 'base'), 'Directory created'); |
| 58 | ok(-d catdir($output, 'TEST', 'BSP', '1', 'sgbr'), 'Directory created'); |
| 59 | ok(-d catdir($output, 'TEST', 'BSP', '1', 'struct'), 'Directory created'); |
| 60 | ok(-f catfile($output, 'TEST', 'BSP', '1', 'data.xml'), 'File created'); |
| 61 | ok(-f catfile($output, 'TEST', 'BSP', '1', 'header.xml'), 'File created'); |
| 62 | ok(-d catdir($output, 'TEST', 'BSP', '2'), 'Directory created'); |
| 63 | ok(-d catdir($output, 'TEST', 'BSP', '3'), 'Directory created'); |
| 64 | |
| 65 | # Check sigles |
| 66 | my $output2 = tempdir(CLEANUP => 1); |
| 67 | ok(-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 |
| 79 | stdout_like( |
| 80 | sub { |
| 81 | system($call); |
| 82 | }, |
| 83 | qr!TEST/BSP/4 extracted.!s, |
| 84 | $call |
| 85 | ); |
| 86 | |
| 87 | # Test with sigle |
| 88 | stdout_unlike( |
| 89 | sub { |
| 90 | system($call); |
| 91 | }, |
| 92 | qr!TEST/BSP/5 extracted.!s, |
| 93 | $call |
| 94 | ); |
| 95 | |
| 96 | ok(!-d catdir($output2, 'TEST', 'BSP', '1'), 'Directory created'); |
| 97 | ok(!-d catdir($output2, 'TEST', 'BSP', '2'), 'Directory created'); |
| 98 | ok(!-d catdir($output2, 'TEST', 'BSP', '3'), 'Directory created'); |
| 99 | ok(-d catdir($output2, 'TEST', 'BSP', '4'), 'Directory created'); |
| 100 | ok(!-d catdir($output2, 'TEST', 'BSP', '5'), 'Directory created'); |
| 101 | |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 102 | # Check multiple archives |
| 103 | $output = tempdir(CLEANUP => 1); |
| 104 | ok(-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 |
| 117 | stdout_like( |
| 118 | sub { |
| 119 | system($call); |
| 120 | }, |
| 121 | qr!WPD15/A00/00081 extracted.!s, |
| 122 | $call |
| 123 | ); |
| 124 | |
| 125 | ok(-d catdir($output, 'WPD15', 'A00', '00081'), 'Directory created'); |
| 126 | ok(-f catfile($output, 'WPD15', 'A00', 'header.xml'), 'Header file created'); |
| 127 | ok(-d catdir($output, 'WPD15', 'A00', '00081', 'base'), 'Directory created'); |
| 128 | |
| 129 | ok(-f catfile($output, 'WPD15', 'A00', '00081', 'tree_tagger', 'morpho.xml'), 'New archive'); |
| 130 | ok(-f catfile($output, 'WPD15', 'A00', '00081', 'opennlp', 'morpho.xml'), 'New archive'); |
| 131 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 132 | |
| 133 | done_testing; |
| 134 | __END__ |