]> git.refcnt.org Git - colorize.git/commitdiff
Move common data to a perl module
authorSteven Schubiger <stsc@refcnt.org>
Tue, 19 Jul 2016 11:54:47 +0000 (13:54 +0200)
committerSteven Schubiger <stsc@refcnt.org>
Tue, 19 Jul 2016 11:54:47 +0000 (13:54 +0200)
lib/Colorize/Common.pm [new file with mode: 0644]
t/fail.t
t/merge.t
test.pl

diff --git a/lib/Colorize/Common.pm b/lib/Colorize/Common.pm
new file mode 100644 (file)
index 0000000..e61450b
--- /dev/null
@@ -0,0 +1,45 @@
+package Colorize::Common;
+
+use strict;
+use warnings;
+use base qw(Exporter);
+use constant true => 1;
+
+use File::Temp qw(tempfile);
+
+our (@EXPORT_OK, %EXPORT_TAGS);
+my @defaults;
+
+@defaults    = qw($source $compiler);
+@EXPORT_OK   = (qw($compiler_flags %BUF_SIZE $write_to_tmpfile), @defaults);
+%EXPORT_TAGS = ('defaults' => [ @defaults ]);
+
+our ($source, $compiler, $compiler_flags, %BUF_SIZE, $write_to_tmpfile);
+
+#---------------#
+# START of data #
+#---------------#
+
+$source = 'colorize.c';
+$compiler = 'gcc';
+$compiler_flags = '-ansi -pedantic -Wall -Wextra -Wformat -Wswitch-default -Wuninitialized -Wunused -Wno-unused-function -Wno-unused-parameter';
+%BUF_SIZE = (
+    normal => 1024,
+    short  => 10,
+);
+$write_to_tmpfile = sub
+{
+    my ($content) = @_;
+
+    my ($fh, $tmpfile) = tempfile(UNLINK => true);
+    print {$fh} $content;
+    close($fh);
+
+    return $tmpfile;
+};
+
+#-------------#
+# END of data #
+#-------------#
+
+1;
index b7f0dcbcd5882982245fdf520ce817f66daee62d..a72e9ab9ad256e183329be60fab4db1529b5e56d 100755 (executable)
--- a/t/fail.t
+++ b/t/fail.t
@@ -2,30 +2,18 @@
 
 use strict;
 use warnings;
+use lib qw(lib);
 use constant true  => 1;
 use constant false => 0;
 
-use File::Temp qw(tempfile tempdir tmpnam);
+use Colorize::Common qw(:defaults $write_to_tmpfile);
+use File::Temp qw(tempdir tmpnam);
 use IPC::Open3 qw(open3);
 use Symbol qw(gensym);
 use Test::More;
 
 my $tests = 20;
 
-my $source = 'colorize.c';
-my $compiler = 'gcc';
-
-my $write_to_tmpfile = sub
-{
-    my ($content) = @_;
-
-    my ($fh, $tmpfile) = tempfile(UNLINK => true);
-    print {$fh} $content;
-    close($fh);
-
-    return $tmpfile;
-};
-
 my $run_program_fail = sub
 {
     my ($program, $args, $message) = @_;
index e2f0de6fa22757813c2055985ee673c0c8d62574..848c0223c035ba4d3d0499f3dae3eaba5e8fc15f 100755 (executable)
--- a/t/merge.t
+++ b/t/merge.t
@@ -2,9 +2,11 @@
 
 use strict;
 use warnings;
+use lib qw(lib);
 use constant true  => 1;
 use constant false => 0;
 
+use Colorize::Common ':defaults';
 use File::Temp qw(tmpnam);
 use Test::More;
 
@@ -94,8 +96,6 @@ $tests += @merge_fail;
 $tests += @buffer;
 $tests += @pushback;
 
-my $source = 'colorize.c';
-my $compiler = 'gcc';
 my %programs;
 
 my $compile = sub
diff --git a/test.pl b/test.pl
index 570a7b77c409ff2767555ada4a9db9f4eea7f6d2..476cb7a13ad9ff9468bded26b8ae049d8f69f1c9 100755 (executable)
--- a/test.pl
+++ b/test.pl
@@ -2,34 +2,17 @@
 
 use strict;
 use warnings;
+use lib qw(lib);
 use constant true  => 1;
 use constant false => 0;
 
-use File::Temp qw(tempfile tmpnam);
+use Colorize::Common qw(:defaults $compiler_flags %BUF_SIZE $write_to_tmpfile);
+use File::Temp qw(tmpnam);
 use Test::Harness qw(runtests);
 use Test::More;
 
 my $tests = 24;
 
-my %BUF_SIZE = (
-   normal => 1024,
-   short  => 10,
-);
-my $source = 'colorize.c';
-my $compiler = 'gcc';
-my $compiler_flags = '-ansi -pedantic -Wall -Wextra -Wformat -Wswitch-default -Wuninitialized -Wunused -Wno-unused-function -Wno-unused-parameter';
-
-my $write_to_tmpfile = sub
-{
-    my ($content) = @_;
-
-    my ($fh, $tmpfile) = tempfile(UNLINK => true);
-    print {$fh} $content;
-    close($fh);
-
-    return $tmpfile;
-};
-
 {
     my @test_files = glob('t/*.t');
     eval { runtests(@test_files) } or warn $@;