Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use TAP::Harness for unit tests #518

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading