Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manually create TAP output
    primarykey
    data
    text
    <p>There is a great Perl module <a href="https://metacpan.org/module/Test::More" rel="nofollow noreferrer">Test::More</a> that everybody uses for unit testing. Here is the very simple script <code>t/sample_1.t</code>:</p> <pre class="lang-perl prettyprint-override"><code>use Test::More tests =&gt; 1; fail('This test fails'); </code></pre> <p>I wanted to write script that does the same thing, but without <a href="https://metacpan.org/module/Test::More" rel="nofollow noreferrer">Test::More</a>.</p> <p>I've read several the docs about TAP (test anything protocol) to find out how to write the script. I've read:</p> <ul> <li><a href="http://en.wikipedia.org/wiki/Test_Anything_Protocol" rel="nofollow noreferrer">Wikipedia article about TAP</a></li> <li><a href="http://search.cpan.org/~petdance/Test-Harness-2.64/lib/Test/Harness/TAP.pod" rel="nofollow noreferrer">TAP specification</a></li> </ul> <p>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).</p> <p>So, I have written a script that does completely the same things as the script with Test::More script. Here is the listing of <code>t/sample_2.t</code>:</p> <pre class="lang-perl prettyprint-override"><code>$| = 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; </code></pre> <p>But when using <code>prove</code> these 2 scripts output different things. The line "# Failed test 'This test fails'" in <code>prove</code> is displayed on different lines for different tests. Here is the screenshot:</p> <p><img src="https://i.stack.imgur.com/nUtI5.png" alt="Perl prove output for 2 sample unit tests"></p> <p>I've written a test scripts that uses <a href="https://metacpan.org/module/Capture::Tiny" rel="nofollow noreferrer">Capture::Tiny</a> to check that STDERR, STDOUT and exit code for both scripts a identical. And the script shows that both scripts output the same things.</p> <p>I've stored all the test files and a test script at <a href="https://github.com/bessarabov/manual_tap_generation" rel="nofollow noreferrer">GitHub repo</a>.</p> <p>My question. How should I write Perl unit test without Test::More to have the same output as with Test::More.</p> <p>PS If you are interested why I need this. I need this to solve <a href="https://github.com/bessarabov/Test-Whitespaces/issues/10" rel="nofollow noreferrer">the issue</a> of my Perl module <a href="https://metacpan.org/module/Test::Whitespaces" rel="nofollow noreferrer">Test::Whitespaces</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload