



パッケージのテストをサポートする
use Test::More tests => テスト数
Module::Starter でパッケージのひな形を作ると、./t の中にテストスクリプトが生成される。
01.test-name1.t , 02.test-name2.t などを追加していくと、テストを追加できる。
これらのテストモジュール内では、Test::More を使用して合否判定する。
use modeule-name; のテスト:
BEGIN { use_ok( 'module-name' ); }
Module::Starter のひな形では 00.load.t でテストされるので、そのまま使えばよい。
テストする: cmp_ok($this, $op, $that, $test-name);
他にも色々なメソッドがあるが、テストFAILの時に結果がダンプされるので、cmp_okが最も便利。例えば、以下のように使う。
cmp_ok($this,'==',$that,'test1');
cmp_ok($this,'eq',$that,'test2');
正規表現との比較: like($this, qr/$that/, $test-name); : $this =~ /$that/
unlike($this, qr/$that/, $test-name); : ! ($this =~ /$that/)
デバッグメッセージの表示: diag($message);
モジュールの画面出力はリダイレクトされているので、画面には表示されない。