Commit 841c5ba5 authored by Xavier Guimard's avatar Xavier Guimard

Improve Debian autopkgtest tests

parent 10ed38bd
lemonldap-ng (2.0.0-1) UNRELEASED; urgency=medium
lemonldap-ng (2.0.0-1) unstable; urgency=medium
2.0 is a major release, many things have been changed. You must read
https://lemonldap-ng.org/documentation/2.0/upgrade before upgrade.
......
......@@ -7,6 +7,7 @@ Build-Depends: debhelper (>= 10),
po-debconf
Build-Depends-Indep: libapache-session-perl,
libauthen-oath-perl,
libauthen-u2f-tester-perl,
libcache-cache-perl,
libclone-perl,
libconfig-inifiles-perl,
......@@ -15,12 +16,14 @@ Build-Depends-Indep: libapache-session-perl,
libcrypt-openssl-rsa-perl,
libcrypt-openssl-x509-perl,
libcrypt-rijndael-perl,
libcrypt-u2f-server-perl,
libdbd-sqlite3-perl,
libdbi-perl,
libdigest-hmac-perl,
libemail-sender-perl,
libgd-securityimage-perl,
libglib-perl,
libgssapi-perl,
libhtml-template-perl,
libimage-magick-perl,
libio-string-perl,
......
# debian/tests/runner launch pkg-perl-autopkgtest tests for each library
Test-Command: ./debian/tests/runner build-deps
Depends: @, @builddeps@, pkg-perl-autopkgtest, libmouse-perl
Test-Command: ./debian/tests/runner runtime-deps
Depends: @, pkg-perl-autopkgtest, libmouse-perl
Test-Command: ./debian/tests/runner runtime-deps-and-recommends
Depends: @, pkg-perl-autopkgtest, libmouse-perl
# Use pkg-perl-autopkgtest test for runtime-deps-and-recommends
Test-Command: /usr/share/pkg-perl-autopkgtest/runner runtime-deps-and-recommends
Depends: @, @builddeps@, pkg-perl-autopkgtest, libmouse-perl, libcache-memcached-perl, libauthen-pam-perl, libauthen-radius-perl, libweb-id-perl, libyaml-perl
Restrictions: needs-recommends
#Test-Command: ./debian/tests/runner heavy-deps
......
#!/bin/sh
set -e
cleanup() {
cd $PDIR
#Clean up after smoke-setup
cleanup_file=debian/tests/pkg-perl/smoke-cleanup
if [ -x $cleanup_file ]
then
( export TDIR; $cleanup_file )
fi
rm -rf $TDIR
}
TEMP=${ADTTMP:-${TMPDIR:-/tmp}}
TDIR=$(mktemp -d $TEMP/smokeXXXXXX)
PDIR=`pwd`
trap cleanup EXIT
file_list=debian/tests/pkg-perl/smoke-files
if [ ! -r $file_list ]; then
# backward compatibility squared for now
file_list=debian/tests/pkg-perl/test-files
fi
if [ ! -r $file_list ]; then
# backward compatibility for now
file_list=debian/tests/test-files
fi
export AUTOMATED_TESTING=1
export NONINTERACTIVE_TESTING=1
# overridable with smoke-env
PKG_PERL_PROVE_ARGS="--verbose --recurse --merge"
PKG_PERL_XVFB_ARGS="-a"
env_list=debian/tests/pkg-perl/smoke-env
if [ ! -r $env_list ]; then
env_list=debian/tests/pkg-perl/env-smoke
fi
if [ -r $env_list ]; then
eval $(sed '/^ *\(#\|$\)/d; s/^/export /' $env_list)
fi
for dir in common handler portal manager; do
TDIR2=${TDIR}/lemonldap-ng-$dir
mkdir -p $TDIR2/blib/lib \
$TDIR2/blib/arch \
$TDIR2/lib/Debian/pkgperl \
$TDIR2/blib/lib/Debian/pkgperl
cp -a lemonldap-ng-$dir/t $TDIR2/
if [ -d lemonldap-ng-$dir/site ]; then
cp -a lemonldap-ng-$dir/site $TDIR2/
fi
cat <<'EOF' > $TDIR2/lib/Debian/pkgperl/Foobar.pm
package Debian::pkgperl::Foobar;
our $VERSION = '0.01';
1;
__END__
=head1 NAME
Debian::pkgperl::Foobar - dummy module for test checkers
=cut
EOF
cp $TDIR2/lib/Debian/pkgperl/Foobar.pm $TDIR2/blib/lib/Debian/pkgperl
if [ ! -e $TDIR2/MANIFEST ]; then
cat <<'EOF' > $TDIR2/MANIFEST
lib/Debian/pkgperl/Foobar.pm
EOF
fi
if [ ! -e $TDIR2/MANIFEST.SKIP ]; then
cp /dev/null $TDIR2/MANIFEST.SKIP
fi
done
# Missing file
cp lemonldap-ng-common/lemonldap-ng.ini ${TDIR}/lemonldap-ng-common
# Test that have no interest
rm -f $TDIR/*/t/99-pod.t \
$TDIR/lemonldap-ng-manager/t/03-HTML-forms.t \
$TDIR/lemonldap-ng-manager/t/20-test-coverage.t \
$TDIR/lemonldap-ng-manager/t/80-attributes.t \
$TDIR/lemonldap-ng-manager/t/90-translations.t
for INI in $(find $TDIR/lemonldap-ng-* -name lemonldap-ng.ini); do
echo "Change $INI logLevel to debug"
perl -pi -e 's/^logLevel\s*=\s*\w+$/logLevel=debug/' $INI || true
done
# For now, too many bugs with Moose in autopkg jail, so manager isn't tested
for dir in common handler portal manager; do
TDIR2=${TDIR}/lemonldap-ng-$dir
# this is intended to be a last resort, please use it responsibly
setup_file=debian/tests/pkg-perl/smoke-setup
if [ -x $setup_file ]
then
( export TDIR2; $setup_file )
# Evaluate skip list a second time since smoke-setup might have
# generated some of the to-be-skipped files.
if [ -r $skip_list ]; then
egrep -v '^ *(#|$)' $skip_list | while read file; do
rm -f $TDIR2/$file
done
fi
fi
tests_file=$(pwd)/debian/tests/pkg-perl/smoke-tests
cd $TDIR2
if [ -r $tests_file ]; then
test_targets=$(eval ls -d $(egrep -v '^#' $tests_file) 2>/dev/null || true)
fi
if command -v xvfb-run >/dev/null
then
XVFB="xvfb-run -a"
else
XVFB=
PKG_PERL_XVFB_ARGS=
PKG_PERL_XVFB_SERVER_ARGS=
fi
test_targets=$(ls -d t/*.t 2>/dev/null || true)
if [ ! -n "$test_targets" ]; then
echo 'Nothing to prove, skipping.'
else
$XVFB $PKG_PERL_XVFB_ARGS ${PKG_PERL_XVFB_SERVER_ARGS:+-s} ${PKG_PERL_XVFB_SERVER_ARGS:+"$PKG_PERL_XVFB_SERVER_ARGS"} prove -I"$TDIR" --blib $PKG_PERL_PROVE_ARGS $test_targets 2>&1
fi
cd -
done
#!/usr/bin/perl -w
use strict;
use Test::More;
use Getopt::Std;
sub usage {
my $exit = shift;
$exit = 0 if !defined $exit;
print "Usage: $0 [ package ] ...\n";
print "\tpackages are read from debian/control if not given as arguments\n";
exit $exit;
}
my %opts;
getopts('h', \%opts)
or usage();
usage(0) if $opts{h};
sub getpackages {
my @p;
my $c = "debian/control";
-f $c or BAIL_OUT("no packages listed and $c not found");
open(C, '<', $c) or BAIL_OUT("opening $c for reading failed:$!");
while (<C>) {
chomp;
/^\s*Package:\s+(\S+)/ and push @p, $1;
}
close C or BAIL_OUT("closing $c failed: $!");
return @p;
}
sub readskip {
my $skip = "debian/tests/pkg-perl/syntax-skip";
$skip = "debian/tests/pkg-perl/skip-syntax" if ! -r $skip;
-r $skip or return ();
open (S, '<', $skip)
or BAIL_OUT("$skip exists but can't be read");
my @ret;
while (<S>) {
chomp;
next if !/\S/;
next if /^\s*#/;
push @ret, qr/\Q$_\E/;
}
close S;
return @ret;
}
my @packages = @ARGV ? @ARGV : getpackages();
usage() if !@packages;
plan tests => 4 * scalar @packages;
my @to_skip = readskip();
for my $package (@packages) {
SKIP: {
ok(!system(qq(dpkg-query --list "$package" >/dev/null 2>&1)),
"Package $package is known to dpkg");
skip "$package not installed", 3 if $?;
my @status_info = qx{dpkg-query --status "$package"};
ok(@status_info, "Got status information for package $package");
skip "$package has Suggestions and no explicit skip list", 2
if grep /^Suggests:/, @status_info and ! @to_skip;
my @files = qx{dpkg-query --listfiles "$package" 2>/dev/null};
ok(@files, "Got file list for package $package");
skip "nothing to test", 1 if !@files;
my @pms;
F: for (@files) {
chomp;
next if !/\.pm$/;
for my $skip_re (@to_skip) {
note "skipping $_", next F if /$skip_re/;
}
my $oninc = 0;
for my $incdir (@INC) {
$oninc++, last if /^\Q$incdir/;
}
next if !$oninc;
push @pms, $_;
}
skip "no perl modules to test in $package", 1 if !@pms;
subtest "all modules in $package pass the syntax check" => sub {
plan tests => scalar @pms;
for (@pms) {
my @out = grep !/syntax OK/, qx($^X -wc $_ 2>&1);
note(@out) if @out;
ok(!$?, "$^X -wc $_ exited successfully");
}
}
}
}
#!/usr/bin/perl -w
use strict;
use Test::More;
use Getopt::Std;
use CPAN::Meta;
use File::Temp;
sub usage {
my $exit = shift;
$exit = 0 if !defined $exit;
print "Usage: $0 [ Some::Module] ...\n";
print "\tthe perl module is guessed from META.{json,yml} if not given as argument\n";
exit $exit;
}
my %opts;
getopts('h', \%opts)
or usage();
usage(0) if $opts{h};
sub getmodule {
my $module;
my $conffile = "debian/tests/pkg-perl/use-name";
$conffile = "debian/tests/pkg-perl/module-name" if ! -e $conffile; # backcompat
$conffile = "debian/tests/module-name" if ! -e $conffile; # backcompat squared
$module = read_conffile($conffile);
return $module if defined $module;
return getmeta();
}
sub read_conffile {
my $conffile = shift;
my $ret;
if ( -f $conffile ) {
open(M, "<", $conffile)
or BAIL_OUT("$conffile exists but can't be read");
while (<M>) {
chomp;
next if /^\s*#/;
/(\S+)/ and $ret = $1, last;
}
close M;
BAIL_OUT("can't find anything in $conffile")
if !defined $ret;
}
return $ret;
}
sub getmeta {
my $meta;
my $dist;
eval { $meta = CPAN::Meta->load_file('META.json') };
eval { $meta = CPAN::Meta->load_file('META.yml' ) } if !$meta;
plan skip_all => "can't guess package from META.json or META.yml"
if !$meta;
$dist = $meta->name;
my $module = $dist;
$module =~ s,-,::,g;
my $file = "$dist.pm";
$file =~ s,-,/,g;
my $basefile = $file;
$basefile =~ s,.*/,,;
( -f $basefile ) or (-f "lib/$file") or plan skip_all => "$basefile or lib/$file not found";
return $module;
}
sub getwhitelist {
my $whitelist = 'debian/tests/pkg-perl/use-whitelist';
my $ret;
$ret = read_conffile($whitelist) if ( -f $whitelist );
$ret;
}
my @modules = @ARGV ? @ARGV : getmodule();
my $whitelist = getwhitelist();
usage() if !@modules;
plan tests => 4 * scalar @modules;
# don't run the command in the source directory, in case
# cwd is on @INC
my $dir;
$dir = $ENV{'AUTOPKGTEST_TMP'};
$dir = $ENV{'ADTTMP'} if !defined $dir;
$dir = File::Temp::tempdir( CLEANUP => 1 ) if !defined $dir;
chdir($dir) or die("can't chdir to $dir");
for my $mod (@modules) {
for my $envprefix ('', 'env PERL_DL_NONLAZY=1 ') {
my $cmd = qq($envprefix $^X -w -M"$mod" -e 1 2>&1);
my @out = qx($cmd);
note(@out) if @out;
ok(!$?, "$cmd exited successfully");
@out = grep { !/$whitelist/ } @out if defined $whitelist;
ok(!@out, "$cmd produced no (non-whitelisted) output");
}
}
t
site/templates
site/htdocs/static/struct.json
t/03-HTML-forms.t
t/80-attributes.t
t/90-translations.t
t/99-pod.t
t
site/templates
site/htdocs/static/common/icons/ok.png
inc
Apache2
ApacheMP2
Common/Logger/Sentry.pm
Handler/Lib/SecureToken.pm
Handler/Server/SecureToken.pm
Portal/Main/Run
Portal/Main/Init
Portal/Main/Display
Portal/Main/Process
#!/bin/sh
BASE=debian/tests/lib
BASE=/usr/share/pkg-perl-autopkgtest
TYPE=$1
[ -n "$TYPE" ] || exit 1
......@@ -8,25 +8,41 @@ TYPE=$1
TESTDIR=${BASE}/${TYPE}.d
[ -d "$TESTDIR" ] || exit 1
SKIPLIST=debian/tests/pkg-perl/SKIP
SKIPTMP=$(mktemp)
if [ -f "$SKIPLIST" ]; then
grep -v '^ *#' "$SKIPLIST" |grep -v '^ *$' > "$SKIPTMP"
fi
LLSOURCEDIR=`pwd`
EXITCODE=0
for T in $(run-parts --list --regex '(^[a-z0-9.]+$)' ${TESTDIR} | \
grep -v -F -f "$SKIPTMP") ; do
if echo "$T" | grep -q '\.t$'
then
prove --norc -v "$T"
RET=$?
if [ $EXITCODE = 0 ]; then EXITCODE=$RET; fi
else
"$T"
RET=$?
if [ $EXITCODE = 0 ]; then EXITCODE=$RET; fi
for LLLIB in lemonldap-ng-*; do
mkdir -p $LLSOURCEDIR/$LLLIB/debian/tests/pkg-perl
for llfile in debian/tests/pkg-perl/${LLLIB}*; do
if [ -r $llfile ]; then
dest=${llfile#*$LLLIB.}
cp -v $llfile $LLSOURCEDIR/$LLLIB/debian/tests/pkg-perl/$dest
fi
done
cd $LLSOURCEDIR/$LLLIB
SKIPLIST=debian/tests/pkg-perl/SKIP
SKIPTMP=$(mktemp)
if [ -f "$SKIPLIST" ]; then
grep -v '^ *#' "$SKIPLIST" |grep -v '^ *$' > "$SKIPTMP"
fi
for T in $(run-parts --list --regex '(^[a-z0-9.]+$)' ${TESTDIR} | \
grep -v -F -f "$SKIPTMP") ; do
if echo "$T" | grep -q '\.t$'
then
prove --norc -v "$T"
RET=$?
if [ $EXITCODE = 0 ]; then EXITCODE=$RET; fi
else
"$T"
RET=$?
if [ $EXITCODE = 0 ]; then EXITCODE=$RET; fi
fi
done
cd $LLSOURCEDIR
rm -rf $LLSOURCEDIR/$LLLIB/debian
done
rm -f "$SKIPTMP"
exit $EXITCODE
package Lemonldap::NG::Handler;
use base 'Lemonldap::NG::Handler::ApacheMP2';
print STDERR
"Use the appropriate handler. For Apache, use Lemonldap::NG::Handler::ApacheMP2";
our $VERSION = '2.0.0';
......
......@@ -395,7 +395,8 @@ sub staticFile {
require Cwd;
require HTTP::Date;
open my $fh, '<:raw', $self->conf->{templatesDir} . "/$file"
or return $self->sendError( $req, $!, 403 );
or return $self->sendError( $req,
$self->conf->{templatesDir} . "/$file: $!", 403 );
my @stat = stat $file;
Plack::Util::set_io_path( $fh, Cwd::realpath($file) );
return [
......
use strict;
use IO::String;
use Test::More;
use lib 'inc';
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use JSON qw(to_json from_json);
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More;
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More; # skip_all => 'CAS is in rebuild';
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......
use lib 'inc';
use Test::More; # skip_all => 'CAS is in rebuild';
use strict;
use IO::String;
use LWP::UserAgent;
use inc::LWP::Protocol::PSGI;
use LWP::Protocol::PSGI;
use MIME::Base64;
BEGIN {
......