Suppress passed test output in Test::More

438 views Asked by At

I have a Perl unit test that outputs "ok" for every passed test. I find myself scrolling up and up to find the first failed test, since that's the only thing I'm interested in. I am using Test::More.

use strict; use warnings;
use JSONRegex;
use Test::More;

I would like only failed tests to appear. I tried the solution of using

perl -MTest::Harness -e 'runtests @ARGV' path/to/test_JSONRegex.pl

and it worked. But I wanted to put that in the shebang line so I could just forget about it. The shebang

#!/usr/bin/env perl -MTest::Harness

failed with message Too late for "-MTest::Harness" option at ./test_JSONRegex.pl line 1.

What is the best way to suppress passed test output while still using strict in my script?

3

There are 3 answers

1
cjm On BEST ANSWER

Why not just use the prove command to run your test script?

prove path/to/test_JSONRegex.pl

is basically equivalent to

perl -MTest::Harness -e 'runtests @ARGV' path/to/test_JSONRegex.pl

but with less typing.

Trying to get the test script to automatically determine whether it's already running inside a test harness is going to be tricky and error prone.

0
fdsdf dsfsa On

Show only errors during testing:

Test::More->builder->output("/dev/null")                                        # 
0
ikegami On
-MTest::Harness

simply puts

use Test::Harness;

at the top of your script. But then what? How do you plan on calling runtests? This is oh-so-very wrong. If you want to save typing, use prove as @cjm mentioned, or create a second small script to run your tests.

#!/bin/sh
# This is path/to/test_JSONRegex
BASE="$( dirname "$( readlink -e "$0" )" )"
perl -MTest::Harness -e'runtests @ARGV' "$BASE/test_JSONRegex.pl"