Emacs Lisp Expectationsã§è¶ ç°¡åã¦ããããã¹ã in elisp
elispにもRubyのexpectationsのような美しく記述できるテスティングフレームワークが欲しい - http://rubikitch.com/に移転しました
expectationsã«æ¿èãã®ä¿ºãããã£ã¨ä½ã£ãããexpectations for elispãexpectations.elããæ¤ç´¢ãã¥ããã¨æã£ã¦el-expectations.elã«ãã¨ããã
ãããªææ³ã§ãã¹ããæ¸ãããæ¬ä½ã®è©ä¾¡çµæãæå¾ å¤ã¨ãããããã°ãã¹ããéããæ¬å®¶expectationsã«ãªãæ©è½ã¨ãã¦ãdescãã§ã³ã¡ã³ããæ¸ãããã¨ããã ãããããªãããªãã¿ãªã®ã§ãã¹ãåã§ã¯ãªãï½
(expectations (desc ã³ã¡ã³ã) (expect æå¾ å¤ æ¬ä½) (expect ...) ... )
å ·ä½çãªã³ã¼ãã¯ãããªã®ã
(expectations (desc "simple expectation") (expect 3 ; (+ 1 2) ã 3 ã«ãªãã¹ãã (+ 1 2)) (expect "hoge" ; (concat "ho" "ge") ã "hoge" ã«ãªãã¹ãã (concat "ho" "ge")) (expect "fuga" ; ãã®è©ä¾¡çµæã "fuga" ã«ãªãã¹ãã (set-buffer (get-buffer-create "tmp")) (erase-buffer) (insert "fuga") (buffer-string)) (desc "extended expectation") (expect (buffer "*scratch*") ; #<buffer *scratch*> ã«ãªãã¹ãã (with-current-buffer "*scratch*" (current-buffer))) (expect (regexp "o") ; "hoge" =~ /o/ ã§ããã¹ãã "hoge") (expect (type integer) ; 3 ã¯æ´æ°ã§ããã¹ãã 3) (desc "error expectation") (expect (error arith-error) ; 0é¤ç®ã¯arith-errorãèµ·ããã¹ãã (/ 1 0)) (expect (error) ; 0é¤ç®ã¯ä½ã§ãããããã¨ã©ã¼ã§ããã¹ãã (/ 1 0)))
ã©ããç°¡åã§ããï¼
elispã®ãã¹ãæ¸ãã®ããã©ãããã¨æã£ã¦ã人ã試ãã¦ã¿ã価å¤ã¯ãããæè¨ãããã
ã¤ã³ã¹ãã¼ã«
M-x install-elisp-from-emacswiki el-expectations.el
ã§EmacsWikiãããã£ã¦ãï¼ãã©ã¦ã¶ã§è¦ãã«ã¯âã¸ã©ããã
http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
使ãæ¹
- expectationsã®Så¼ãM-C-xã¨ãã§evalã
- M-x expectations-execute ã§ãã¹ãå®è¡ãâé »ç¹ã«å®è¡ãããªããã¼ãã¤ã³ããã¨ãã¨ããã
- 失æãããã¹ãããã£ãã C-x ` ï¼next-errorï¼ãprevious-errorã§è¾¿ãã
ãã ãç¾æç¹ã§ã¯ã²ã¨ã¤ã®ãã¡ã¤ã«ã«ãµãã¤ä»¥ä¸ã®expectationsã®Så¼ã¯æ¸ããªãå¶éãããããµãã¤ä»¥ä¸æ¸ãã¦ãã¾ãã¨C-x `ã§ã³ã±ã¦ãã¾ãããã®å¶éã¯ãªããã¹ãã ãªâ¦
æåæã®å®è¡çµæ
âã®ä¾ãå®è¡ããçµæ㯠*expectations result* ãããã¡ã«ãããªé¢¨ã«åºãã
Executing expectations in nil... 1 :============ simple expectation ============ 2 :OK 3 :OK 4 :OK 5 :=========== extended expectation =========== 6 :OK 7 :OK 8 :OK 9 :============ error expectation ============ 10 :OK 11 :OK
失ææã®å®è¡çµæ
æåæããã¤ã¾ããã®ã§å¤±ææã®çµæãè²¼ã£ã¨ãã
(expectations (desc "error test") (expect 4 (error "hoge") 4) (desc "eval") (expect 5 4) (expect "hoge" "hage") (expect '(1) '(2)) (expect (get-buffer-create "buf1") (get-buffer-create "buf2")) (desc "buffer") (expect (buffer "*scratch*") (get-buffer-create "*fail*")) (desc "regexp") (expect (regexp "o") "hage") (desc "type") (expect (type string) 1) (desc "error") (expect (error arith-error) (/ 1 1)) (expect (error end-of-file) (/ 1 0)) (expect (error) (/ 1 1)) )
ãããå®è¡ãã¦ã¿ãã¨ãããªãã
Executing expectations in /m/home/rubikitch/emacs/lisp/el-expectations-failure-sample.el... 1 :================ error test ================ 2 :ERROR: (error hoge) 3 :=================== eval =================== 4 :FAIL: Expected <5> but was <4> 5 :FAIL: Expected <"hoge"> but was <"hage"> 6 :FAIL: Expected <(1)> but was <(2)> 7 :FAIL: Expected <#<buffer buf1>> but was <#<buffer buf2>> 8 :================== buffer ================== 9 :FAIL: Expected <#<buffer *scratch*>> but was <#<buffer *fail*>> 10 :================== regexp ================== 11 :FAIL: "hage" should match /o/ 12 :=================== type =================== 13 :FAIL: 1 is not a string 14 :================== error ================== 15 :FAIL: should raise <arith-error>, but no error was raised 16 :FAIL: should raise <end-of-file>, but raised <arith-error> 17 :FAIL: should raise any error, but no error was raised
追è¨ï¼ãããã¢ã¼ã
ä»è¨èªã®ãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ã®ããã«ã³ãã³ãã©ã¤ã³ãããå®è¡ã§ããããã«ãã¨ããã
以ä¸ã®ã·ã§ã«ã¹ã¯ãªãããel-expectationsã¨ããååã§ä¿åããã
ãããã¢ã¼ãã§å®è¡ãããã¨ã§ãã©ã¤ãã©ãªã®requireå¿ãã¨ãã®ãã¹ãæªç¶ã«é²ããã¨ãã§ãããEmacsã®ä¸ã ã¨requireããã¦ããç¶æ ãªã®ã§ã¤ãã¤ãrequireãå ¥ããã®ãå¿ãã¦ãã¾ãã®ã§ãããã¨ã.emacsã«å½±é¿ãããªãã®ã§è¨å®ä¾åã«ãªã£ã¦ããªããã¨ã確ãããããã
#!/bin/sh EMACS=emacs OPTIONS="-L . -L $HOME/emacs/lisp" OUTPUT=/tmp/.el-expectations $EMACS -q --no-site-file --batch $OPTIONS -l el-expectations -f batch-expectations $1 $OUTPUT ret=$? cat $OUTPUT rm $OUTPUT exit $ret
ã§ãã£ã¦ãããããã«
$ el-expectations el-expectations-success-sample.el Loading subst-ksc... Loading subst-gb2312... Loading subst-big5... Loading subst-jis... Executing expectations in /m/home/rubikitch/emacs/lisp/el-expectations-success-sample.el... 1 :========== run-hook-with-args-until-success ========== 2 :OK 3 :OK 4 :OK 5 :======================= buffer ======================= 6 :OK 7 :OK 8 :======================= regexp ======================= 9 :OK 10 :======================== type ======================== 11 :OK 12 :OK 13 :======================= error ======================= 14 :OK 15 :OK 16 :======================== eval ======================== 17 :OK 18 :OK 12 expectations, 0 failures, 0 errors $ el-expectations el-expectations-failure-sample.el Loading subst-ksc... Loading subst-gb2312... Loading subst-big5... Loading subst-jis... Executing expectations in /m/home/rubikitch/emacs/lisp/el-expectations-failure-sample.el... 1 :===================== error test ===================== 2 :ERROR: (error hoge) 3 :======================== eval ======================== 4 :FAIL: Expected <5> but was <4> 5 :FAIL: Expected <"hoge"> but was <"hage"> 6 :FAIL: Expected <(1)> but was <(2)> 7 :FAIL: Expected <#<buffer buf1>> but was <#<buffer buf2>> 8 :======================= buffer ======================= 9 :FAIL: Expected <#<buffer *scratch*>> but was <#<buffer *fail*>> 10 :======================= regexp ======================= 11 :FAIL: "hage" should match /o/ 12 :======================== type ======================== 13 :FAIL: 1 is not a string 14 :======================= error ======================= 15 :FAIL: should raise <arith-error>, but no error was raised 16 :FAIL: should raise <end-of-file>, but raised <arith-error> 17 :FAIL: should raise any error, but no error was raised 11 expectations, 10 failures, 1 errors zsh: exit 11 el-expectations el-expectations-failure-sample.el