There is a great Perl module
Test::More that everybody uses for
unit testing. Here is the very simple script t/sample_1.t
:
use Test::More tests => 1;
fail('This test fails');
I wanted to write script that does the same thing, but without Test::More.
I've read several the docs about TAP (test anything protocol) to find out how to write the script. I've read:
Unfortunately the documentation wasn't enough. I had to examine the output of script that uses Test::More to find out that I need to output diagnostics to STDERR (there was nothing about this in the docs).
So, I have written a script that does completely the same things as the script with Test::More script. Here is the listing of t/sample_2.t
:
$| = 1;
print "1..1\n";
print "not ok 1 - This test fails\n";
print STDERR "# Failed test 'This test fails'\n";
print STDERR "# at t/sample_1.t line 3.\n";
print STDERR "# Looks like you failed 1 test of 1.\n";
exit 1;
But when using prove
these 2 scripts output different things. The line "# Failed test 'This test fails'" in prove
is displayed on different lines for different tests. Here is the screenshot:
I've written a test scripts that uses Capture::Tiny to check that STDERR, STDOUT and exit code for both scripts a identical. And the script shows that both scripts output the same things.
I've stored all the test files and a test script at GitHub repo.
My question. How should I write Perl unit test without Test::More to have the same output as with Test::More.
PS If you are interested why I need this. I need this to solve the issue of my Perl module Test::Whitespaces.
prove -v
) usingdiag
. – Applest/sample_1.t
does: github.com/bessarabov/manual_tap_generation/blob/master/t/… I will try to use it in my module. But I still don't understand why I can't create the output without any module. – Guttery