Add tests for compression, and a CLI tool for manual testing.
authorQuim Rovira <quim@rovira.cat>
Sun, 14 Aug 2016 09:38:41 +0000 (11:38 +0200)
committerQuim Rovira <quim@rovira.cat>
Sun, 14 Aug 2016 09:46:30 +0000 (11:46 +0200)
I changed the names of the tests, so that compress round-trip runs
after the uncompress tests.

Also added a cli tool that tries to follow the official /bro/ cli tool,
but it's use is mostly for validation and testing, and is still missing
support for many of the flags (eg. --repeat).

For this, I moved the File::Slurp module to an actual dependency, not
a tests-only dep.

Makefile.PL
README
bin/bro-perl [new file with mode: 0755]
t/00-load.t [new file with mode: 0644]
t/01-uncompress.t [new file with mode: 0644]
t/02-roundtrip.t [new file with mode: 0644]
t/IO-Compress-Brotli.t [deleted file]
t/IO-Uncompress-Brotli.t [deleted file]

index e2649e74e7baba2efb109441060de7bdc12ac9ec..79ea79acb60a731e806975d882c07def1d06c747 100644 (file)
@@ -9,10 +9,12 @@ WriteMakefile(
        MIN_PERL_VERSION => '5.14.0',
        LICENSE          => 'perl',
        SIGN             => 1,
-       PREREQ_PM        => {},
-       BUILD_REQUIRES   => {
-               qw/File::Slurp 0/,
+       EXE_FILES        => [ 'bin/bro-perl' ],
+       PREREQ_PM        => {
+               'File::Slurp'  => '9999.19',
+               'Getopt::Long' => '2.45',
        },
+       BUILD_REQUIRES   => {},
        INC              => '-Ibrotli',
        MYEXTLIB         => 'brotli/libbrotli$(LIB_EXT)',
        clean            => { FILES => 'brotli/libbrotli$(LIB_EXT)' },
diff --git a/README b/README
index 858d0d5a6093c0634bc91ad620f06ec12632458d..17f6a76769ba3b69d5e4218be66ad7874703cfe5 100644 (file)
--- a/README
+++ b/README
@@ -24,7 +24,8 @@ DEPENDENCIES
 
 This module requires these other modules and libraries:
 
-* File::Slurp (only used for testing)
+* File::Slurp
+* Getopt::Long
 
 Additionally, it requires a C compiler.
 
diff --git a/bin/bro-perl b/bin/bro-perl
new file mode 100755 (executable)
index 0000000..89a4e00
--- /dev/null
@@ -0,0 +1,75 @@
+#!perl
+#
+
+use warnings;
+use strict;
+use 5.014;
+
+use File::Slurp;
+use Getopt::Long;
+
+use IO::Compress::Brotli;
+use IO::Uncompress::Brotli;
+
+GetOptions(
+    'c|custom-dictionary=s' => \(my $DICTIONARY),
+    'd|decompress'          => \(my $DECOMPRESS),
+    'h|help'                => \(my $HELP),
+    'i|input=s'             => \(my $INPUT),
+    'o|output=s'            => \(my $OUTPUT),
+    'q|quality=i'           => \(my $QUALITY = 11),
+    'r|repeat=i'            => \(my $REPEAT),
+    's|stream=i'            => \(my $STREAM),
+    'v|verbose'             => \(my $VERBOSE),
+    'w|window=i'            => \(my $WINDOW = 22),
+);
+
+if( $HELP ) {
+    say "Usage: $0 [--force] [--quality n] [--decompress] [--input filename] [--output filename]".
+        " [--repeat iters] [--verbose] [--window n] [--custom-dictionary filename] [--stream size]";
+    exit 1;
+}
+
+my ($ifh, $ofh) = (\*STDIN, \*STDOUT);
+
+if( $INPUT ) {
+    open $ifh, "<", $INPUT
+        or die "Cannot open input file $INPUT.\n";
+}
+binmode $ifh;
+
+if( $OUTPUT ) {
+    open $ofh, ">", $OUTPUT
+        or die "Cannot open output file $OUTPUT.\n";
+}
+binmode $ofh;
+
+if( $DECOMPRESS ) {
+    if( $STREAM ) {
+        my $brotli = IO::Uncompress::Brotli->create();
+        while( read $ifh, (my $buf), $STREAM ) {
+            print $ofh $brotli->decompress($buf);
+        }
+    }
+    else {
+        my $encoded = read_file( $ifh );
+        my $decoded = unbro( $encoded );
+        write_file( $ofh, $decoded );
+    }
+}
+else {
+    if( $STREAM ) {
+        my $brotli = IO::Compress::Brotli->create();
+        $brotli->quality( $QUALITY );
+        $brotli->window( $WINDOW );
+        while( read $ifh, (my $buf), $STREAM ) {
+            print $ofh $brotli->compress($buf);
+        }
+    }
+    else {
+        my $decoded = read_file( $ifh );
+        my $encoded = bro( $decoded, $QUALITY, $WINDOW );
+        write_file( $ofh, $encoded );
+    }
+}
+
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644 (file)
index 0000000..a0a534c
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use v5.14;
+use warnings;
+
+use Test::More tests => 2;
+
+BEGIN {
+    use_ok('IO::Compress::Brotli');
+    use_ok('IO::Uncompress::Brotli');
+}
diff --git a/t/01-uncompress.t b/t/01-uncompress.t
new file mode 100644 (file)
index 0000000..fe2fe3a
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+use v5.14;
+use warnings;
+
+use Test::More tests => 80;
+use File::Slurp;
+
+use IO::Uncompress::Brotli;
+
+my $todo_re = qr/empty\.compressed\.(?:1[7-9]|2)|x\.compressed\.0[12]/;
+
+for my $test (<brotli/tests/testdata/*.compressed*>) {
+       my ($expected) = $test =~ s/\.compressed.*//r;
+       $expected = read_file $expected;
+
+       if($test !~ $todo_re) {
+               my $decoded = unbro (scalar read_file $test);
+               is $decoded, $expected, "$test";
+       }
+
+       open FH, '<', $test;
+       my $unbro = IO::Uncompress::Brotli->create;
+       my ($buf, $out);
+       until (eof FH) {
+               read FH, $buf, 100;
+               $out .= $unbro->decompress($buf);
+       }
+       is $out, $expected, "$test (streaming)";
+}
diff --git a/t/02-roundtrip.t b/t/02-roundtrip.t
new file mode 100644 (file)
index 0000000..16407d1
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+use v5.14;
+use warnings;
+
+use Test::More tests => 114;
+use File::Slurp;
+
+use IO::Compress::Brotli;
+use IO::Uncompress::Brotli;
+
+for my $test (<brotli/tests/testdata/*.compressed>) {
+       my ($source) = $test =~ s/\.compressed$//r;
+       $source = read_file $source;
+
+    for my $quality (9,11) {
+        my $encoded = bro($source, $quality);
+        my $decoded = unbro($encoded);
+
+        is $decoded, $source, "$test - quality $quality";
+    }
+
+    for my $quality (1,5,9,11) {
+               my $enc = IO::Compress::Brotli->create;
+               $enc->quality($quality);
+        my $encoded = $enc->compress($source, 1);
+        $encoded .= $enc->finish();
+
+               my $dec = IO::Uncompress::Brotli->create;
+        my $decoded = $dec->decompress($encoded);
+
+        is $decoded, $source, "$test - streaming / quality $quality";
+    }
+}
diff --git a/t/IO-Compress-Brotli.t b/t/IO-Compress-Brotli.t
deleted file mode 100644 (file)
index c732120..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# Before 'make install' is performed this script should be runnable with
-# 'make test'. After 'make install' it should work as 'perl IO-Compress-Brotli.t'
-
-#########################
-
-# change 'tests => 1' to 'tests => last_test_to_print';
-
-use strict;
-use warnings;
-
-use Test::More tests => 1;
-BEGIN { use_ok('IO::Compress::Brotli') };
-
-#########################
-
-# Insert your test code below, the Test::More module is use()ed here so read
-# its man page ( perldoc Test::More ) for help writing this test script.
-
diff --git a/t/IO-Uncompress-Brotli.t b/t/IO-Uncompress-Brotli.t
deleted file mode 100644 (file)
index 94141c1..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/perl
-use v5.14;
-use warnings;
-
-use Test::More tests => 81;
-use File::Slurp;
-BEGIN{ use_ok('IO::Uncompress::Brotli'); }
-
-my $todo_re = qr/empty\.compressed\.(?:1[7-9]|2)|x\.compressed\.0[12]/;
-
-for my $test (<brotli/tests/testdata/*.compressed*>) {
-       my ($expected) = $test =~ s/\.compressed.*//r;
-       $expected = read_file $expected;
-
-       if($test !~ $todo_re) {
-               my $decoded = unbro (scalar read_file $test);
-               is $decoded, $expected, "$test";
-       }
-
-       open FH, '<', $test;
-       my $unbro = IO::Uncompress::Brotli->create;
-       my ($buf, $out);
-       until (eof FH) {
-               read FH, $buf, 100;
-               $out .= $unbro->decompress($buf);
-       }
-       is $out, $expected, "$test (streaming)";
-}
This page took 0.016047 seconds and 4 git commands to generate.