了解如何在 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更深入的說明。