Added test for sigles support in extract
Change-Id: I5f5596a88da6314f0d1f7e8299fef7425f89a52f
diff --git a/t/script/extract.t b/t/script/extract.t
new file mode 100644
index 0000000..4429a08
--- /dev/null
+++ b/t/script/extract.t
@@ -0,0 +1,113 @@
+#/usr/bin/env perl
+use strict;
+use warnings;
+use File::Basename 'dirname';
+use File::Spec::Functions qw/catdir catfile/;
+use File::Temp qw/tempdir/;
+use Mojo::Util qw/slurp/;
+use Mojo::JSON qw/decode_json/;
+use IO::Uncompress::Gunzip;
+use Test::More;
+use Test::Output;
+use Data::Dumper;
+use utf8;
+
+my $f = dirname(__FILE__);
+my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
+
+my $call = join(
+ ' ',
+ 'perl', $script,
+ 'extract'
+);
+
+# Test without parameters
+stdout_like(
+ sub {
+ system($call);
+ },
+ qr!extract.+?Extract KorAP-XML files!s,
+ $call
+);
+
+my $input = catfile($f, '..', 'corpus', 'archive.zip');
+ok(-f $input, 'Input archive found');
+
+my $output = tempdir(CLEANUP => 1);
+ok(-d $output, 'Output directory exists');
+
+$call = join(
+ ' ',
+ 'perl', $script,
+ 'extract',
+ '--input' => $input,
+ '--output' => $output,
+);
+
+# Test without compression
+stdout_like(
+ sub {
+ system($call);
+ },
+ qr!TEST/BSP/1 extracted.!s,
+ $call
+);
+
+ok(-d catdir($output, 'TEST', 'BSP', '1'), 'Directory created');
+ok(-d catdir($output, 'TEST', 'BSP', '1', 'base'), 'Directory created');
+ok(-d catdir($output, 'TEST', 'BSP', '1', 'sgbr'), 'Directory created');
+ok(-d catdir($output, 'TEST', 'BSP', '1', 'struct'), 'Directory created');
+ok(-f catfile($output, 'TEST', 'BSP', '1', 'data.xml'), 'File created');
+ok(-f catfile($output, 'TEST', 'BSP', '1', 'header.xml'), 'File created');
+ok(-d catdir($output, 'TEST', 'BSP', '2'), 'Directory created');
+ok(-d catdir($output, 'TEST', 'BSP', '3'), 'Directory created');
+
+# Check sigles
+my $output2 = tempdir(CLEANUP => 1);
+ok(-d $output2, 'Output directory exists');
+
+$call = join(
+ ' ',
+ 'perl', $script,
+ 'extract',
+ '--input' => $input,
+ '--output' => $output2,
+ '-sg' => 'TEST/BSP/4'
+);
+
+# Test with sigle
+stdout_like(
+ sub {
+ system($call);
+ },
+ qr!TEST/BSP/4 extracted.!s,
+ $call
+);
+
+# Test with sigle
+stdout_unlike(
+ sub {
+ system($call);
+ },
+ qr!TEST/BSP/5 extracted.!s,
+ $call
+);
+
+ok(!-d catdir($output2, 'TEST', 'BSP', '1'), 'Directory created');
+ok(!-d catdir($output2, 'TEST', 'BSP', '2'), 'Directory created');
+ok(!-d catdir($output2, 'TEST', 'BSP', '3'), 'Directory created');
+ok(-d catdir($output2, 'TEST', 'BSP', '4'), 'Directory created');
+ok(!-d catdir($output2, 'TEST', 'BSP', '5'), 'Directory created');
+
+
+done_testing;
+__END__
+
+
+
+
+
+# Test sigle!
+# Test multiple archives
+
+
diff --git a/t/script/single.t b/t/script/single.t
index a05e5e9..9d8d28f 100644
--- a/t/script/single.t
+++ b/t/script/single.t
@@ -203,8 +203,6 @@
is($json->{keywords}, 'sgbrKodex:T', 'keywords');
is($json->{publisher}, 'Dorfblatt GmbH', 'publisher');
-# Test sigle!
-
done_testing;
__END__