Perl 学习路径上的测试

学习如何在 Exercism 上测试你的 Perl 练习


运行所有测试

t/目录中有一个扩展名为.t的 Perl 脚本,用来测试你提交的解答。 你可以用下面的命令来运行测试:

prove

在你开始这个练习之前,输出大概是这样的:

./t/hello-world.t .. 1/2
# Failed test 'Say Hi!'
# at exercises/hello-world/t/hello-world.t line 15.
# +---------+---------------+
# | GOT     | CHECK         |
# +---------+---------------+
# | <UNDEF> | Hello, World! |
# +---------+---------------+
exercises/hello-world/t/hello-world.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests

Test Summary Report
-------------------
./t/hello-world.t (Wstat: 256 Tests: 2 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
Files=1, Tests=2,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.18 cusr  0.02 csys =  0.23 CPU)
Result: FAIL

你需要修改lib/目录中扩展名为.pm的模块,并写出一份提交的解答来通过测试。 测试通过之后,上面那条命令的输出大概是这样的:

./t/hello-world.t .. ok
All tests successful.
Files=1, Tests=2,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.07 cusr  0.01 csys =  0.10 CPU)
Result: PASS

关于测试文件中使用的断言的文档,可以在 Test2::Manual::Testing::Introduction 中找到。 在 perldoc 上可以找到关于Test2更深入的说明。