CL TEST MORE - lisp-cookbook-ja/common-lisp GitHub Wiki
https://github.com/fukamachi/cl-test-more
特徴
- TAPでの結果出力
- テストのスクリプトとしての実行をサポート
概要
(require 'cl-test-more)
;; or
(load "cl-test-more.lisp")
(in-package :cl-test-more)
(plan 9)
;; check if first argument is true
(ok (eq got expected) "Description")
;; check if "got" equals "expected"
(is got expected "Description")
(isnt got expected "Description")
;; with :test function
(is got expected "Description" :test #'string=)
;; rather than print *standard-output* "# This is just a comment\n"
(diag "This is just a comment")
;; macro expansion
(is-expand (got macro) (expected :like "this") "Description")
;; output
(is-print (write-line "aiueo") "aiueo\n" "Description")
;; error
(is-error (error "hoge") 'simple-error "Description")
;; type
(is-type 10 'number "Description")
;; regular expression
(like "aiueo" "[iu]e" "Description")
;; functions always pass or fail
(pass "Description")
(fail "Description")
;; grouping tests
(deftest test-a
(is "A" (symbol-name :a))
(isnt "b" (symbol-name :b)))
(run-test :test-a)
(run-test-all)
インストール
Quicklisp(Quicklispを使う)でインストールできます。
(ql:quickload :cl-test-more)
テストの書き方
- ok
- is
- isnt
- is-expand
- is-print
- is-error
- is-type
- like
- diag
- pass
- fail
- plan
- run-test
- run-test-all
スクリプトとしての実行
スクリプトとして実行する場合、通常の実行と以下の点で異なります。
- 終了時に自動で結果を集計、表示
- 途中でエラーが出たときにデバッガを表示せず終了
- planでテストの数を指定しておけば、テストが正常通りにすべて実行されたかを確認できる
この実行形式の場合、run-test-allは必要ありません。Allegro CL, SBCL, CMUCL, Clozure CL, ECL, CLISPでサポートされています(他の処理系の場合はrun-test-allが必要です)。
その他
デフォルトのテスト関数を指定する
テスト関数はデフォルトで"equal"を使ってテストします。このデフォルトの比較関数はdefault-test-functionで定義されており、自由に設定することができます。