From a79ebc0315296dfe78e87230d17b6ecd6574e1c3 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse Date: Fri, 1 Jan 2010 22:39:14 +0000 Subject: rename test scripts with .t suffix --- t/gprintify | 151 ------------------------------------------ t/gprintify.t | 151 ++++++++++++++++++++++++++++++++++++++++++ t/strip_and_check_elf_files | 82 ----------------------- t/strip_and_check_elf_files.t | 82 +++++++++++++++++++++++ 4 files changed, 233 insertions(+), 233 deletions(-) delete mode 100755 t/gprintify create mode 100755 t/gprintify.t delete mode 100755 t/strip_and_check_elf_files create mode 100755 t/strip_and_check_elf_files.t diff --git a/t/gprintify b/t/gprintify deleted file mode 100755 index 9069d1d..0000000 --- a/t/gprintify +++ /dev/null @@ -1,151 +0,0 @@ -#!/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; - -my @string_results = ( - [ 'result: $foo', 'result: %s', ' "$foo"' ], - [ 'result: $foo,$bar', 'result: %s,%s', ' "$foo" "$bar"' ], - [ 'result: \$foo', 'result: \$foo', '' ], - [ 'result: \$foo,$bar', 'result: \$foo,%s', ' "$bar"' ], - [ 'result: ${foo}', 'result: %s', ' "${foo}"', '' ], - [ 'result: ${foo##*/}', 'result: %s', ' "${foo##*/}"' ], - [ 'result: ${foo%%*/}', 'result: %s', ' "${foo%%*/}"' ], - [ 'result: ${foo#*/}', 'result: %s', ' "${foo#*/}"' ], - [ 'result: ${foo%*/}', 'result: %s', ' "${foo%*/}"' ] -); -my @start_results = ( - [ 'echo "result: $foo"', 'gprintf "', '\n"' ], - [ '# echo "result: $foo"', '# gprintf "', '\n"' ], - [ 'echo -n "result: $foo"', 'gprintf "', '"' ], - [ 'echo -e "result: $foo"', 'gprintf "', '\n"' ], -); - -my @line_results = ( - [ - 'echo "result: $foo"' . "\n", - 'gprintf "result: %s\n" "$foo"' . "\n" - ], - [ - 'echo "result: \"$foo\""' . "\n", - 'gprintf "result: \"%s\"\n" "$foo"' . "\n" - ], - [ - 'test "$foo" != "AB"', - 'test "$foo" != "AB"', - ] -); - -plan tests => - 4 + (@string_results * 2) + (@start_results * 2) + (@line_results); - -# test loading -ok(require("gprintify"), "loading file OK"); - -# test string function -foreach my $result (@string_results) { - my ($new_string, $variables) = process_string($result->[0]); - is($new_string, $result->[1], "new string OK"); - is($variables, $result->[2], "variable OK"); -} - -# test start function -foreach my $result (@start_results) { - my ($new_start, $string_end) = process_start($result->[0]); - is($new_start, $result->[1], "new start OK"); - is($string_end, $result->[2], "string end OK"); -} - -# test line function -foreach my $result (@line_results) { - my ($new_line) = process_line($result->[0]); - is($new_line, $result->[1], "new line OK"); -} - -# test the script itself -my ($buildroot, $script, $before, $after); - -($buildroot, $script) = setup(<<'EOF'); -echo "Usage: $0 {start|stop|status}" -EOF - -$before = get_md5($script); -run($buildroot); -$after = get_md5($script); - -is( - $before, - $after, - 'service not sourcing /etc/init.d/functions should not be modified' -); - -($buildroot, $script) = setup(<<'EOF'); -. /etc/init.d/functions -echo "Usage: $0 {start|stop|status}" -EOF - -$before = get_md5($script); -run($buildroot); -$after = get_md5($script); - -isnt( - $before, - $after, - 'service sourcing /etc/init.d/functions should be modified' -); - -($buildroot, $script) = setup(<<'EOF'); -. /etc/init.d/functions -echo "Usage: $0 {start|stop|status}" -EOF - -$before = get_md5($script); -$ENV{EXCLUDE_FROM_GPRINTIFICATION} = 'test'; -run($buildroot); -$after = get_md5($script); - -is( - $before, - $after, - 'EXCLUDE_FROM_GPRINTIFICATION should prevent service modification' -); - -sub setup { - my ($content) = @_; - - my $buildroot = tempdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1)); - - my $initrddir = $buildroot . '/etc/rc.d/init.d'; - my $script = $initrddir . '/test'; - - make_path($initrddir); - open(my $out, '>', $script) or die "can't write to $script: $!"; - 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(); -} diff --git a/t/gprintify.t b/t/gprintify.t new file mode 100755 index 0000000..9069d1d --- /dev/null +++ b/t/gprintify.t @@ -0,0 +1,151 @@ +#!/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; + +my @string_results = ( + [ 'result: $foo', 'result: %s', ' "$foo"' ], + [ 'result: $foo,$bar', 'result: %s,%s', ' "$foo" "$bar"' ], + [ 'result: \$foo', 'result: \$foo', '' ], + [ 'result: \$foo,$bar', 'result: \$foo,%s', ' "$bar"' ], + [ 'result: ${foo}', 'result: %s', ' "${foo}"', '' ], + [ 'result: ${foo##*/}', 'result: %s', ' "${foo##*/}"' ], + [ 'result: ${foo%%*/}', 'result: %s', ' "${foo%%*/}"' ], + [ 'result: ${foo#*/}', 'result: %s', ' "${foo#*/}"' ], + [ 'result: ${foo%*/}', 'result: %s', ' "${foo%*/}"' ] +); +my @start_results = ( + [ 'echo "result: $foo"', 'gprintf "', '\n"' ], + [ '# echo "result: $foo"', '# gprintf "', '\n"' ], + [ 'echo -n "result: $foo"', 'gprintf "', '"' ], + [ 'echo -e "result: $foo"', 'gprintf "', '\n"' ], +); + +my @line_results = ( + [ + 'echo "result: $foo"' . "\n", + 'gprintf "result: %s\n" "$foo"' . "\n" + ], + [ + 'echo "result: \"$foo\""' . "\n", + 'gprintf "result: \"%s\"\n" "$foo"' . "\n" + ], + [ + 'test "$foo" != "AB"', + 'test "$foo" != "AB"', + ] +); + +plan tests => + 4 + (@string_results * 2) + (@start_results * 2) + (@line_results); + +# test loading +ok(require("gprintify"), "loading file OK"); + +# test string function +foreach my $result (@string_results) { + my ($new_string, $variables) = process_string($result->[0]); + is($new_string, $result->[1], "new string OK"); + is($variables, $result->[2], "variable OK"); +} + +# test start function +foreach my $result (@start_results) { + my ($new_start, $string_end) = process_start($result->[0]); + is($new_start, $result->[1], "new start OK"); + is($string_end, $result->[2], "string end OK"); +} + +# test line function +foreach my $result (@line_results) { + my ($new_line) = process_line($result->[0]); + is($new_line, $result->[1], "new line OK"); +} + +# test the script itself +my ($buildroot, $script, $before, $after); + +($buildroot, $script) = setup(<<'EOF'); +echo "Usage: $0 {start|stop|status}" +EOF + +$before = get_md5($script); +run($buildroot); +$after = get_md5($script); + +is( + $before, + $after, + 'service not sourcing /etc/init.d/functions should not be modified' +); + +($buildroot, $script) = setup(<<'EOF'); +. /etc/init.d/functions +echo "Usage: $0 {start|stop|status}" +EOF + +$before = get_md5($script); +run($buildroot); +$after = get_md5($script); + +isnt( + $before, + $after, + 'service sourcing /etc/init.d/functions should be modified' +); + +($buildroot, $script) = setup(<<'EOF'); +. /etc/init.d/functions +echo "Usage: $0 {start|stop|status}" +EOF + +$before = get_md5($script); +$ENV{EXCLUDE_FROM_GPRINTIFICATION} = 'test'; +run($buildroot); +$after = get_md5($script); + +is( + $before, + $after, + 'EXCLUDE_FROM_GPRINTIFICATION should prevent service modification' +); + +sub setup { + my ($content) = @_; + + my $buildroot = tempdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1)); + + my $initrddir = $buildroot . '/etc/rc.d/init.d'; + my $script = $initrddir . '/test'; + + make_path($initrddir); + open(my $out, '>', $script) or die "can't write to $script: $!"; + 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(); +} diff --git a/t/strip_and_check_elf_files b/t/strip_and_check_elf_files deleted file mode 100755 index 1173c6c..0000000 --- a/t/strip_and_check_elf_files +++ /dev/null @@ -1,82 +0,0 @@ -#!/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 - -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(); -} 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 + +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(); +} -- cgit v1.2.1