Skip to content

Commit

Permalink
chore: use TAP::Harness for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
speed47 committed Jan 3, 2025
1 parent faaa2ed commit 7443436
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
19 changes: 5 additions & 14 deletions tests/functional/launch_tests_on_instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/run-tests.pl
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion tests/unit/run.pl → tests/unit/tests/base.t
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/is_access_granted_ipv4.pl → tests/unit/tests/is_access_granted_ipv4.t
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Test::Deep;

use File::Basename;
use lib dirname(__FILE__) . '/../../lib/perl';
use lib dirname(__FILE__) . '/../../../lib/perl';
use OVH::Bastion;
use OVH::Result;

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/is_access_granted_ipv6.pl → tests/unit/tests/is_access_granted_ipv6.t
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Test::Deep;

use File::Basename;
use lib dirname(__FILE__) . '/../../lib/perl';
use lib dirname(__FILE__) . '/../../../lib/perl';
use OVH::Bastion;
use OVH::Result;

Expand Down

0 comments on commit 7443436

Please sign in to comment.