From 74434366fb8a5baf205d72653f01af8ec4f67b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Fri, 3 Jan 2025 10:04:28 +0000 Subject: [PATCH] chore: use TAP::Harness for unit tests --- tests/functional/launch_tests_on_instance.sh | 19 +++++-------------- tests/unit/run-tests.pl | 18 ++++++++++++++++++ tests/unit/{run.pl => tests/base.t} | 2 +- .../is_access_granted_ipv4.t} | 2 +- .../is_access_granted_ipv6.t} | 2 +- 5 files changed, 26 insertions(+), 17 deletions(-) create mode 100755 tests/unit/run-tests.pl rename tests/unit/{run.pl => tests/base.t} (99%) mode change 100755 => 100644 rename tests/unit/{is_access_granted_ipv4.pl => tests/is_access_granted_ipv4.t} (99%) mode change 100755 => 100644 rename tests/unit/{is_access_granted_ipv6.pl => tests/is_access_granted_ipv6.t} (99%) mode change 100755 => 100644 diff --git a/tests/functional/launch_tests_on_instance.sh b/tests/functional/launch_tests_on_instance.sh index 77dfbdb9e..50d318bd2 100755 --- a/tests/functional/launch_tests_on_instance.sh +++ b/tests/functional/launch_tests_on_instance.sh @@ -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 diff --git a/tests/unit/run-tests.pl b/tests/unit/run-tests.pl new file mode 100755 index 000000000..fe84b01df --- /dev/null +++ b/tests/unit/run-tests.pl @@ -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); diff --git a/tests/unit/run.pl b/tests/unit/tests/base.t old mode 100755 new mode 100644 similarity index 99% rename from tests/unit/run.pl rename to tests/unit/tests/base.t index 0483d123c..b707d2a9f --- a/tests/unit/run.pl +++ b/tests/unit/tests/base.t @@ -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; diff --git a/tests/unit/is_access_granted_ipv4.pl b/tests/unit/tests/is_access_granted_ipv4.t old mode 100755 new mode 100644 similarity index 99% rename from tests/unit/is_access_granted_ipv4.pl rename to tests/unit/tests/is_access_granted_ipv4.t index 810b94253..df436232f --- a/tests/unit/is_access_granted_ipv4.pl +++ b/tests/unit/tests/is_access_granted_ipv4.t @@ -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; diff --git a/tests/unit/is_access_granted_ipv6.pl b/tests/unit/tests/is_access_granted_ipv6.t old mode 100755 new mode 100644 similarity index 99% rename from tests/unit/is_access_granted_ipv6.pl rename to tests/unit/tests/is_access_granted_ipv6.t index 821addfd0..b78075470 --- a/tests/unit/is_access_granted_ipv6.pl +++ b/tests/unit/tests/is_access_granted_ipv6.t @@ -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;