aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGlenn Morris2013-07-11 09:13:38 -0700
committerGlenn Morris2013-07-11 09:13:38 -0700
commita19b3c2d975c605c3ed76f1c178cdec7c3c7bdcf (patch)
treecd87d97c915194a3e615fac8445c90b7419876b0 /test
parent17bd3d0493fa7d0ecfa60a646141abebfc8290eb (diff)
downloademacs-a19b3c2d975c605c3ed76f1c178cdec7c3c7bdcf.tar.gz
emacs-a19b3c2d975c605c3ed76f1c178cdec7c3c7bdcf.zip
Stop reimplementing a bunch of cl- functions in ert
* lisp/emacs-lisp/ert.el: Require cl-lib at runtime too. (ert--cl-do-remf, ert--remprop, ert--remove-if-not) (ert--intersection, ert--set-difference, ert--set-difference-eq) (ert--union, ert--gensym-counter, ert--gensym-counter) (ert--coerce-to-vector, ert--remove*, ert--string-position) (ert--mismatch, ert--subseq): Remove reimplementations of cl funcs. (ert-make-test-unbound, ert--expand-should-1) (ert--expand-should, ert--should-error-handle-error) (should-error, ert--explain-equal-rec) (ert--plist-difference-explanation, ert-select-tests) (ert--make-stats, ert--remove-from-list, ert--string-first-line): Use cl-lib functions rather than reimplementations. * test/automated/ert-tests.el: Require cl-lib at runtime too. (ert-test-special-operator-p): Use cl-gensym rather than ert-- version. (ert-test-remprop, ert-test-remove-if-not, ert-test-remove*) (ert-test-set-functions, ert-test-gensym) (ert-test-coerce-to-vector, ert-test-string-position) (ert-test-mismatch): Remove tests. * test/automated/cl-lib.el: New, split from ert-tests.el.
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog8
-rw-r--r--test/automated/cl-lib.el198
-rw-r--r--test/automated/ert-tests.el171
3 files changed, 208 insertions, 169 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 29aa736e8ab..1282ff07246 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,5 +1,13 @@
12013-07-11 Glenn Morris <rgm@gnu.org> 12013-07-11 Glenn Morris <rgm@gnu.org>
2 2
3 * automated/ert-tests.el: Require cl-lib at runtime too.
4 (ert-test-special-operator-p): Use cl-gensym rather than ert-- version.
5 (ert-test-remprop, ert-test-remove-if-not, ert-test-remove*)
6 (ert-test-set-functions, ert-test-gensym)
7 (ert-test-coerce-to-vector, ert-test-string-position)
8 (ert-test-mismatch): Remove tests.
9 * automated/cl-lib.el: New, split from ert-tests.el.
10
3 * automated/ruby-mode-tests.el (ruby-deftest-move-to-block): 11 * automated/ruby-mode-tests.el (ruby-deftest-move-to-block):
4 Goto point-min. 12 Goto point-min.
5 (works-on-do, zero-is-noop, ok-with-three, ok-with-minus-two) 13 (works-on-do, zero-is-noop, ok-with-three, ok-with-minus-two)
diff --git a/test/automated/cl-lib.el b/test/automated/cl-lib.el
new file mode 100644
index 00000000000..3a339e01734
--- /dev/null
+++ b/test/automated/cl-lib.el
@@ -0,0 +1,198 @@
1;;; cl-lib.el --- tests for emacs-lisp/cl-lib.el
2
3;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; This program is free software: you can redistribute it and/or
8;; modify it under the terms of the GNU General Public License as
9;; published by the Free Software Foundation, either version 3 of the
10;; License, or (at your option) any later version.
11;;
12;; This program is distributed in the hope that it will be useful, but
13;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15;; General Public License for more details.
16;;
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20;;; Commentary:
21
22;; Extracted from ert-tests.el, back when ert used to reimplement some
23;; cl functions.
24
25;;; Code:
26
27(require 'cl-lib)
28(require 'ert)
29
30(ert-deftest cl-lib-test-remprop ()
31 (let ((x (cl-gensym)))
32 (should (equal (symbol-plist x) '()))
33 ;; Remove nonexistent property on empty plist.
34 (cl-remprop x 'b)
35 (should (equal (symbol-plist x) '()))
36 (put x 'a 1)
37 (should (equal (symbol-plist x) '(a 1)))
38 ;; Remove nonexistent property on nonempty plist.
39 (cl-remprop x 'b)
40 (should (equal (symbol-plist x) '(a 1)))
41 (put x 'b 2)
42 (put x 'c 3)
43 (put x 'd 4)
44 (should (equal (symbol-plist x) '(a 1 b 2 c 3 d 4)))
45 ;; Remove property that is neither first nor last.
46 (cl-remprop x 'c)
47 (should (equal (symbol-plist x) '(a 1 b 2 d 4)))
48 ;; Remove last property from a plist of length >1.
49 (cl-remprop x 'd)
50 (should (equal (symbol-plist x) '(a 1 b 2)))
51 ;; Remove first property from a plist of length >1.
52 (cl-remprop x 'a)
53 (should (equal (symbol-plist x) '(b 2)))
54 ;; Remove property when there is only one.
55 (cl-remprop x 'b)
56 (should (equal (symbol-plist x) '()))))
57
58(ert-deftest cl-lib-test-remove-if-not ()
59 (let ((list (list 'a 'b 'c 'd))
60 (i 0))
61 (let ((result (cl-remove-if-not (lambda (x)
62 (should (eql x (nth i list)))
63 (cl-incf i)
64 (member i '(2 3)))
65 list)))
66 (should (equal i 4))
67 (should (equal result '(b c)))
68 (should (equal list '(a b c d)))))
69 (should (equal '()
70 (cl-remove-if-not (lambda (_x) (should nil)) '()))))
71
72(ert-deftest cl-lib-test-remove ()
73 (let ((list (list 'a 'b 'c 'd))
74 (key-index 0)
75 (test-index 0))
76 (let ((result
77 (cl-remove 'foo list
78 :key (lambda (x)
79 (should (eql x (nth key-index list)))
80 (prog1
81 (list key-index x)
82 (cl-incf key-index)))
83 :test
84 (lambda (a b)
85 (should (eql a 'foo))
86 (should (equal b (list test-index
87 (nth test-index list))))
88 (cl-incf test-index)
89 (member test-index '(2 3))))))
90 (should (equal key-index 4))
91 (should (equal test-index 4))
92 (should (equal result '(a d)))
93 (should (equal list '(a b c d)))))
94 (let ((x (cons nil nil))
95 (y (cons nil nil)))
96 (should (equal (cl-remove x (list x y))
97 ;; or (list x), since we use `equal' -- the
98 ;; important thing is that only one element got
99 ;; removed, this proves that the default test is
100 ;; `eql', not `equal'
101 (list y)))))
102
103
104(ert-deftest cl-lib-test-set-functions ()
105 (let ((c1 (cons nil nil))
106 (c2 (cons nil nil))
107 (sym (make-symbol "a")))
108 (let ((e '())
109 (a (list 'a 'b sym nil "" "x" c1 c2))
110 (b (list c1 'y 'b sym 'x)))
111 (should (equal (cl-set-difference e e) e))
112 (should (equal (cl-set-difference a e) a))
113 (should (equal (cl-set-difference e a) e))
114 (should (equal (cl-set-difference a a) e))
115 (should (equal (cl-set-difference b e) b))
116 (should (equal (cl-set-difference e b) e))
117 (should (equal (cl-set-difference b b) e))
118 ;; Note: this test (and others) is sensitive to the order of the
119 ;; result, which is not documented.
120 (should (equal (cl-set-difference a b) (list c2 "x" "" nil 'a)))
121 (should (equal (cl-set-difference b a) (list 'x 'y)))
122
123 ;; We aren't testing whether this is really using `eq' rather than `eql'.
124 (should (equal (cl-set-difference e e :test 'eq) e))
125 (should (equal (cl-set-difference a e :test 'eq) a))
126 (should (equal (cl-set-difference e a :test 'eq) e))
127 (should (equal (cl-set-difference a a :test 'eq) e))
128 (should (equal (cl-set-difference b e :test 'eq) b))
129 (should (equal (cl-set-difference e b :test 'eq) e))
130 (should (equal (cl-set-difference b b :test 'eq) e))
131 (should (equal (cl-set-difference a b :test 'eq) (list c2 "x" "" nil 'a)))
132 (should (equal (cl-set-difference b a :test 'eq) (list 'x 'y)))
133
134 (should (equal (cl-union e e) e))
135 (should (equal (cl-union a e) a))
136 (should (equal (cl-union e a) a))
137 (should (equal (cl-union a a) a))
138 (should (equal (cl-union b e) b))
139 (should (equal (cl-union e b) b))
140 (should (equal (cl-union b b) b))
141 (should (equal (cl-union a b) (list 'x 'y 'a 'b sym nil "" "x" c1 c2)))
142
143 (should (equal (cl-union b a) (list 'x 'y 'a 'b sym nil "" "x" c1 c2)))
144
145 (should (equal (cl-intersection e e) e))
146 (should (equal (cl-intersection a e) e))
147 (should (equal (cl-intersection e a) e))
148 (should (equal (cl-intersection a a) a))
149 (should (equal (cl-intersection b e) e))
150 (should (equal (cl-intersection e b) e))
151 (should (equal (cl-intersection b b) b))
152 (should (equal (cl-intersection a b) (list sym 'b c1)))
153 (should (equal (cl-intersection b a) (list sym 'b c1))))))
154
155(ert-deftest cl-lib-test-gensym ()
156 ;; Since the expansion of `should' calls `cl-gensym' and thus has a
157 ;; side-effect on `cl--gensym-counter', we have to make sure all
158 ;; macros in our test body are expanded before we rebind
159 ;; `cl--gensym-counter' and run the body. Otherwise, the test would
160 ;; fail if run interpreted.
161 (let ((body (byte-compile
162 '(lambda ()
163 (should (equal (symbol-name (cl-gensym)) "G0"))
164 (should (equal (symbol-name (cl-gensym)) "G1"))
165 (should (equal (symbol-name (cl-gensym)) "G2"))
166 (should (equal (symbol-name (cl-gensym "foo")) "foo3"))
167 (should (equal (symbol-name (cl-gensym "bar")) "bar4"))
168 (should (equal cl--gensym-counter 5))))))
169 (let ((cl--gensym-counter 0))
170 (funcall body))))
171
172(ert-deftest cl-lib-test-coerce-to-vector ()
173 (let* ((a (vector))
174 (b (vector 1 a 3))
175 (c (list))
176 (d (list b a)))
177 (should (eql (cl-coerce a 'vector) a))
178 (should (eql (cl-coerce b 'vector) b))
179 (should (equal (cl-coerce c 'vector) (vector)))
180 (should (equal (cl-coerce d 'vector) (vector b a)))))
181
182(ert-deftest cl-lib-test-string-position ()
183 (should (eql (cl-position ?x "") nil))
184 (should (eql (cl-position ?a "abc") 0))
185 (should (eql (cl-position ?b "abc") 1))
186 (should (eql (cl-position ?c "abc") 2))
187 (should (eql (cl-position ?d "abc") nil))
188 (should (eql (cl-position ?A "abc") nil)))
189
190(ert-deftest cl-lib-test-mismatch ()
191 (should (eql (cl-mismatch "" "") nil))
192 (should (eql (cl-mismatch "" "a") 0))
193 (should (eql (cl-mismatch "a" "a") nil))
194 (should (eql (cl-mismatch "ab" "a") 1))
195 (should (eql (cl-mismatch "Aa" "aA") 0))
196 (should (eql (cl-mismatch '(a b c) '(a b d)) 2)))
197
198;;; cl-lib.el ends here
diff --git a/test/automated/ert-tests.el b/test/automated/ert-tests.el
index 0c3c3692c1d..36864377ec9 100644
--- a/test/automated/ert-tests.el
+++ b/test/automated/ert-tests.el
@@ -26,11 +26,9 @@
26 26
27;;; Code: 27;;; Code:
28 28
29(eval-when-compile 29(require 'cl-lib)
30 (require 'cl-lib))
31(require 'ert) 30(require 'ert)
32 31
33
34;;; Self-test that doesn't rely on ERT, for bootstrapping. 32;;; Self-test that doesn't rely on ERT, for bootstrapping.
35 33
36;; This is used to test that bodies actually run. 34;; This is used to test that bodies actually run.
@@ -578,7 +576,7 @@ This macro is used to test if macroexpansion in `should' works."
578 (should (ert--special-operator-p 'if)) 576 (should (ert--special-operator-p 'if))
579 (should-not (ert--special-operator-p 'car)) 577 (should-not (ert--special-operator-p 'car))
580 (should-not (ert--special-operator-p 'ert--special-operator-p)) 578 (should-not (ert--special-operator-p 'ert--special-operator-p))
581 (let ((b (ert--gensym))) 579 (let ((b (cl-gensym)))
582 (should-not (ert--special-operator-p b)) 580 (should-not (ert--special-operator-p b))
583 (fset b 'if) 581 (fset b 'if)
584 (should (ert--special-operator-p b)))) 582 (should (ert--special-operator-p b))))
@@ -626,171 +624,6 @@ This macro is used to test if macroexpansion in `should' works."
626 :explanation nil) 624 :explanation nil)
627 )))))) 625 ))))))
628 626
629(ert-deftest ert-test-remprop ()
630 (let ((x (ert--gensym)))
631 (should (equal (symbol-plist x) '()))
632 ;; Remove nonexistent property on empty plist.
633 (ert--remprop x 'b)
634 (should (equal (symbol-plist x) '()))
635 (put x 'a 1)
636 (should (equal (symbol-plist x) '(a 1)))
637 ;; Remove nonexistent property on nonempty plist.
638 (ert--remprop x 'b)
639 (should (equal (symbol-plist x) '(a 1)))
640 (put x 'b 2)
641 (put x 'c 3)
642 (put x 'd 4)
643 (should (equal (symbol-plist x) '(a 1 b 2 c 3 d 4)))
644 ;; Remove property that is neither first nor last.
645 (ert--remprop x 'c)
646 (should (equal (symbol-plist x) '(a 1 b 2 d 4)))
647 ;; Remove last property from a plist of length >1.
648 (ert--remprop x 'd)
649 (should (equal (symbol-plist x) '(a 1 b 2)))
650 ;; Remove first property from a plist of length >1.
651 (ert--remprop x 'a)
652 (should (equal (symbol-plist x) '(b 2)))
653 ;; Remove property when there is only one.
654 (ert--remprop x 'b)
655 (should (equal (symbol-plist x) '()))))
656
657(ert-deftest ert-test-remove-if-not ()
658 (let ((list (list 'a 'b 'c 'd))
659 (i 0))
660 (let ((result (ert--remove-if-not (lambda (x)
661 (should (eql x (nth i list)))
662 (cl-incf i)
663 (member i '(2 3)))
664 list)))
665 (should (equal i 4))
666 (should (equal result '(b c)))
667 (should (equal list '(a b c d)))))
668 (should (equal '()
669 (ert--remove-if-not (lambda (_x) (should nil)) '()))))
670
671(ert-deftest ert-test-remove* ()
672 (let ((list (list 'a 'b 'c 'd))
673 (key-index 0)
674 (test-index 0))
675 (let ((result
676 (ert--remove* 'foo list
677 :key (lambda (x)
678 (should (eql x (nth key-index list)))
679 (prog1
680 (list key-index x)
681 (cl-incf key-index)))
682 :test
683 (lambda (a b)
684 (should (eql a 'foo))
685 (should (equal b (list test-index
686 (nth test-index list))))
687 (cl-incf test-index)
688 (member test-index '(2 3))))))
689 (should (equal key-index 4))
690 (should (equal test-index 4))
691 (should (equal result '(a d)))
692 (should (equal list '(a b c d)))))
693 (let ((x (cons nil nil))
694 (y (cons nil nil)))
695 (should (equal (ert--remove* x (list x y))
696 ;; or (list x), since we use `equal' -- the
697 ;; important thing is that only one element got
698 ;; removed, this proves that the default test is
699 ;; `eql', not `equal'
700 (list y)))))
701
702
703(ert-deftest ert-test-set-functions ()
704 (let ((c1 (cons nil nil))
705 (c2 (cons nil nil))
706 (sym (make-symbol "a")))
707 (let ((e '())
708 (a (list 'a 'b sym nil "" "x" c1 c2))
709 (b (list c1 'y 'b sym 'x)))
710 (should (equal (ert--set-difference e e) e))
711 (should (equal (ert--set-difference a e) a))
712 (should (equal (ert--set-difference e a) e))
713 (should (equal (ert--set-difference a a) e))
714 (should (equal (ert--set-difference b e) b))
715 (should (equal (ert--set-difference e b) e))
716 (should (equal (ert--set-difference b b) e))
717 (should (equal (ert--set-difference a b) (list 'a nil "" "x" c2)))
718 (should (equal (ert--set-difference b a) (list 'y 'x)))
719
720 ;; We aren't testing whether this is really using `eq' rather than `eql'.
721 (should (equal (ert--set-difference-eq e e) e))
722 (should (equal (ert--set-difference-eq a e) a))
723 (should (equal (ert--set-difference-eq e a) e))
724 (should (equal (ert--set-difference-eq a a) e))
725 (should (equal (ert--set-difference-eq b e) b))
726 (should (equal (ert--set-difference-eq e b) e))
727 (should (equal (ert--set-difference-eq b b) e))
728 (should (equal (ert--set-difference-eq a b) (list 'a nil "" "x" c2)))
729 (should (equal (ert--set-difference-eq b a) (list 'y 'x)))
730
731 (should (equal (ert--union e e) e))
732 (should (equal (ert--union a e) a))
733 (should (equal (ert--union e a) a))
734 (should (equal (ert--union a a) a))
735 (should (equal (ert--union b e) b))
736 (should (equal (ert--union e b) b))
737 (should (equal (ert--union b b) b))
738 (should (equal (ert--union a b) (list 'a 'b sym nil "" "x" c1 c2 'y 'x)))
739 (should (equal (ert--union b a) (list c1 'y 'b sym 'x 'a nil "" "x" c2)))
740
741 (should (equal (ert--intersection e e) e))
742 (should (equal (ert--intersection a e) e))
743 (should (equal (ert--intersection e a) e))
744 (should (equal (ert--intersection a a) a))
745 (should (equal (ert--intersection b e) e))
746 (should (equal (ert--intersection e b) e))
747 (should (equal (ert--intersection b b) b))
748 (should (equal (ert--intersection a b) (list 'b sym c1)))
749 (should (equal (ert--intersection b a) (list c1 'b sym))))))
750
751(ert-deftest ert-test-gensym ()
752 ;; Since the expansion of `should' calls `ert--gensym' and thus has a
753 ;; side-effect on `ert--gensym-counter', we have to make sure all
754 ;; macros in our test body are expanded before we rebind
755 ;; `ert--gensym-counter' and run the body. Otherwise, the test would
756 ;; fail if run interpreted.
757 (let ((body (byte-compile
758 '(lambda ()
759 (should (equal (symbol-name (ert--gensym)) "G0"))
760 (should (equal (symbol-name (ert--gensym)) "G1"))
761 (should (equal (symbol-name (ert--gensym)) "G2"))
762 (should (equal (symbol-name (ert--gensym "foo")) "foo3"))
763 (should (equal (symbol-name (ert--gensym "bar")) "bar4"))
764 (should (equal ert--gensym-counter 5))))))
765 (let ((ert--gensym-counter 0))
766 (funcall body))))
767
768(ert-deftest ert-test-coerce-to-vector ()
769 (let* ((a (vector))
770 (b (vector 1 a 3))
771 (c (list))
772 (d (list b a)))
773 (should (eql (ert--coerce-to-vector a) a))
774 (should (eql (ert--coerce-to-vector b) b))
775 (should (equal (ert--coerce-to-vector c) (vector)))
776 (should (equal (ert--coerce-to-vector d) (vector b a)))))
777
778(ert-deftest ert-test-string-position ()
779 (should (eql (ert--string-position ?x "") nil))
780 (should (eql (ert--string-position ?a "abc") 0))
781 (should (eql (ert--string-position ?b "abc") 1))
782 (should (eql (ert--string-position ?c "abc") 2))
783 (should (eql (ert--string-position ?d "abc") nil))
784 (should (eql (ert--string-position ?A "abc") nil)))
785
786(ert-deftest ert-test-mismatch ()
787 (should (eql (ert--mismatch "" "") nil))
788 (should (eql (ert--mismatch "" "a") 0))
789 (should (eql (ert--mismatch "a" "a") nil))
790 (should (eql (ert--mismatch "ab" "a") 1))
791 (should (eql (ert--mismatch "Aa" "aA") 0))
792 (should (eql (ert--mismatch '(a b c) '(a b d)) 2)))
793
794(ert-deftest ert-test-string-first-line () 627(ert-deftest ert-test-string-first-line ()
795 (should (equal (ert--string-first-line "") "")) 628 (should (equal (ert--string-first-line "") ""))
796 (should (equal (ert--string-first-line "abc") "abc")) 629 (should (equal (ert--string-first-line "abc") "abc"))