1 ;;;_ elinstall/tests.el --- Tests for elinstall
5 ;; Copyright (C) 2010 Tom Breton (Tehom)
7 ;; Author: Tom Breton (Tehom) <tehom@panix.com>
8 ;; Keywords: lisp, maint, internal
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
33 (require 'emtest
/runner
/define
)
34 (require 'emtest
/testhelp
/standard
)
35 (require 'emtest
/testhelp
/misc
)
36 (require 'emtest
/testhelp
/tagnames
)
37 (require 'emtest
/testhelp
/testpoint
)
38 (require 'emtest
/testhelp
/mocks
/filebuf
)
41 (require 'emtest
/testhelp
/testpoint
/requirer
))
44 (require 'cus-edit
) ;;Because we save "installedness" manually
49 (defconst elinstall
:th
:examples
50 (emtb:expand-filename-by-load-file
"examples")
51 "Directory of example files" )
54 ;;;_ . elinstall:th:surrounders
55 (defconst elinstall
:th
:surrounders
56 ;;Mock customize-save-variable to do nothing.
57 ;;Also mock interaction: yes-or-no-p. This suggests that I should
58 ;;articulate the package more, to separate interaction.
59 '((emtp:insulate
(customize-save-variable)))
60 "The normal surrounders for elinstall tests" )
64 ((of 'elinstall-already-installed
)
65 (:surrounders elinstall
:th
:surrounders
))
69 ((elinstall-already-installed nil
))
70 (emt:doc
"Situation: Nothing has been installed.")
71 (emt:doc
"Operation: Query whether EXAMPLE has been installed.")
72 (emt:doc
"Response: give nil.")
75 (elinstall-already-installed "example")))
77 (emt:doc
"Operation: Record that EXAMPLE has been installed.")
79 (elinstall-record-installed "example")
80 (emt:doc
"Operation: Query whether EXAMPLE has been installed.")
81 (emt:doc
"Response: give true.")
83 (elinstall-already-installed "example")))))
85 ;;;_ , Generating the right actions
86 (emt:deftest-3 elinstall-find-actions-by-spec
87 ;;At least one for each command.
89 ;;Also test recursing in directories
92 (emt:doc
"Situation: On examples/1 directory.")
93 (emt:doc
"Response: WRITEME."))))
96 ;;;_ , Given list of actions, segregate it right.
98 (defconst elinstall
:td
:examples
100 ((dir (expand-file-name "2/" elinstall
:th
:examples
)))
103 (transparent-tags () (type name
))
105 ;;The actions themselves:
106 (group ((type action
))
107 (group ((subtype add-file-autoloads
))
110 `(add-file-autoloads "deffile-1"
113 ,(expand-file-name "a1.el" dir
)))
116 `(add-file-autoloads "deffile-1" "b1" ,dir
117 ,(expand-file-name "b1.el" dir
))))
120 `(add-file-autoloads "deffile-2"
123 ,(expand-file-name "c2.el" dir
)))
126 `(add-file-autoloads "deffile-2" "d2" ,dir
127 ,(expand-file-name "d2.el" dir
)))))
128 (group ((subtype add-to-load-path
))
129 (item ((target 1)(qname 'alp1
))
130 `(add-to-load-path "deffile-1" ,dir
))
131 (item ((target 2)(qname 'alp2
))
132 `(add-to-load-path "deffile-2" ,dir
)))
134 (group ((subtype add-to-info-path
))
135 (item ((target 1)(qname 'aip1
))
136 `(add-to-info-path "deffile-1" ,dir
))
137 (item ((target 2)(qname 'aip2
))
138 `(add-to-info-path "deffile-2" ,dir
)))
140 (group ((subtype preload-file
))
141 (item ((target 1)(qname 'plf1
))
142 `(preload-file "deffile-1" 50))
143 (item ((target 2)(qname 'plf2
))
144 `(preload-file "deffile-2"))
145 (item ((target 3)(qname 'plf3
))
146 `(preload-file "deffile-3"))))
150 (item ((type action-list
))
152 (item ((type segment-list
))
154 ;;List all pointing towards the same deffile
156 (item ((type action-list
))
158 ,(emtg (type action
)(target 1)(qname 'a1
))
159 ,(emtg (type action
)(target 1)(qname 'b
))))
162 (item ((type segment-list
))
164 ,(emtg (type action
)(target 1)(qname 'a1
))
165 ,(emtg (type action
)(target 1)(qname 'b
))))))
167 ;;List pointing towards two deffiles
169 (item ((type action-list
))
171 ,(emtg (type action
)(target 1)(qname 'a1
))
172 ,(emtg (type action
)(target 2)(qname 'c
))
173 ,(emtg (type action
)(target 1)(qname 'b
))
174 ,(emtg (type action
)(target 2)(qname 'd
))))
176 (item ((type segment-list
))
178 ,(emtg (type action
)(target 1)(qname 'a1
))
179 ,(emtg (type action
)(target 1)(qname 'b
)))
181 ,(emtg (type action
)(target 2)(qname 'c
))
182 ,(emtg (type action
)(target 2)(qname 'd
))))))
184 ;;List including all types except preload actions
186 (item ((type action-list
))
188 ,(emtg (type action
)(subtype add-to-info-path
)
190 ,(emtg (type action
)(subtype add-to-load-path
)
192 ,(emtg (type action
)(target 1)(qname 'a1
))
193 ,(emtg (type action
)(target 2)(qname 'c
))
194 ,(emtg (type action
)(target 1)(qname 'b
))
195 ,(emtg (type action
)(target 2)(qname 'd
))
196 ,(emtg (type action
)(subtype add-to-info-path
)
198 ,(emtg (type action
)(subtype add-to-load-path
)
202 (item ((type segment-list
))
205 ,(emtg (type action
)(subtype add-to-info-path
)
207 ,(emtg (type action
)(subtype add-to-load-path
)
209 ,(emtg (type action
)(target 1)(qname 'a1
))
210 ,(emtg (type action
)(target 1)(qname 'b
)))
212 ,(emtg (type action
)(target 2)(qname 'c
))
213 ,(emtg (type action
)(target 2)(qname 'd
))
214 ,(emtg (type action
)(subtype add-to-info-path
)
216 ,(emtg (type action
)(subtype add-to-load-path
)
219 ;;List including some preload actions
221 (item ((type action-list
))
223 ,(emtg (type action
)(subtype preload-file
)
225 ,(emtg (type action
)(target 1)(qname 'a1
))
226 ,(emtg (type action
)(target 2)(qname 'c
))
227 ,(emtg (type action
)(subtype preload-file
)
229 ,(emtg (type action
)(target 1)(qname 'b
))
230 ,(emtg (type action
)(target 2)(qname 'd
))
231 ,(emtg (type action
)(subtype preload-file
)
234 (item ((type segment-list
))
237 ,(emtg (type action
)(subtype preload-file
)
239 ,(emtg (type action
)(subtype preload-file
)
241 ,(emtg (type action
)(subtype preload-file
)
245 ,(emtg (type action
)(target 1)(qname 'a1
))
246 ,(emtg (type action
)(target 1)(qname 'b
)))
249 ,(emtg (type action
)(target 2)(qname 'c
))
250 ,(emtg (type action
)(target 2)(qname 'd
))))))
252 ;;List includes some null actions
254 (item ((type action-list
))
257 ,(emtg (type action
)(target 1)(qname 'a1
))
259 ,(emtg (type action
)(target 2)(qname 'c
))
261 ,(emtg (type action
)(target 1)(qname 'b
))
262 ,(emtg (type action
)(target 2)(qname 'd
))))
264 (item ((type segment-list
))
266 ,(emtg (type action
)(target 1)(qname 'a1
))
267 ,(emtg (type action
)(target 1)(qname 'b
)))
269 ,(emtg (type action
)(target 2)(qname 'c
))
270 ,(emtg (type action
)(target 2)(qname 'd
)))))))))
272 ;;;_ . elinstall-remove-autogen-action
273 (emt:deftest-3 elinstall-remove-autogen-action
275 (emtg:with elinstall
:td
:examples
()
276 (emt:doc
"Param: List of actions including an
277 add-file-autoloads for a1.")
278 (emt:doc
"Param: filename a1.")
279 (emt:doc
"Response: The a1 action is removed.")
282 (elinstall-remove-autogen-action
285 (emtg (type action
)(target 1)(name 'a
))
286 (add-file-autoloads "deffile-1" "b1")))
287 '((add-file-autoloads "deffile-1" "b1")))
292 ;;;_ . elinstall-segregate-actions
294 (emt:deftest-3 elinstall-segregate-actions
296 (emtg:with elinstall
:td
:examples
()
300 (elinstall-segregate-actions
301 (emtg (type action-list
)))))
306 (emtg (type segment-list
))
310 (equal (car a
)(car b
))
315 ;;;_ , Given list of actions, doing the right adds to deffile
316 ;;Similar requirements for `elinstall-do-segment'
317 (emt:deftest-3 elinstall-update-deffile
318 ;;Test that when called multiple times, it updates right:
319 ;;Removes gone files.
320 ;;Autoloads with slash-path if asked to (That requires another setup)
321 ;;That will use function 31a1-1 in 31a1.el
322 ;;Check it by autoloading it.
324 ;;load-path is just to "3/"
325 ;;(For add-to-load-path)
326 ;;Doesn't make the same add-to-load-path section twice
329 (emtg:with elinstall
:td
:examples
331 ((elinsert:th
:found
'())
333 (expand-file-name "2/" elinstall
:th
:examples
))
334 ;;Because the load will sometimes set it.
335 (load-path (list dir
)))
338 (emtb:with-file-f
(:absent
:visited-name
'tmp
) x
339 (emt:doc
"Case: Only one autoload")
340 (emt:doc
"Situation: elinsert:th:found is an empty list
341 and all the autoloads in question push symbols to it.")
342 (emt:doc
"Operation: update the def file")
343 (elinstall-update-deffile x
345 ,(emtg (type action
)(target 1)(qname 'a1
)))
347 (emt:doc
"Operation: load the def file")
349 (emt:doc
"Response: It has done what was expected")
351 (equal elinsert
:th
:found
'(a1))))))))
352 ;;;_ , elinstall-remove-autogen-action
353 ;;Test that it removes on the same sort of filename that
354 ;;elinstall-generate-file-autoloads hands to it.
355 ;;elinstall-get-autogen-action, same requirement.
360 (provide 'elinstall
/tests
)
362 ;;;_ * Local emacs vars.
363 ;;;_ + Local variables:
368 ;;; elinstall/tests.el ends here