2008年3月21日

AutoTest::Screenとredgreenを同時に使用するには

autotest
ZenTestに含まれる4つのユーティリティのうちの1つで、あらかじめautotestを実行しておくとファイルを変更した際に、"関連あるテストを自動実行してくれる"ユーティリティ
AutoTest::Screen
autotestのプラグインの1つ。テスト結果をscreenのステータスラインに表示する
redgreen
RubyのTest::Unitの実行結果に色付け(成功なら緑、失敗なら赤)をしてくれるツール。視認性の向上と開発者のモチベーションアップに繋がる(公式)
この2つを同時に使おうとしたのですが、AutoTest::Screenがエラーを検知出来なかったのです。色々と調べたところ、redgreenが追加する色付け用特殊文字が正規表現に含まれていないからなのでした。かなり時間をかけてしまったので、情けない気分です・・・。 以下の.autotestでredgreenを使用している場合でも、使用していない場合でも、正しく動作するはずです。.autotestの内容は「Autotest::Screenが便利な件について。 (SaikyoLine.jp)」を参考にさせて頂きました。
require 'autotest/redgreen'
require 'autotest/screen'

Autotest::Screen.statusline = %q[%{=r dd} %-w%{=b dd}[%n] %t %{-}%+w %=]
class Autotest::Screen
  Autotest.add_hook :run_command do |at|
    message 'Testing...' if execute?
  end

  Autotest.add_hook :ran_command do |at|
    if execute? then
      output = at.results.join
      failed = output.scan(/^\s+\d+\) (\e\[31m){0,1}(Failure|Error)(\e\[0m){0,1}:\n(.*?)\((.*?)\)/)
      if failed.size == 0 then
        message "All Green", :green
      else
        f,e = failed.partition { |s| s[0] =~ /Failure/ }
        message "Red F:#{f.size} E:#{e.size}", :red
      end
    end
  end
end

Trackback on "AutoTest::Screenとredgreenを同時に使用するには"

このエントリーのトラックバックURL: 

"AutoTest::Screenとredgreenを同時に使用するには"へのトラックバックはまだありません。

Comment on "AutoTest::Screenとredgreenを同時に使用するには"

"AutoTest::Screenとredgreenを同時に使用するには"へのコメントはまだありません。

Post a Comment

コメントする
(書式を変更するような一部のHTMLタグを使うことができます)
ブラウザに投稿者情報を登録しますか?(Cookieを使用します。次回書き込み時に便利です。)
  •  
  •