jeudi 20 août 2020

How can I test subs in a perl programs with Test::More without losing the programs exit code?

When writing small to medium size perl programs I have functions that I would like to test with "Test::More".

The idea is to be able to call my program like "./supertool.pl --test" to do the tests. While beeing able to use "./supertool.pl" for normal program usage.

But when I add "use Test::More qw(no_plan);" in the head section it garbles the program output and its exit code.

Here's an example which can be called in console like: './supertool.pl ; echo $? ; echo "Expected: 0"'.

#!/usr/bin/perl

use strict;
use warnings;
use Test::More qw(no_plan);

if (0)
{
        note("one test");
        test__x();
        done_testing;
}

exit(0);

sub test_x
{
        ok( 1, "1 is ok" );
}

The output is:

1..0
255
Expected: 0

But I whished the output to be

0
Expected: 0

Is it possible to tweak Test::More into not printing "1..0" and into not garbling the programs exit code when doing no tests?

Aucun commentaire:

Enregistrer un commentaire