Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic test case. #162

Merged
merged 1 commit into from Sep 16, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions etc/auto-complete-test.el
@@ -0,0 +1,52 @@
(require 'ert)

(require 'auto-complete)
(require 'auto-complete-config)

(defmacro auto-complete-test:common (&rest body)
(declare (indent 0) (debug t))
`(save-excursion
;; (with-current-buffer "*scratch*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この行は要らないのでは?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9行目に限れば不要です。

(with-temp-buffer
(switch-to-buffer (current-buffer))
(auto-complete-mode 1)
(emacs-lisp-mode)
,@body
(ac-menu-delete)
)))

(ert-deftest auto-complete-test ()
(auto-complete-test:common
(defvar ac-source-test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defvar を使うと、どちらかのテストで指定した変数の値が使われなくなってしまいます。 let で指定するのが良いんじゃないでしょうか。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#163 で修正しました

'((candidates list "Foo" "FooBar" "Bar" "Baz" "LongLongLine")))
(defvar ac-source-action-test
'((candidates list "Action1" "Action2")
(action . (lambda () (message "Done!")))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L40 もそうですが、 message を呼ぶよりは (incf counter) などとしてあとで (should (= counter 1)) でチェックするほうが良いと思います。

また、 batch モードで起動したときに、 ERT の output に message が混ざって結果が見辛くなります。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etc/test.txt から引っ張ったきたので、何も考えてませんでした。
確かにmessageはやめた方がいいと思います。
カウンターでも良いですが、依存関係を増やしていいならmockを使った方がいいかなと思ってます。

(setq ac-sources '(ac-source-test ac-source-action-test))
(should-not (popup-live-p ac-menu))
(should (eq ac-menu nil))
(insert "Foo")
(auto-complete)
(should (popup-live-p ac-menu))
(should (equal (popup-list ac-menu) '("Foo" "FooBar")))
))

(ert-deftest auto-complete-test2 ()
(auto-complete-test:common
(defvar ac-source-test
'((candidates list "Foo" "FooBar" "Bar" "Baz" "LongLongLine")))
(defvar ac-source-action-test
'((candidates list "Action1" "Action2")
(action . (lambda () (message "Done!")))))
(setq ac-sources '(ac-source-test ac-source-action-test))
(should-not (popup-live-p ac-menu))
(should (eq ac-menu nil))
(insert "Foo")
(auto-complete)
(execute-kbd-macro "B")
(ac-update-greedy)
(should (popup-live-p ac-menu))
(should (equal (popup-list ac-menu) '("FooBar")))
))

(ert-run-tests-interactively t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストの方法は、 interactive (M-x ert) でやるのと batch でやる方法があるので、どちらでも起動出来るようにするべきだと思います。なので、この行は消すべきかと。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おっしゃる通りだと思います。