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