chore: use TAP::Harness for unit tests

This commit is contained in:
Stéphane Lesimple 2025-01-03 10:04:28 +00:00 committed by Stéphane Lesimple
parent faaa2ed651
commit 0e2138a389
5 changed files with 26 additions and 17 deletions

View file

@ -758,20 +758,11 @@ runtests()
if [ "$opt_unit_tests" = 1 ]; then
echo '=== running unit tests ==='
# a while read loop doesn't work well here:
# shellcheck disable=SC2044
for f in $(find "$basedir/tests/unit/" -mindepth 1 -maxdepth 1 -type f -name "*.pl" -print)
do
fbasename=$(basename "$f")
echo "-> $fbasename"
set +e
$r0 perl "$opt_remote_basedir/tests/unit/$fbasename"; ret=$?
set -e
if [ $ret != 0 ]; then
printf "%b%b%b\\n" "$WHITE_ON_RED" "Unit tests failed (ret=$ret) :(" "$NOC"
exit 1
fi
done
$r0 perl "$opt_remote_basedir/tests/unit/run-tests.pl"; ret=$?
if [ $ret != 0 ]; then
printf "%b%b%b\\n" "$WHITE_ON_RED" "Unit tests failed (ret=$ret) :(" "$NOC"
exit 1
fi
fi
if [ "$opt_functional_tests" = 1 ]; then

18
tests/unit/run-tests.pl Executable file
View file

@ -0,0 +1,18 @@
#! /usr/bin/env perl
# vim: set filetype=perl ts=4 sw=4 sts=4 et:
use common::sense;
use TAP::Harness;
use FindBin qw{ $RealDir };
my @testfiles = glob("$RealDir/tests/*.t");
print "Got " . @testfiles . " unit test files to run:\n";
my $harness = TAP::Harness->new(
{
verbosity => 0,
failures => 1,
color => 1,
}
);
exit($harness->runtests(@testfiles)->all_passed ? 0 : 1);

2
tests/unit/run.pl → tests/unit/tests/base.t Executable file → Normal file
View file

@ -5,7 +5,7 @@ use Test::More;
use Test::Deep;
use File::Basename;
use lib dirname(__FILE__) . '/../../lib/perl';
use lib dirname(__FILE__) . '/../../../lib/perl';
use OVH::Bastion;
use OVH::Result;
use JSON;

View file

@ -5,7 +5,7 @@ use Test::More;
use Test::Deep;
use File::Basename;
use lib dirname(__FILE__) . '/../../lib/perl';
use lib dirname(__FILE__) . '/../../../lib/perl';
use OVH::Bastion;
use OVH::Result;

View file

@ -5,7 +5,7 @@ use Test::More;
use Test::Deep;
use File::Basename;
use lib dirname(__FILE__) . '/../../lib/perl';
use lib dirname(__FILE__) . '/../../../lib/perl';
use OVH::Bastion;
use OVH::Result;