aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Ludlam2019-10-14 20:53:24 -0400
committerStefan Monnier2019-10-15 11:08:18 -0400
commit26f5edf0c8afb0a66071a248854898ccbf66b801 (patch)
tree31c1a383832b7116b1a2ab336fc2bcf8da63113d
parent57a786db5a5c653172f994ff707f8eded3d92168 (diff)
downloademacs-26f5edf0c8afb0a66071a248854898ccbf66b801.tar.gz
emacs-26f5edf0c8afb0a66071a248854898ccbf66b801.zip
Adapt the CEDET SRecoder getset tests to use ERT
These tests were copied from CEDET from SourceForge. Author: Eric Ludlam <zappo@gnu.org>
-rw-r--r--test/lisp/cedet/srecode-utest-getset.el177
1 files changed, 177 insertions, 0 deletions
diff --git a/test/lisp/cedet/srecode-utest-getset.el b/test/lisp/cedet/srecode-utest-getset.el
new file mode 100644
index 00000000000..d69a195a128
--- /dev/null
+++ b/test/lisp/cedet/srecode-utest-getset.el
@@ -0,0 +1,177 @@
1;;; srecode/test-getset.el --- Test the getset inserter.
2
3;; Copyright (C) 2008, 2009, 2011, 2019 Free Software Foundation, Inc
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Commentary:
21;;
22;; Unit tests for the getset inserter application.
23
24;;(require 'cedet-uutil)
25(require 'srecode/semantic)
26
27;;; Code:
28(defvar srecode-utest-getset-pre-fill
29 "// Test Class for getset tests in c++.
30
31class myClass {
32public:
33 myClass() { };
34 ~myClass() { };
35 /** miscFunction
36 */
37 int miscFunction(int);
38
39private:
40 int fStartingField;
41
42};
43
44"
45 "The pre-fill class for the getset tests.")
46
47
48;;; Master Harness
49;;
50(defvar srecode-utest-getset-testfile
51 (expand-file-name
52 (concat (make-temp-name "srecode-utest-getset-") ".cpp")
53 temporary-file-directory)
54 "File used to do testing.")
55
56(ert-deftest srecode-utest-getset-output ()
57 "Test various template insertion options."
58 (save-excursion
59 (let ((testbuff (find-file-noselect srecode-utest-getset-testfile))
60 (srecode-insert-getset-fully-automatic-flag t))
61
62 (set-buffer testbuff)
63 (semantic-mode 1)
64 (srecode-load-tables-for-mode major-mode)
65 (srecode-load-tables-for-mode major-mode 'getset)
66
67 (should (srecode-table))
68 ;;(error "No template table found for mode %s" major-mode))
69
70 (condition-case nil
71 (erase-buffer)
72 (error nil))
73
74 (insert srecode-utest-getset-pre-fill)
75 (goto-char (point-min))
76
77 ;; Test PRE FILL
78 (should-not
79 (srecode-utest-getset-tagcheck '("public"
80 "myClass"
81 "myClass"
82 "miscFunction"
83 "private"
84 "fStartingField")))
85 (should-not
86 (srecode-utest-getset-jumptotag "fStartingField"))
87
88 ;; Startup with fully automatic selection.
89 (srecode-insert-getset)
90
91 ;; * Post get-set "StartingField"
92 (should-not
93 (srecode-utest-getset-tagcheck '("public"
94 "myClass"
95 "myClass"
96 "getStartingField"
97 "setStartingField"
98 "miscFunction"
99 "private"
100 "fStartingField")))
101
102 ;; Now try convenience args.
103 (goto-char (point-min))
104 (should-not
105 (srecode-utest-getset-jumptotag "fStartingField"))
106 (end-of-line)
107 (insert "\n")
108
109 (srecode-insert-getset nil "AutoInsertField")
110
111 ;; * Post get-set "AutoInsertField"
112 (should-not
113 (srecode-utest-getset-tagcheck '("public"
114 "myClass"
115 "myClass"
116 "getStartingField"
117 "setStartingField"
118 "getAutoInsertField"
119 "setAutoInsertField"
120 "miscFunction"
121 "private"
122 "fStartingField"
123 "fAutoInsertField")))
124
125 ;; Make sure all the comments are in the right place.
126 (should-not
127 (srecode-utest-getset-jumptotag "miscFunction"))
128
129 (let ((pos (point)))
130 (skip-chars-backward " \t\n") ; xemacs forward-comment is different.
131 (forward-comment -1)
132 (re-search-forward "miscFunction" pos))
133
134 ))
135 (when (file-exists-p srecode-utest-getset-testfile)
136 (delete-file srecode-utest-getset-testfile))
137 )
138
139(defun srecode-utest-getset-tagcheck (expected-members)
140 "Make sure that the tags in myClass have EXPECTED-MEMBERS."
141 (semantic-fetch-tags)
142 (let* ((mc (semantic-find-tags-by-name "myClass" (current-buffer)))
143 (mem (semantic-tag-type-members (car mc)))
144 (fail nil))
145 (catch 'fail-early
146 (while (and mem expected-members)
147 (when (not (string= (semantic-tag-name (car mem))
148 (car expected-members)))
149 (switch-to-buffer (current-buffer))
150 (setq fail (format "Did not find %s in %s" (car expected-members)
151 (buffer-file-name)))
152 (throw 'fail-early nil))
153 (setq mem (cdr mem)
154 expected-members (cdr expected-members)))
155 (when expected-members
156 (switch-to-buffer (current-buffer))
157 (setq fail (format "Did not find all expected tags in class: %s" (buffer-file-name)))
158 (throw 'fail-early t))
159 (when mem
160 (switch-to-buffer (current-buffer))
161 (setq fail (format "Found extra tags in class: %s" (buffer-file-name)))))
162
163 (when fail (message "%s" (buffer-string)))
164 fail))
165
166(defun srecode-utest-getset-jumptotag (tagname)
167 "Jump to the tag named TAGNAME."
168 (semantic-fetch-tags)
169 (let ((fail nil)
170 (tag (semantic-deep-find-tags-by-name tagname (current-buffer))))
171 (if tag
172 (semantic-go-to-tag (car tag))
173 (setq fail (format "Failed to jump to tag %s" tagname)))
174 fail))
175
176(provide 'cedet/srecode/test-getset)
177;;; srecode/test-getset.el ends here