#!/bin/sh

apt update --allow-releaseinfo-change
apt -y install devscripts dpkg-dev
mk-build-deps --install --remove \
    --tool "apt-get -o Debug::pkgProblemResolver=yes -q -y" \
    debian/control
export DEBIAN_FRONTEND=noninteractive
apt -y install libperl-critic-perl libdevel-cover-perl cpanminus slapd
cpanm install Devel::Cover::Report::SonarGeneric
export LLNGTESTLDAP=1
make SKIP_DOCUMENTATION=1

for module in common handler portal manager; do
    cd lemonldap-ng-$module
    perlcritic --cruel --quiet --verbose "%f~|~%s~|~%l~|~%c~|~%m~|~%e~|~%p~||~%n" lib t > perlcritic_report.txt
    cover -delete
    HARNESS_PERL_SWITCHES=-MDevel::Cover prove -j4
    cover -report SonarGeneric
    sed -i "s,path=\"blib,path=\"lemonldap-ng-$module,g" cover_db/sonar_generic.xml

    # Make sure all files are readable to avoid Indexer errors
    chmod o+rX -R .

    cd ..
done
