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