aboutsummaryrefslogtreecommitdiffstats
path: root/t/strip_and_check_elf_files.t
diff options
context:
space:
mode:
authorGuillaume Rousse <guillomovitch@mandriva.org>2010-01-01 22:39:14 +0000
committerGuillaume Rousse <guillomovitch@mandriva.org>2010-01-01 22:39:14 +0000
commita79ebc0315296dfe78e87230d17b6ecd6574e1c3 (patch)
tree358419fd72050993791f3128d058bd51f7f20a71 /t/strip_and_check_elf_files.t
parent6a8041abb31a149c32af13b576a1ebf1ec543cb6 (diff)
downloadspec-helper-a79ebc0315296dfe78e87230d17b6ecd6574e1c3.tar
spec-helper-a79ebc0315296dfe78e87230d17b6ecd6574e1c3.tar.gz
spec-helper-a79ebc0315296dfe78e87230d17b6ecd6574e1c3.tar.bz2
spec-helper-a79ebc0315296dfe78e87230d17b6ecd6574e1c3.tar.xz
spec-helper-a79ebc0315296dfe78e87230d17b6ecd6574e1c3.zip
rename test scripts with .t suffix
Diffstat (limited to 't/strip_and_check_elf_files.t')
-rwxr-xr-xt/strip_and_check_elf_files.t82
1 files changed, 82 insertions, 0 deletions
diff --git a/t/strip_and_check_elf_files.t b/t/strip_and_check_elf_files.t
new file mode 100755
index 0000000..1173c6c
--- /dev/null
+++ b/t/strip_and_check_elf_files.t
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+# $Id: gprintify 257533 2009-05-23 12:45:15Z guillomovitch $
+
+use strict;
+use warnings;
+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);
+
+($buildroot, $binary) = setup();
+
+$before = get_md5($binary);
+run($buildroot);
+$after = get_md5($binary);
+
+isnt(
+ $before,
+ $after,
+ 'binary should be modified'
+);
+
+($buildroot, $binary) = setup();
+
+$before = get_md5($binary);
+$ENV{EXCLUDE_FROM_STRIP} = 'test';
+run($buildroot);
+$after = get_md5($binary);
+
+is(
+ $before,
+ $after,
+ 'EXCLUDE_FROM_STRIP should prevent binary stripping'
+);
+
+sub setup {
+
+ my $source = File::Temp->new(UNLINK => 1, SUFFIX => '.c');
+ print $source <<'EOF';
+#include <stdio.h>
+
+int main()
+{
+ printf("Hello world!\n");
+ return 0;
+}
+EOF
+ close($source);
+
+ my $buildroot = tempdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1));
+ my $bindir = $buildroot . '/usr/bin';
+ my $binary = $bindir . '/test';
+ make_path($bindir);
+
+ system('gcc', '-o', $binary, $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();
+}