aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--t/Utils.pm30
-rwxr-xr-xt/fix_eol.t25
-rwxr-xr-xt/gprintify.t51
-rwxr-xr-xt/strip_and_check_elf_files.t49
4 files changed, 65 insertions, 90 deletions
diff --git a/t/Utils.pm b/t/Utils.pm
new file mode 100644
index 0000000..eef8187
--- /dev/null
+++ b/t/Utils.pm
@@ -0,0 +1,30 @@
+package Utils;
+
+use strict;
+use warnings;
+use base qw(Exporter);
+use FindBin qw/$Bin/;
+use Digest::MD5;
+
+our @EXPORT_OK = qw(run get_md5);
+
+
+sub run {
+ my ($buildroot, $program) = @_;
+
+ $ENV{RPM_BUILD_ROOT} = $buildroot;
+ system("$Bin/../$program");
+}
+
+
+sub get_md5 {
+ my ($file) = @_;
+ open(my $in, '<', $file) or die "can't read $file: $!";
+ binmode($in);
+ my $md5 = Digest::MD5->new();
+ $md5->addfile($in);
+ close($in);
+ return $md5->hexdigest();
+}
+
+1;
diff --git a/t/fix_eol.t b/t/fix_eol.t
index 9363769..b7c7e0f 100755
--- a/t/fix_eol.t
+++ b/t/fix_eol.t
@@ -3,12 +3,10 @@
use strict;
use warnings;
+use Utils qw/run get_md5/;
use Test::More;
use File::Temp qw/tempdir/;
use File::Path qw/make_path/;
-use FindBin qw/$Bin/;
-use lib "$Bin/../lib";
-use Digest::MD5;
plan tests => 2;
@@ -19,7 +17,7 @@ my ($buildroot, $test, $before, $after);
foo\r
EOF
$before = get_md5($test);
-run($buildroot);
+run($buildroot, 'fix_eol');
$after = get_md5($test);
isnt(
@@ -33,7 +31,7 @@ foo\r
EOF
$before = get_md5($test);
$ENV{EXCLUDE_FROM_EOL_CONVERSION} = 'test';
-run($buildroot);
+run($buildroot, 'fix_eol');
$after = get_md5($test);
is(
@@ -58,20 +56,3 @@ sub setup {
return ($buildroot, $test);
}
-
-sub run {
- my ($buildroot) = @_;
-
- $ENV{RPM_BUILD_ROOT} = $buildroot;
- system("$Bin/../fix_eol");
-}
-
-sub get_md5 {
- my ($file) = @_;
- open(my $in, '<', $file) or die "can't read $file: $!";
- binmode($in);
- my $md5 = Digest::MD5->new();
- $md5->addfile($in);
- close($in);
- return $md5->hexdigest();
-}
diff --git a/t/gprintify.t b/t/gprintify.t
index 9069d1d..b71b212 100755
--- a/t/gprintify.t
+++ b/t/gprintify.t
@@ -3,12 +3,12 @@
use strict;
use warnings;
+use Utils qw/run get_md5/;
use Test::More;
use File::Temp qw/tempdir/;
use File::Path qw/make_path/;
use FindBin qw/$Bin/;
use lib "$Bin/../lib";
-use Digest::MD5;
my @string_results = (
[ 'result: $foo', 'result: %s', ' "$foo"' ],
@@ -70,15 +70,15 @@ foreach my $result (@line_results) {
}
# test the script itself
-my ($buildroot, $script, $before, $after);
+my ($buildroot, $test, $before, $after);
-($buildroot, $script) = setup(<<'EOF');
+($buildroot, $test) = setup(<<'EOF');
echo "Usage: $0 {start|stop|status}"
EOF
-$before = get_md5($script);
-run($buildroot);
-$after = get_md5($script);
+$before = get_md5($test);
+run($buildroot, 'gprintify');
+$after = get_md5($test);
is(
$before,
@@ -86,14 +86,14 @@ is(
'service not sourcing /etc/init.d/functions should not be modified'
);
-($buildroot, $script) = setup(<<'EOF');
+($buildroot, $test) = setup(<<'EOF');
. /etc/init.d/functions
echo "Usage: $0 {start|stop|status}"
EOF
-$before = get_md5($script);
-run($buildroot);
-$after = get_md5($script);
+$before = get_md5($test);
+run($buildroot, 'gprintify');
+$after = get_md5($test);
isnt(
$before,
@@ -101,15 +101,15 @@ isnt(
'service sourcing /etc/init.d/functions should be modified'
);
-($buildroot, $script) = setup(<<'EOF');
+($buildroot, $test) = setup(<<'EOF');
. /etc/init.d/functions
echo "Usage: $0 {start|stop|status}"
EOF
-$before = get_md5($script);
+$before = get_md5($test);
$ENV{EXCLUDE_FROM_GPRINTIFICATION} = 'test';
-run($buildroot);
-$after = get_md5($script);
+run($buildroot, 'gprintify');
+$after = get_md5($test);
is(
$before,
@@ -123,29 +123,12 @@ sub setup {
my $buildroot = tempdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1));
my $initrddir = $buildroot . '/etc/rc.d/init.d';
- my $script = $initrddir . '/test';
+ my $test = $initrddir . '/test';
make_path($initrddir);
- open(my $out, '>', $script) or die "can't write to $script: $!";
+ open(my $out, '>', $test) or die "can't write to $test: $!";
print $out $content;
close($out);
- return ($buildroot, $script);
-}
-
-sub run {
- my ($buildroot) = @_;
-
- $ENV{RPM_BUILD_ROOT} = $buildroot;
- system("$Bin/../gprintify");
-}
-
-sub get_md5 {
- my ($file) = @_;
- open(my $in, '<', $file) or die "can't read $file: $!";
- binmode($in);
- my $md5 = Digest::MD5->new();
- $md5->addfile($in);
- close($in);
- return $md5->hexdigest();
+ return ($buildroot, $test);
}
diff --git a/t/strip_and_check_elf_files.t b/t/strip_and_check_elf_files.t
index 1173c6c..6975da8 100755
--- a/t/strip_and_check_elf_files.t
+++ b/t/strip_and_check_elf_files.t
@@ -3,41 +3,39 @@
use strict;
use warnings;
+use Utils qw/run get_md5/;
use Test::More;
use File::Temp qw/tempdir/;
use File::Path qw/make_path/;
-use FindBin qw/$Bin/;
-use lib "$Bin/../lib";
-use Digest::MD5;
plan tests => 2;
# test the script itself
-my ($buildroot, $binary, $before, $after);
+my ($buildroot, $test, $before, $after);
-($buildroot, $binary) = setup();
+($buildroot, $test) = setup();
-$before = get_md5($binary);
-run($buildroot);
-$after = get_md5($binary);
+$before = get_md5($test);
+run($buildroot, 'strip_and_check_elf_files');
+$after = get_md5($test);
isnt(
$before,
$after,
- 'binary should be modified'
+ 'test should be modified'
);
-($buildroot, $binary) = setup();
+($buildroot, $test) = setup();
-$before = get_md5($binary);
+$before = get_md5($test);
$ENV{EXCLUDE_FROM_STRIP} = 'test';
-run($buildroot);
-$after = get_md5($binary);
+run($buildroot, 'strip_and_check_elf_files');
+$after = get_md5($test);
is(
$before,
$after,
- 'EXCLUDE_FROM_STRIP should prevent binary stripping'
+ 'EXCLUDE_FROM_STRIP should prevent test stripping'
);
sub setup {
@@ -56,27 +54,10 @@ EOF
my $buildroot = tempdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1));
my $bindir = $buildroot . '/usr/bin';
- my $binary = $bindir . '/test';
+ my $test = $bindir . '/test';
make_path($bindir);
- system('gcc', '-o', $binary, $source);
+ system('gcc', '-o', $test, $source);
- return ($buildroot, $binary);
-}
-
-sub run {
- my ($buildroot) = @_;
-
- $ENV{RPM_BUILD_ROOT} = $buildroot;
- system("$Bin/../strip_and_check_elf_files");
-}
-
-sub get_md5 {
- my ($file) = @_;
- open(my $in, '<', $file) or die "can't read $file: $!";
- binmode($in);
- my $md5 = Digest::MD5->new();
- $md5->addfile($in);
- close($in);
- return $md5->hexdigest();
+ return ($buildroot, $test);
}