diff options
| author | Aurélien Aptel | 2015-11-16 01:00:25 +0100 |
|---|---|---|
| committer | Ted Zlatanov | 2015-11-18 14:24:35 -0500 |
| commit | 955e25dbcd0519d115f58b275923a71c04579e83 (patch) | |
| tree | a75f83e478b62b1de689c1e8c91e4a6cb67f68f3 /modules/mod-test/test.el | |
| parent | 218caccd968d16a1a8d1f336e72f211c3e169142 (diff) | |
| download | emacs-955e25dbcd0519d115f58b275923a71c04579e83.tar.gz emacs-955e25dbcd0519d115f58b275923a71c04579e83.zip | |
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>
Diffstat (limited to 'modules/mod-test/test.el')
| -rw-r--r-- | modules/mod-test/test.el | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/modules/mod-test/test.el b/modules/mod-test/test.el new file mode 100644 index 00000000000..1242b6a2ec2 --- /dev/null +++ b/modules/mod-test/test.el | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | ;; | ||
| 2 | ;; Dynamic modules tests | ||
| 3 | ;; | ||
| 4 | |||
| 5 | (require 'ert) | ||
| 6 | |||
| 7 | (add-to-list 'load-path (file-name-directory (or #$ (expand-file-name (buffer-file-name))))) | ||
| 8 | (require 'mod-test) | ||
| 9 | |||
| 10 | ;; | ||
| 11 | ;; basic tests | ||
| 12 | ;; | ||
| 13 | |||
| 14 | (ert-deftest mod-test-sum-test () | ||
| 15 | (should (= (mod-test-sum 1 2) 3))) | ||
| 16 | |||
| 17 | (ert-deftest mod-test-sum-docstring () | ||
| 18 | (should (string= (documentation 'mod-test-sum) "Return A + B"))) | ||
| 19 | |||
| 20 | ;; | ||
| 21 | ;; non-local exists (throw, signal) | ||
| 22 | ;; | ||
| 23 | |||
| 24 | (ert-deftest mod-test-non-local-exit-signal-test () | ||
| 25 | (should-error (mod-test-signal))) | ||
| 26 | |||
| 27 | (ert-deftest mod-test-non-local-exit-throw-test () | ||
| 28 | (should (equal | ||
| 29 | (catch 'tag | ||
| 30 | (mod-test-throw) | ||
| 31 | (ert-fail "expected throw")) | ||
| 32 | 65))) | ||
| 33 | |||
| 34 | (ert-deftest mod-test-non-local-exit-funcall-normal () | ||
| 35 | (should (equal (mod-test-non-local-exit-funcall (lambda () 23)) | ||
| 36 | 23))) | ||
| 37 | |||
| 38 | (ert-deftest mod-test-non-local-exit-funcall-signal () | ||
| 39 | (should (equal (mod-test-non-local-exit-funcall (lambda () (signal 'error '(32)))) | ||
| 40 | '(signal error (32))))) | ||
| 41 | |||
| 42 | (ert-deftest mod-test-non-local-exit-funcall-throw () | ||
| 43 | (should (equal (mod-test-non-local-exit-funcall (lambda () (throw 'tag 32))) | ||
| 44 | '(throw tag 32)))) | ||
| 45 | |||
| 46 | ;; | ||
| 47 | ;; string | ||
| 48 | ;; | ||
| 49 | |||
| 50 | (defun multiply-string (s n) | ||
| 51 | (let ((res "")) | ||
| 52 | (dotimes (i n res) | ||
| 53 | (setq res (concat res s))))) | ||
| 54 | |||
| 55 | (ert-deftest mod-test-globref-make-test () | ||
| 56 | (let ((mod-str (mod-test-globref-make)) | ||
| 57 | (ref-str (multiply-string "abcdefghijklmnopqrstuvwxyz" 100))) | ||
| 58 | (garbage-collect) ;; XXX: not enough to really test but it's something.. | ||
| 59 | (should (string= ref-str mod-str)))) | ||
| 60 | |||
| 61 | (ert-deftest mod-test-string-a-to-b-test () | ||
| 62 | (should (string= (mod-test-string-a-to-b "aaa") "bbb"))) | ||
| 63 | |||
| 64 | ;; | ||
| 65 | ;; user-pointer | ||
| 66 | ;; | ||
| 67 | |||
| 68 | (ert-deftest mod-test-userptr-fun-test () | ||
| 69 | (let* ((n 42) | ||
| 70 | (v (mod-test-userptr-make n)) | ||
| 71 | (r (mod-test-userptr-get v))) | ||
| 72 | |||
| 73 | (should (eq (type-of v) 'user-ptr)) | ||
| 74 | (should (integerp r)) | ||
| 75 | (should (= r n)))) | ||
| 76 | |||
| 77 | ;; TODO: try to test finalizer | ||
| 78 | |||
| 79 | ;; | ||
| 80 | ;; vectors | ||
| 81 | ;; | ||
| 82 | |||
| 83 | (ert-deftest mod-test-vector-test () | ||
| 84 | (dolist (s '(2 10 100 1000)) | ||
| 85 | (dolist (e '(42 foo "foo")) | ||
| 86 | (let* ((v-ref (make-vector 2 e)) | ||
| 87 | (eq-ref (eq (aref v-ref 0) (aref v-ref 1))) | ||
| 88 | (v-test (make-vector s nil))) | ||
| 89 | |||
| 90 | (should (eq (mod-test-vector-fill v-test e) t)) | ||
| 91 | (should (eq (mod-test-vector-eq v-test e) eq-ref)))))) | ||