From b2943eeed10a5cf4ef43e97bcf289b5d4665f010 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 15 Nov 2014 12:13:40 +0100 Subject: [PATCH] tests: Move helper funtion to common.inc Also fixes md5fh's fd leak. --- tests/common.inc | 14 ++++++++++++++ tests/normal.pl | 13 ++----------- 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 tests/common.inc diff --git a/tests/common.inc b/tests/common.inc new file mode 100644 index 0000000..1d597f7 --- /dev/null +++ b/tests/common.inc @@ -0,0 +1,14 @@ +# Helper function +# Get the MD5 sum of the file open at the filehandle +sub md5fh +{ + my $fh_orig = shift; + open(my $fh, "<&", $fh_orig); # Duplicate the file handle so the seek + seek($fh, 0, 0); # does not affect the caller + my $md5 = Digest::MD5->new->addfile($fh)->hexdigest; + close($fh); + return $md5; +} + +# As this file will be require()'d, it needs to return true +return 1; diff --git a/tests/normal.pl b/tests/normal.pl index fcefc9c..6d0658b 100644 --- a/tests/normal.pl +++ b/tests/normal.pl @@ -9,6 +9,8 @@ use File::Temp; use IO::Handle; use Digest::MD5 qw(md5_hex); +require("tests/common.inc"); + my $tempDir = $ENV{'TMPDIR'} || "/tmp"; # run unit tests @@ -268,17 +270,6 @@ sub encName return $enc; } -# Helper function -# Get the MD5 sum of the file open at the filehandle -sub md5fh -{ - my $fh_orig = shift; - open(my $fh, "<&", $fh_orig); # Duplicate the file handle so the seek - seek($fh, 0, 0); # does not affect the caller - return Digest::MD5->new->addfile($fh)->hexdigest; - close($fh); -} - # Test symlinks & hardlinks sub links {