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にあります。 Test2についてのより詳しい説明は、perldocで読むことができます。