狠狠撸

狠狠撸Share a Scribd company logo
テストをもっと気軽に書こう
sbt-doctest
@kawachi
Python には doctest がある
? コメント内にある文字列を使ってテスト
? これが一番簡単そう
"""!
This is the "example" module.!
!
The example module supplies one function, factorial(). For example,!
!
>>> factorial(5)!
120!
"""
scala doctest で検索
? 「だれか作ってるでしょ」
でもこれ古い
? 2010年から更新されていない
自分で作ってみる
? パターン見つけてテストつくるだけだし、?
自分でもなんとかなるんじゃないか
? sbt と組み合わせて sbt test のタイミングで?
生成するようにしたい
できましたー
? http://github.com/tkawachi/sbt-doctest
やってること
1. scaladoc で使っている parser を使って?
ドキュメントを取り出す
2. parser combinator を使って?
ドキュメントに含まれているテストを取り出す
3. テストをファイルに保存する
以上を sourceGenerators in Test で?
実行する sbt plugin を作成。
Python style と?
scala repl style をサポート
? タイプ数が少ないのは
Python style だよなー
? console で実行してから貼
り付けたい場合もある
? → とりあえず両方?
/**!
* # Python style!
* >>> Test.f(10)!
* 20!
*!
* # Scala repl style!
* scala> Test.f(20)!
* res1: Int = 40!
*/
scaladoc との兼ね合い
? scaladoc が崩れるのを防ぐ
には {{{ }}} 内で書くと良さ
そう
? {{{ }}} 内でなくてもテストは
動く
/**!
* {{{!
* # Python style!
* >>> Test.f(10)!
* 20!
*!
* # Scala repl style!
* scala> Test.f(20)!
* res1: Int = 40!
* }}}!
*/
Import できます
/**!
* {{{!
* # Python style!
* >>> import Test.f!
* >>> f(10)!
* 20!
*!
* # Scala repl style!
* scala> import Test.f2!
* scala> f2(20)!
* res1: Int = 40!
* }}}!
*/
haskell-doctest から?
prop> をインスパイア
? ScalaCheck のテストを生成
/**!
* {{{!
* prop> (i: Int) => i + i should === i * 2!
* }}}!
*/
今後の予定
? 複数行のテスト
? sonatype へリリース
ご感想をお待ちしています
? http://github.com/tkawachi/sbt-doctest

More Related Content

Sbt doctest