如何在测试中简单地将信息发送到标准输出? [英] How can simply send info to stdout in a Test?
问题描述
似乎只是将 say
、print
等放入 .t
中是行不通的.输出是隐藏的.因此,当使用 Test::More
和 Test::Tester
时,我如何简单地打印一些东西?我想要这个,所以我可以在确定如何测试它的同时玩一些代码.注意:如果将其发送到 stderr 或仅使用详细可见,则可以.我还使用 diag
进行了干燥,但这似乎在测试中的任何地方都不起作用.
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::Tester
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.
推荐答案
如果你直接运行测试脚本,你会看到 print
的输出——测试只是 Perl 代码.但是,如果您使用工具运行测试,您在输出中看到的内容将由工具决定,尤其是其详细程度,以及您是打印到 STDOUT
还是 STDERR代码>.
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
.
有关在测试中打印消息的另一种方式,请参阅 Diagnostics>测试::更多
,特别是:
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;
这篇关于如何在测试中简单地将信息发送到标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!