diff options
author | Guillaume Rousse <guillomovitch@mandriva.org> | 2010-01-01 23:04:03 +0000 |
---|---|---|
committer | Guillaume Rousse <guillomovitch@mandriva.org> | 2010-01-01 23:04:03 +0000 |
commit | 13710e05cbe37fb5048cdc76520818252f411447 (patch) | |
tree | 583fa44bf79397c25f4d230086b20ea9d5b3b9a8 | |
parent | cbdd86445bb77f0632c65aeeec57a39bf5dc5e83 (diff) | |
download | spec-helper-13710e05cbe37fb5048cdc76520818252f411447.tar spec-helper-13710e05cbe37fb5048cdc76520818252f411447.tar.gz spec-helper-13710e05cbe37fb5048cdc76520818252f411447.tar.bz2 spec-helper-13710e05cbe37fb5048cdc76520818252f411447.tar.xz spec-helper-13710e05cbe37fb5048cdc76520818252f411447.zip |
initial import
-rwxr-xr-x | t/fix_eol.t | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/t/fix_eol.t b/t/fix_eol.t new file mode 100755 index 0000000..9363769 --- /dev/null +++ b/t/fix_eol.t @@ -0,0 +1,77 @@ +#!/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, $test, $before, $after); + +($buildroot, $test) = setup(<<EOF); +foo\r +EOF +$before = get_md5($test); +run($buildroot); +$after = get_md5($test); + +isnt( + $before, + $after, + 'script should be modified' +); + +($buildroot, $test) = setup(<<EOF); +foo\r +EOF +$before = get_md5($test); +$ENV{EXCLUDE_FROM_EOL_CONVERSION} = 'test'; +run($buildroot); +$after = get_md5($test); + +is( + $before, + $after, + 'EXCLUDE_FROM_EOL_CONVERSION should prevent end-of-line conversion' +); + +sub setup { + my ($content) = @_; + + my $buildroot = tempdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1)); + + my $initrddir = $buildroot . '/etc/rc.d/init.d'; + my $datadir = $buildroot . '/usr/share'; + my $test = $datadir . '/test'; + + make_path($datadir); + open(my $out, '>', $test) or die "can't write to $test: $!"; + print $out $content; + close($out); + + 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(); +} |