测试::更多:由于转义序列导致计划错误

时间:2013-09-03 07:41:21

标签: perl winapi testing escaping perl-module

当我为此模块运行以下测试时,测试失败。

当我向转义序列"\e(U"添加换行符时,测试通过。

为什么这个转义序列会导致测试失败?


package My_Module;

use Win32::Console::ANSI;

print "\e(U"; # dissables the so-called ANSI to OEM conversion

# print "\e(U\n" # written this way, the test passes.

1;

use Test::More tests => 1; 

BEGIN { use_ok( 'My_Module' ) || print "Bail out!\n" }

diag( "Testing My_Module, Perl $], $^X" );

结果:

C:\strawberry\perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/00-load.t .. # Testing My_Module, Perl 5.018001, C:\strawberry\perl\bin\perl.exe
t/00-load.t .. Failed 1/1 subtests

Test Summary Report
-------------------
t/00-load.t (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: Bad plan.  You planned 1 tests but ran 0.
Files=1, Tests=0,  1 wallclock secs ( 0.03 usr +  0.05 sys =  0.08 CPU)
Result: FAIL
Failed 1/1 test programs. 0/0 subtests failed.
dmake:  Error code 255, while making 'test_dynamic'

1 个答案:

答案 0 :(得分:3)

如果以详细模式运行测试,您将看到测试的输出为:

←(Uok 1 - use MyModule;

这不是由perl作为成功测试重新调整的,它应该是: ok 1 - use MyModule;请参阅TAP specification

如果您在模块打印secuence print "\e(U\n"中添加\ n,它可能会通过测试,但我不知道这是否适用于您的目的。

我认为测试输出的最佳方法是使用Test::Output