diff --git a/Graphics-TIFF-8-Use-temporary-directories-to-enable-parallel-testing.patch b/Graphics-TIFF-8-Use-temporary-directories-to-enable-parallel-testing.patch new file mode 100644 index 0000000..e9c7d3b --- /dev/null +++ b/Graphics-TIFF-8-Use-temporary-directories-to-enable-parallel-testing.patch @@ -0,0 +1,314 @@ +From b588eb92546a18a87d710f281668de306972acd1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Tue, 9 Feb 2021 13:54:11 +0100 +Subject: [PATCH] Use temporary directories to enable parallel testing +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +If tests are performed in parallel (e.g. "prove -b -j4"), the tests +randomly fail because they stumble on their same-named temporary files +(e.g. "test.tif"). + +This patch fixes it by using putting the temporary files into +temporary, uniquely-named directories. The directories are +automatically cleaned on perl exit. + +Signed-off-by: Petr Písař +--- + Makefile.PL | 2 ++ + t/1.t | 28 ++++++++++++++++------------ + t/2.t | 9 ++++++--- + t/92_tiffinfo.t | 45 ++++++++++++++++++++++++--------------------- + t/93_tiff2pdf.t | 12 +++++++----- + 5 files changed, 55 insertions(+), 41 deletions(-) + +diff --git a/Makefile.PL b/Makefile.PL +index 8c2caed..8bc3a6e 100644 +--- a/Makefile.PL ++++ b/Makefile.PL +@@ -40,6 +40,8 @@ WriteMakefile( + 'ExtUtils::PkgConfig' => 0 + }, + TEST_REQUIRES => { ++ 'File::Spec' => 0, ++ 'File::Temp' => 0.19, + 'Test::More' => 0, + 'Test::Requires' => 0, + 'Test::Deep' => 0, +diff --git a/t/1.t b/t/1.t +index 7b8dbdc..955a6a3 100644 +--- a/t/1.t ++++ b/t/1.t +@@ -5,6 +5,8 @@ use Test::More tests => 49; + use Test::Deep; + use IPC::Cmd qw(can_run); + use Test::Requires qw( Image::Magick ); ++use File::Temp; ++use File::Spec; + BEGIN { use_ok('Graphics::TIFF') } + + ######################### +@@ -21,14 +23,16 @@ if ( $version < 4.000003 ) { + + ok( Graphics::TIFF->IsCODECConfigured(COMPRESSION_DEFLATE), + 'IsCODECConfigured' ); ++my $directory = File::Temp->newdir; + + my $image = Image::Magick->new; ++my $file = File::Spec->catfile( $directory, 'test.tif' ); + $image->Read('rose:'); + $image->Set( density => '72x72' ); +-$image->Write('test.tif'); ++$image->Write($file); + +-my $tif = Graphics::TIFF->Open( 'test.tif', 'r' ); +-is( $tif->FileName, 'test.tif', 'FileName' ); ++my $tif = Graphics::TIFF->Open( $file, 'r' ); ++is( $tif->FileName, $file, 'FileName' ); + isa_ok $tif, 'Graphics::TIFF'; + can_ok $tif, qw(Close ReadDirectory GetField); + +@@ -106,7 +110,7 @@ is( length( $tif->ReadRawStrip( 1, 20 ) ), 20, 'ReadRawStrip' ); + + is( $tif->ReadTile( 0, 0, 0, 0 ), undef, 'ReadTile' ); + +-my $filename = 'out.txt'; ++my $filename = File::Spec->catfile( $directory, 'out.txt' ); + open my $fh, '>', $filename; + $tif->PrintDirectory( $fh, 0 ); + $tif->Close; +@@ -119,8 +123,9 @@ unlink $filename; + SKIP: { + skip 'tiffcmp not installed', 1 if ( not can_run('tiffcmp') ); + +- my $tif = Graphics::TIFF->Open( 'test.tif', 'r' ); +- my $out = Graphics::TIFF->Open( 'test2.tif', 'w' ); ++ my $tif = Graphics::TIFF->Open( $file, 'r' ); ++ my $file2 = File::Spec->catfile($directory, 'test2.tif'); ++ my $out = Graphics::TIFF->Open( $file2, 'w' ); + for my $tag ( + ( TIFFTAG_IMAGEWIDTH, TIFFTAG_IMAGELENGTH, + TIFFTAG_SAMPLESPERPIXEL, TIFFTAG_BITSPERSAMPLE, +@@ -145,7 +150,7 @@ SKIP: { + $tif->Close; + $out->Close; + +- is( `tiffcmp test.tif test2.tif`, '', 'tiffcmp' ); ++ is( `tiffcmp $file $file2`, '', 'tiffcmp' ); + } + + ######################### +@@ -153,8 +158,8 @@ SKIP: { + $image = Image::Magick->new; + $image->Read('rose:'); + $image->Set( density => '72x72', alpha => 'Set' ); +-$image->Write('test.tif'); +-$tif = Graphics::TIFF->Open( 'test.tif', 'r' ); ++$image->Write($file); ++$tif = Graphics::TIFF->Open( $file, 'r' ); + + my @values = $tif->GetField(TIFFTAG_EXTRASAMPLES); + is_deeply( \@values, [EXTRASAMPLE_UNASSALPHA], +@@ -171,8 +176,8 @@ $tif->Close; + $image = Image::Magick->new; + $image->Read('rose:'); + $image->Set( density => '72x72', type => 'palette', depth => 2 ); +-$image->Write('test.tif'); +-$tif = Graphics::TIFF->Open( 'test.tif', 'r' ); ++$image->Write($file); ++$tif = Graphics::TIFF->Open( $file, 'r' ); + + @values = $tif->GetField(TIFFTAG_COLORMAP); + is $#{ $values[0] }, 255, 'GetField TIFFTAG_COLORMAP r'; +@@ -188,4 +193,3 @@ $tif->Close; + + ######################### + +-unlink 'test.tif', 'test2.tif'; +diff --git a/t/2.t b/t/2.t +index 2019888..377b0f3 100644 +--- a/t/2.t ++++ b/t/2.t +@@ -3,6 +3,8 @@ use strict; + use Graphics::TIFF ':all'; + use Test::More tests => 12; + use Test::Deep; ++use File::Temp; ++use File::Spec; + BEGIN { use_ok('Graphics::TIFF') } + + ######################### +@@ -19,6 +21,7 @@ if ( $version < 4.000003 ) { + + ok( Graphics::TIFF->IsCODECConfigured(COMPRESSION_DEFLATE), + 'IsCODECConfigured' ); ++my $directory = File::Temp->newdir; + + ######################### + +@@ -38,7 +41,8 @@ for my $i ( 0 .. $buffer_size - 1 ) { + my $expected = pack "C*", @buffer; + + # write TIFF +-my $tif = Graphics::TIFF->Open( 'test.tif', 'w' ); ++my $file = File::Spec->catfile( $directory, 'test.tif' ); ++my $tif = Graphics::TIFF->Open( $file, 'w' ); + $tif->SetField( TIFFTAG_IMAGEWIDTH, $width ); + $tif->SetField( TIFFTAG_IMAGELENGTH, $height ); + $tif->SetField( TIFFTAG_SAMPLESPERPIXEL, $depth ); +@@ -51,7 +55,7 @@ $tif->WriteDirectory; + $tif->Close; + + # read TIFF +-$tif = Graphics::TIFF->Open( 'test.tif', 'r' ); ++$tif = Graphics::TIFF->Open( $file, 'r' ); + my $stripsize = $tif->StripSize; + my $example = ''; + for my $i ( 0 .. $tif->NumberOfStrips - 1 ) { +@@ -71,4 +75,3 @@ $tif->Close; + + ######################### + +-unlink 'test.tif'; +diff --git a/t/92_tiffinfo.t b/t/92_tiffinfo.t +index 41bca2b..dd2eb02 100644 +--- a/t/92_tiffinfo.t ++++ b/t/92_tiffinfo.t +@@ -4,6 +4,8 @@ use English; + use IPC::Cmd qw(can_run); + use Test::More; + use Test::Requires qw( v5.10 Image::Magick ); ++use File::Temp; ++use File::Spec; + + ######################### + +@@ -15,59 +17,60 @@ else { + exit; + } + ++my $directory = File::Temp->newdir; ++my $file = File::Spec->catfile( $directory, 'test.tif' ); + my $image = Image::Magick->new; + $image->Read( 'rose:', 'rose:' ); + $image->Set( density => '72x72' ); +-$image->Write('test.tif'); ++$image->Write($file); + my $cmd = 'PERL5LIB="blib:blib/arch:lib:$PERL5LIB" ' + . "$EXECUTABLE_NAME examples/tiffinfo.pl"; + +-is( `$cmd test.tif`, `tiffinfo test.tif`, 'basic multi-directory' ); ++is( `$cmd $file`, `tiffinfo $file`, 'basic multi-directory' ); + +-is( `$cmd -2 test.tif`, `tiffinfo -2 test.tif`, 'dirnum' ); ++is( `$cmd -2 $file`, `tiffinfo -2 $file`, 'dirnum' ); + + $image = Image::Magick->new; + $image->Read('rose:'); + $image->Set( density => '72x72' ); +-$image->Write('test.tif'); ++$image->Write($file); + +-is( `$cmd -d test.tif`, `tiffinfo -d test.tif`, '-d' ); ++is( `$cmd -d $file`, `tiffinfo -d $file`, '-d' ); + +-is( `$cmd -D test.tif`, `tiffinfo -D test.tif`, '-D' ); ++is( `$cmd -D $file`, `tiffinfo -D $file`, '-D' ); + + is( +- `$cmd -d -f lsb2msb test.tif`, +- `tiffinfo -d -f lsb2msb test.tif`, ++ `$cmd -d -f lsb2msb $file`, ++ `tiffinfo -d -f lsb2msb $file`, + '-f lsb2msb' + ); + + is( +- `$cmd -d -f msb2lsb test.tif`, +- `tiffinfo -d -f msb2lsb test.tif`, ++ `$cmd -d -f msb2lsb $file`, ++ `tiffinfo -d -f msb2lsb $file`, + '-f msb2lsb' + ); + +-is( `$cmd -c test.tif`, `tiffinfo -c test.tif`, '-c' ); ++is( `$cmd -c $file`, `tiffinfo -c $file`, '-c' ); + +-is( `$cmd -i test.tif`, `tiffinfo -i test.tif`, '-i' ); ++is( `$cmd -i $file`, `tiffinfo -i $file`, '-i' ); + +-is( `$cmd -o 2 test.tif 2>&1`, `tiffinfo -o 2 test.tif 2>&1`, '-o' ); ++is( `$cmd -o 2 $file 2>&1`, `tiffinfo -o 2 $file 2>&1`, '-o' ); + +-is( `$cmd -j test.tif`, `tiffinfo -j test.tif`, '-j' ); ++is( `$cmd -j $file`, `tiffinfo -j $file`, '-j' ); + +-is( `$cmd -r -d test.tif`, `tiffinfo -r -d test.tif`, '-r -d' ); ++is( `$cmd -r -d $file`, `tiffinfo -r -d $file`, '-r -d' ); + +-is( `$cmd -s -d test.tif`, `tiffinfo -s -d test.tif`, '-s -d' ); ++is( `$cmd -s -d $file`, `tiffinfo -s -d $file`, '-s -d' ); + +-is( `$cmd -w -d test.tif`, `tiffinfo -w -d test.tif`, '-w -d' ); ++is( `$cmd -w -d $file`, `tiffinfo -w -d $file`, '-w -d' ); + +-is( `$cmd -z -d test.tif`, `tiffinfo -z -d test.tif`, '-z -d' ); ++is( `$cmd -z -d $file`, `tiffinfo -z -d $file`, '-z -d' ); + + # strip '' from around ?, which newer glibc libraries seem to have added +-my $expected = `tiffinfo -? test.tif 2>&1`; ++my $expected = `tiffinfo -? $file 2>&1`; + $expected =~ s/'\?'/?/xsm; +-is( `$cmd -? test.tif 2>&1`, $expected, '-?' ); ++is( `$cmd -? $file 2>&1`, $expected, '-?' ); + + ######################### + +-unlink 'test.tif'; +diff --git a/t/93_tiff2pdf.t b/t/93_tiff2pdf.t +index a6ade87..da7284e 100644 +--- a/t/93_tiff2pdf.t ++++ b/t/93_tiff2pdf.t +@@ -4,6 +4,8 @@ use English; + use IPC::Cmd qw(can_run); + use Test::More; + use Test::Requires qw( v5.10 Image::Magick ); ++use File::Temp; ++use File::Spec; + + ######################### + +@@ -15,11 +17,12 @@ else { + exit; + } + ++my $directory = File::Temp->newdir; + my $cmd = 'PERL5LIB="blib:blib/arch:lib:$PERL5LIB" ' + . "$EXECUTABLE_NAME examples/tiff2pdf.pl"; +-my $tif = 'test.tif'; +-my $pdf = 'C.pdf'; +-my $compressed_tif = 'comp.tif'; ++my $tif = File::Spec->catfile( $directory, 'test.tif' ); ++my $pdf = File::Spec->catfile( $directory, 'C.pdf' ); ++my $compressed_tif = File::Spec->catfile( $directory, 'comp.tif' ); + my $make_reproducible = + 'grep --binary-files=text -v "/ID" | grep --binary-files=text -v "/CreationDate" | grep --binary-files=text -v "/ModDate" | grep --binary-files=text -v "/Producer"'; + +@@ -35,7 +38,7 @@ is( `$cmd -? $tif 2>&1`, $expected, '-?' ); + my $image = Image::Magick->new; + $image->Read('rose:'); + $image->Set( density => '72x72' ); +-$image->Write('test.tif'); ++$image->Write($tif); + system("tiff2pdf -d -o $pdf $tif"); + + $expected = `cat $pdf | $make_reproducible | hexdump`; +@@ -77,4 +80,3 @@ SKIP: { + + ######################### + +-unlink $tif, $compressed_tif, $pdf; +-- +2.26.2 + diff --git a/perl-Graphics-TIFF.spec b/perl-Graphics-TIFF.spec index 649246c..e1c95af 100644 --- a/perl-Graphics-TIFF.spec +++ b/perl-Graphics-TIFF.spec @@ -8,6 +8,8 @@ Summary: Perl extension for the LibTIFF library License: GPL+ or Artistic URL: https://metacpan.org/release/Graphics-TIFF Source0: https://cpan.metacpan.org/authors/id/R/RA/RATCLIFFE/Graphics-TIFF-%{version}.tar.gz +# Make tests parallel-safe, CPAN RT#134352, proposed to the upstream +Patch0: Graphics-TIFF-8-Use-temporary-directories-to-enable-parallel-testing.patch BuildRequires: coreutils BuildRequires: findutils BuildRequires: gcc @@ -16,6 +18,7 @@ BuildRequires: perl-devel BuildRequires: perl-generators BuildRequires: perl-interpreter BuildRequires: perl(:VERSION) >= 5.8.5 +BuildRequires: perl(Config) BuildRequires: perl(English) BuildRequires: perl(ExtUtils::Depends) BuildRequires: perl(ExtUtils::MakeMaker) >= 6.76 @@ -30,6 +33,7 @@ BuildRequires: perl(Readonly) BuildRequires: perl(XSLoader) # Tests: BuildRequires: perl(File::Spec) +BuildRequires: perl(File::Temp) BuildRequires: perl(IPC::Cmd) BuildRequires: perl(Test::Deep) BuildRequires: perl(Test::More) @@ -53,14 +57,41 @@ Requires: perl(:MODULE_COMPAT_%(eval "`perl -V:version`"; echo $version)) The Graphics::TIFF module allows a Perl developer to access TIFF images using LibTIFF library in a Perlish and object-oriented way. +%package tests +Summary: Tests for %{name} +BuildArch: noarch +Requires: %{name} = %{?epoch:%{epoch}:}%{version}-%{release} +Requires: perl-Test-Harness +%if %{with perl_Graphics_TIFF_enables_optional_test} +# Optional tests: +Requires: grep +# libtiff-tools for tiffcp, tiff2pdf, tiffinfo +Requires: libtiff-tools +Requires: perl(:VERSION) >= 5.10 +Requires: perl(if) +Requires: perl(Image::Magick) +# Test::Perl::Critic not used +# for hexdump +Requires: util-linux +%endif + +%description tests +Tests from %{name}-%{version}. Execute them +with "%{_libexecdir}/%{name}/test". + %prep %setup -q -n Graphics-TIFF-%{version} +%patch0 -p1 %if !%{with perl_Graphics_TIFF_enables_optional_test} for F in t/1.t t/92_tiffinfo.t t/93_tiff2pdf.t; do rm "$F" perl -i -ne 'print $_ unless m{\Q'"$F"'\E}' MANIFEST done %endif +for F in t/*.t; do + perl -i -MConfig -ple 'print $Config{startperl} if $. == 1' "$F" + chmod +x "$F" +done %build perl Makefile.PL INSTALLDIRS=vendor NO_PACKLIST=1 NO_PERLLOCAL=1 OPTIMIZE="$RPM_OPT_FLAGS" @@ -69,10 +100,26 @@ perl Makefile.PL INSTALLDIRS=vendor NO_PACKLIST=1 NO_PERLLOCAL=1 OPTIMIZE="$RPM_ %install %{make_install} find $RPM_BUILD_ROOT -type f -name '*.bs' -size 0 -delete +# Install tests +mkdir -p %{buildroot}/%{_libexecdir}/%{name} +cp -a t %{buildroot}/%{_libexecdir}/%{name} +perl -i -pe 's{\blib(/Graphics/TIFF.pm)\b}{%{perl_vendorarch}$1}' %{buildroot}/%{_libexecdir}/%{name}/t/90_MANIFEST.t +%if %{with perl_Graphics_TIFF_enables_optional_test} +cp -a examples %{buildroot}/%{_libexecdir}/%{name} +chmod +x %{buildroot}/%{_libexecdir}/%{name}/examples/* +%endif +cat > %{buildroot}/%{_libexecdir}/%{name}/test << 'EOF' +#!/bin/sh +unset TEST_AUTHOR +cd %{_libexecdir}/%{name} && exec prove -I . -j "$(getconf _NPROCESSORS_ONLN)" +EOF +chmod +x %{buildroot}/%{_libexecdir}/%{name}/test +# Correct permissions %{_fixperms} $RPM_BUILD_ROOT/* %check unset TEST_AUTHOR +export HARNESS_OPTIONS=j$(perl -e 'if ($ARGV[0] =~ /.*-j([0-9][0-9]*).*/) {print $1} else {print 1}' -- '%{?_smp_mflags}') make test %files @@ -81,9 +128,13 @@ make test %{perl_vendorarch}/Graphics* %{_mandir}/man3/* +%files tests +%{_libexecdir}/%{name} + %changelog * Tue Feb 09 2021 Petr Pisar - 8-1 - Version 8 bump +- Package tests and make them parallel-safe * Mon Feb 08 2021 Petr Pisar - 7-3 - Adapt tests to libtiff-4.2.0 (CPAN RT#134344)