[英]How can simply send info to stdout in a Test?
It appears that simply putting a say
, print
, etc into a .t
doesn't work.看来,简单地将
say
、 print
等放入.t
是行不通的。 The output is hidden. output 被隐藏。 So when using
Test::More
and Test::Tester
how can I simply print something?那么当使用
Test::More
和Test::Tester
时,我怎样才能简单地打印一些东西呢? 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.
注意:可以将其发送到 stderr 或仅使用详细信息查看。 Also I dried using
diag
but that didn't appear to work just anywhere in the test.我也使用
diag
进行了干燥,但这似乎在测试中的任何地方都不起作用。
If you run a test script directly, you will see the output of print
-- tests are just Perl code.如果您直接运行测试脚本,您将看到
print
的 output -- 测试只是 Perl 代码。 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
.但是,如果您使用线束运行测试,您在 output 中看到的内容将取决于线束,尤其是其详细程度,以及您打印到
STDOUT
还是STDERR
。
For another way to print messages within tests, see Diagnostics in the documentation for Test::More
, notably:有关在测试中打印消息的另一种方法,请参阅
Test::More
文档中的诊断,特别是:
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.