Skip to content

Commit

Permalink
Merge pull request #163 from tkf/travis-ci
Browse files Browse the repository at this point in the history
This PR adds:

* Automated tests in Travis CI based on the PR #162.
* AC's dependencies (popup/fuzzy) and ERT as git submodules under `lib/`.
* `travis-ci` make target in Makfile, so that tests ran on Travis CI
  server can be ran in local machine by `make travis-ci`.
  • Loading branch information
tkf committed Sep 16, 2012
2 parents 03ac748 + 6e64d18 commit 8ec385e
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "lib/fuzzy"]
path = lib/fuzzy
url = git://github.com/auto-complete/fuzzy-el.git
[submodule "lib/popup"]
path = lib/popup
url = git://github.com/auto-complete/popup-el.git
[submodule "lib/ert"]
path = lib/ert
url = git://github.com/ohler/ert.git
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: emacs-lisp
before_install:
- git submodule update --init
- if [ "$EMACS" = 'emacs-snapshot' ]; then
sudo add-apt-repository -y ppa:cassou/emacs &&
sudo apt-get update -qq &&
sudo apt-get install -qq
emacs-snapshot-el emacs-snapshot-gtk emacs-snapshot;
fi
env:
- EMACS=emacs
- EMACS=emacs-snapshot
script:
make travis-ci EMACS=$EMACS
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
VERSION=`perl -ne 'print $$1 if /;; Version: (.*)/' auto-complete.el`
PACKAGE=auto-complete-${VERSION}
EMACS=emacs

byte-compile:
emacs -Q -L . -batch -f batch-byte-compile auto-complete.el auto-complete-config.el
${EMACS} -Q -L . -batch -f batch-byte-compile auto-complete.el auto-complete-config.el

install:
emacs -Q -L . -batch -l etc/install ${DIR}
${EMACS} -Q -L . -batch -l etc/install ${DIR}

clean:
rm -f *.elc
Expand All @@ -25,3 +26,7 @@ package.tar.bz2: tar

package.zip: package
zip -r ${PACKAGE}.zip ${PACKAGE}

travis-ci:
${EMACS} --version
${EMACS} -batch -Q -l tests/run-test.el
1 change: 1 addition & 0 deletions lib/ert
Submodule ert added at 00aef6
1 change: 1 addition & 0 deletions lib/fuzzy
Submodule fuzzy added at b47d80
1 change: 1 addition & 0 deletions lib/popup
Submodule popup added at f15c82
53 changes: 53 additions & 0 deletions tests/auto-complete-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(require 'ert)

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

;; Move this into test case or setup macro once we start testing with
;; non-default config.
(ac-config-default)

(defmacro ac-test-with-common-setup (&rest body)
(declare (indent 0) (debug t))
`(save-excursion
(with-temp-buffer
(switch-to-buffer (current-buffer))
(auto-complete-mode 1)
(emacs-lisp-mode)
,@body
(ac-menu-delete)
)))

(ert-deftest ac-test-simple-invocation ()
(ac-test-with-common-setup
(let ((ac-source-test
'((candidates list "Foo" "FooBar" "Bar" "Baz" "LongLongLine")))
(ac-source-action-test
'((candidates list "Action1" "Action2")
(action . (lambda () (message "Done!")))))
(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 ac-test-simple-update ()
(ac-test-with-common-setup
(let ((ac-source-test
'((candidates list "Foo" "FooBar" "Bar" "Baz" "LongLongLine")))
(ac-source-action-test
'((candidates list "Action1" "Action2")
(action . (lambda () (message "Done!")))))
(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")))
)))
44 changes: 44 additions & 0 deletions tests/run-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;; Usage:
;;
;; emacs -Q -l tests/run-test.el # interactive mode
;; emacs -batch -Q -l tests/run-test.el # batch mode


;; Utils
(defun ac-test-join-path (path &rest rest)
"Join a list of PATHS with appropriate separator (such as /).
\(fn &rest paths)"
(if rest
(concat (file-name-as-directory path) (apply 'ac-test-join-path rest))
path))

(defvar ac-test-dir (file-name-directory load-file-name))
(defvar ac-root-dir (concat ac-test-dir ".."))


;; Setup `load-path'
(mapc (lambda (p) (add-to-list 'load-path p))
(list ac-test-dir
ac-root-dir
(ac-test-join-path ac-root-dir "lib" "popup")
(ac-test-join-path ac-root-dir "lib" "fuzzy")))


;; Use ERT from github when this Emacs does not have it
(unless (locate-library "ert")
(add-to-list
'load-path
(ac-test-join-path ac-root-dir "lib" "ert" "lisp" "emacs-lisp"))
(require 'ert-batch)
(require 'ert-ui))


;; Load tests
(load "auto-complete-test")


;; Run tests
(if noninteractive
(ert-run-tests-batch-and-exit)
(ert t))

0 comments on commit 8ec385e

Please sign in to comment.