diff --git a/perl-HTML-Parser.spec b/perl-HTML-Parser.spec
index 91412ac..bf3da76 100644
--- a/perl-HTML-Parser.spec
+++ b/perl-HTML-Parser.spec
@@ -46,10 +46,29 @@ The HTML-Parser module for perl to parse and extract information from
HTML documents, including the HTML::Entities, HTML::HeadParser,
HTML::LinkExtor, HTML::PullParser, and HTML::TokeParser modules.
+%package tests
+Summary: Tests for %{name}
+Requires: %{name} = %{?epoch:%{epoch}:}%{version}-%{release}
+Requires: perl-Test-Harness
+
+%description tests
+Tests from %{name}. Execute them
+with "%{_libexecdir}/%{name}/test".
+
%prep
%setup -q -n HTML-Parser-%{version}
chmod -c a-x eg/*
+# Help file to recognise the Perl scripts and normalize shebangs
+for F in t/*.t; do
+ if head -1 "$F" | grep -q -e '^#!.*perl\b' ; then
+ perl -MConfig -pi -e 's|^#!.*perl\b|$Config{startperl}|' "$F"
+ else
+ perl -i -MConfig -ple 'print $Config{startperl} if $. == 1' "$F"
+ fi
+ chmod +x "$F"
+done
+
%build
perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE="%{optflags}" NO_PACKLIST=1 NO_PERLLOCAL=1
%{make_build}
@@ -61,9 +80,28 @@ iconv -f iso-8859-1 -t utf-8 <"$file" > "${file}_" && \
touch -r ${file} ${file}_ && \
mv -f "${file}_" "$file"
find %{buildroot} -type f -name '*.bs' -empty -delete
+
+# Install tests
+mkdir -p %{buildroot}/%{_libexecdir}/%{name}
+cp -a t %{buildroot}/%{_libexecdir}/%{name}
+cat > %{buildroot}/%{_libexecdir}/%{name}/test << 'EOF'
+#!/bin/bash
+set -e
+# Some tests write into temporary files/directories. The easiest solution
+# is to copy the tests into a writable directory and execute them from there.
+DIR=$(mktemp -d)
+pushd "$DIR"
+cp -a %{_libexecdir}/%{name}/* ./
+prove -I . -j "$(getconf _NPROCESSORS_ONLN)"
+popd
+rm -rf "$DIR"
+EOF
+chmod +x %{buildroot}/%{_libexecdir}/%{name}/test
+
%{_fixperms} %{buildroot}/*
%check
+export HARNESS_OPTIONS=j$(perl -e 'if ($ARGV[0] =~ /.*-j([0-9][0-9]*).*/) {print $1} else {print 1}' -- '%{?_smp_mflags}')
make test
%files
@@ -73,9 +111,13 @@ make test
%{perl_vendorarch}/auto/HTML/
%{_mandir}/man3/*.3pm*
+%files tests
+%{_libexecdir}/%{name}
+
%changelog
* Fri Mar 05 2021 Jitka Plesnikova - 3.76-1
- 3.76 bump
+- Package tests
* Wed Jan 27 2021 Fedora Release Engineering - 3.75-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild