1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-06 11:50:51 -08:00
emacs/modules/mod-test/test.el
Aurélien Aptel 955e25dbcd Add dynamic module test and helper script
Add 'modhelp.py' script (python2) to automate module testing and
module generation.

To build and test all modules in the modules/ dir
  $ ./modhelp.py test

To generate a module from template code (good starting point)
  $ ./modhelp init mynewtestmodule

See the script -h option for more documentation.

* modules/modhelp.py: New module helper script.
* modules/mod-test/Makefile: New file. Makefile for the test module.
* modules/mod-test/mod-test.c: New file. Test module source file.
* modules/mod-test/test.el: New file. ert test suite for the test module.
* modules/.gitignore: New file. Local .gitignore file.

Co-authored-by: Philipp Stephani <phst@google.com>
2015-11-18 14:24:35 -05:00

91 lines
2.3 KiB
EmacsLisp

;;
;; Dynamic modules tests
;;
(require 'ert)
(add-to-list 'load-path (file-name-directory (or #$ (expand-file-name (buffer-file-name)))))
(require 'mod-test)
;;
;; basic tests
;;
(ert-deftest mod-test-sum-test ()
(should (= (mod-test-sum 1 2) 3)))
(ert-deftest mod-test-sum-docstring ()
(should (string= (documentation 'mod-test-sum) "Return A + B")))
;;
;; non-local exists (throw, signal)
;;
(ert-deftest mod-test-non-local-exit-signal-test ()
(should-error (mod-test-signal)))
(ert-deftest mod-test-non-local-exit-throw-test ()
(should (equal
(catch 'tag
(mod-test-throw)
(ert-fail "expected throw"))
65)))
(ert-deftest mod-test-non-local-exit-funcall-normal ()
(should (equal (mod-test-non-local-exit-funcall (lambda () 23))
23)))
(ert-deftest mod-test-non-local-exit-funcall-signal ()
(should (equal (mod-test-non-local-exit-funcall (lambda () (signal 'error '(32))))
'(signal error (32)))))
(ert-deftest mod-test-non-local-exit-funcall-throw ()
(should (equal (mod-test-non-local-exit-funcall (lambda () (throw 'tag 32)))
'(throw tag 32))))
;;
;; string
;;
(defun multiply-string (s n)
(let ((res ""))
(dotimes (i n res)
(setq res (concat res s)))))
(ert-deftest mod-test-globref-make-test ()
(let ((mod-str (mod-test-globref-make))
(ref-str (multiply-string "abcdefghijklmnopqrstuvwxyz" 100)))
(garbage-collect) ;; XXX: not enough to really test but it's something..
(should (string= ref-str mod-str))))
(ert-deftest mod-test-string-a-to-b-test ()
(should (string= (mod-test-string-a-to-b "aaa") "bbb")))
;;
;; user-pointer
;;
(ert-deftest mod-test-userptr-fun-test ()
(let* ((n 42)
(v (mod-test-userptr-make n))
(r (mod-test-userptr-get v)))
(should (eq (type-of v) 'user-ptr))
(should (integerp r))
(should (= r n))))
;; TODO: try to test finalizer
;;
;; vectors
;;
(ert-deftest mod-test-vector-test ()
(dolist (s '(2 10 100 1000))
(dolist (e '(42 foo "foo"))
(let* ((v-ref (make-vector 2 e))
(eq-ref (eq (aref v-ref 0) (aref v-ref 1)))
(v-test (make-vector s nil)))
(should (eq (mod-test-vector-fill v-test e) t))
(should (eq (mod-test-vector-eq v-test e) eq-ref))))))