It appears that simply putting a say
, print
, etc into a .t
doesn't work. The output is hidden. So when using Test::More
and Test::Te开发者_如何学编程ster
how can I simply print something? I want this so I can play with some code while determining how to test it. note: it's ok if it's sent to stderr or only viewable using verbose. Also I dried using diag
but that didn't appear to work just anywhere in the test.
If you run a test script directly, you will see the output of print
-- tests are just Perl code. However, if you run your tests using a harness, what you see in the output will be determined by the harness, especially its verbosity level, and by whether you print to STDOUT
or STDERR
.
For another way to print messages within tests, see Diagnostics in the documentation for Test::More
, notably:
diag(...);
note(...);
Experimenting with a script like this will quickly illustrate how things work:
# Example usages:
# perl some_test.t # We see everything in output.
# prove some_test.t # We see only diag() and STDERR.
# prove -v some_test.t # Everything again.
# In some_test.t
use strict;
use warnings;
use Test::More;
pass;
diag("diag()");
note("note()");
print "STDOUT\n";
print STDERR "STDERR\n";
done_testing;
精彩评论