]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy-test.el: Add testing
authorOleh Krehel <ohwoeowho@gmail.com>
Thu, 19 Mar 2015 17:08:30 +0000 (18:08 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Thu, 19 Mar 2015 17:10:10 +0000 (18:10 +0100)
* Makefile: Add a test and compile target.

.travis.yml [new file with mode: 0644]
Makefile [new file with mode: 0644]
ivy-test.el [new file with mode: 0644]

diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..1f5dbc7
--- /dev/null
@@ -0,0 +1,12 @@
+language: emacs-lisp
+env:
+  matrix:
+    - EMACS=emacs24
+
+before_install:
+  - sudo add-apt-repository -y ppa:cassou/emacs
+  - sudo apt-get update -qq
+  - sudo apt-get install -qq $EMACS
+
+script:
+  - make test
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..453f709
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+emacs ?= emacs
+
+LOAD = -l ivy.el -l swiper.el
+
+.PHONY: all compile clean
+
+all: test
+
+test:
+       $(emacs) -batch $(LOAD) -l ivy-test.el -f ert-run-tests-batch-and-exit
+
+compile:
+       $(emacs) -batch $(LOAD) --eval "(mapc #'byte-compile-file '(\"ivy.el\" \"swiper.el\"))"
+
+clean:
+       rm -f *.elc
diff --git a/ivy-test.el b/ivy-test.el
new file mode 100644 (file)
index 0000000..af17414
--- /dev/null
@@ -0,0 +1,46 @@
+(require 'ert)
+
+(defvar ivy-expr nil
+  "Holds a test expression to evaluate with `ivy-eval'.")
+
+(defvar ivy-result nil
+  "Holds the eval result of `ivy-expr' by `ivy-eval'.")
+
+(defun ivy-eval ()
+  "Evaluate `ivy-expr'."
+  (interactive)
+  (setq ivy-result (eval ivy-expr)))
+
+(global-set-key (kbd "C-c e") 'ivy-eval)
+
+(defun ivy-with (expr keys)
+  "Evaluate EXPR followed by KEYS."
+  (let ((ivy-expr expr))
+    (execute-kbd-macro
+     (vconcat (kbd "C-c e")
+              (kbd keys)))
+    ivy-result))
+
+(ert-deftest ivy-read ()
+  (should (equal
+           (ivy-read "pattern: " nil)
+           nil))
+  (should (equal
+           (ivy-read "pattern: " '("42"))
+           "42"))
+  (should (equal
+           (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
+                     "C-m")
+           "blue"))
+  (should (equal
+           (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
+                     "y C-m")
+           "yellow"))
+  (should (equal
+           (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
+                     "y DEL b C-m")
+           "blue"))
+  (should (equal
+           (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
+                     "z C-m")
+           nil)))