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 (group ((type filename
))
108 ;;But it might not be made in this directory, but
109 ;;rather in a tmp directory.
113 (expand-file-name "a1.el" dir
)))
115 ;;The actions themselves:
116 (group ((type action
))
117 (group ((subtype add-file-autoloads
))
120 `(add-file-autoloads "deffile-1"
123 ,(expand-file-name "a1.el" dir
)))
126 `(add-file-autoloads "deffile-1" "b1" ,dir
127 ,(expand-file-name "b1.el" dir
))))
130 `(add-file-autoloads "deffile-2"
133 ,(expand-file-name "c2.el" dir
)))
136 `(add-file-autoloads "deffile-2" "d2" ,dir
137 ,(expand-file-name "d2.el" dir
)))))
138 (group ((subtype add-to-load-path
))
139 (item ((target 1)(qname 'alp1
))
140 `(add-to-load-path "deffile-1" ,dir
))
141 (item ((target 2)(qname 'alp2
))
142 `(add-to-load-path "deffile-2" ,dir
)))
144 (group ((subtype add-to-info-path
))
145 (item ((target 1)(qname 'aip1
))
146 `(add-to-info-path "deffile-1" ,dir
))
147 (item ((target 2)(qname 'aip2
))
148 `(add-to-info-path "deffile-2" ,dir
)))
150 (group ((subtype preload-file
))
151 (item ((target 1)(qname 'plf1
))
152 `(preload-file "deffile-1" 50))
153 (item ((target 2)(qname 'plf2
))
154 `(preload-file "deffile-2"))
155 (item ((target 3)(qname 'plf3
))
156 `(preload-file "deffile-3"))))
158 ;;$$OBSOLETE. All segments are now under stuff.
161 (item ((type action-list
))
163 (item ((type segment-list
))
165 ;;List all pointing towards the same deffile
167 (item ((type action-list
))
169 ,(emtg (type action
)(target 1)(qname 'a1
))
170 ,(emtg (type action
)(target 1)(qname 'b
))))
173 (item ((type segment-list
))
175 ,(emtg (type action
)(target 1)(qname 'a1
))
176 ,(emtg (type action
)(target 1)(qname 'b
))))))
178 ;;List pointing towards two deffiles
180 (item ((type action-list
))
182 ,(emtg (type action
)(target 1)(qname 'a1
))
183 ,(emtg (type action
)(target 2)(qname 'c
))
184 ,(emtg (type action
)(target 1)(qname 'b
))
185 ,(emtg (type action
)(target 2)(qname 'd
))))
187 (item ((type segment-list
))
189 ,(emtg (type action
)(target 1)(qname 'a1
))
190 ,(emtg (type action
)(target 1)(qname 'b
)))
192 ,(emtg (type action
)(target 2)(qname 'c
))
193 ,(emtg (type action
)(target 2)(qname 'd
))))))
195 ;;List including all types except preload actions
197 (item ((type action-list
))
199 ,(emtg (type action
)(subtype add-to-info-path
)
201 ,(emtg (type action
)(subtype add-to-load-path
)
203 ,(emtg (type action
)(target 1)(qname 'a1
))
204 ,(emtg (type action
)(target 2)(qname 'c
))
205 ,(emtg (type action
)(target 1)(qname 'b
))
206 ,(emtg (type action
)(target 2)(qname 'd
))
207 ,(emtg (type action
)(subtype add-to-info-path
)
209 ,(emtg (type action
)(subtype add-to-load-path
)
213 (item ((type segment-list
))
216 ,(emtg (type action
)(subtype add-to-info-path
)
218 ,(emtg (type action
)(subtype add-to-load-path
)
220 ,(emtg (type action
)(target 1)(qname 'a1
))
221 ,(emtg (type action
)(target 1)(qname 'b
)))
223 ,(emtg (type action
)(target 2)(qname 'c
))
224 ,(emtg (type action
)(target 2)(qname 'd
))
225 ,(emtg (type action
)(subtype add-to-info-path
)
227 ,(emtg (type action
)(subtype add-to-load-path
)
230 ;;List including some preload actions
232 (item ((type action-list
))
234 ,(emtg (type action
)(subtype preload-file
)
236 ,(emtg (type action
)(target 1)(qname 'a1
))
237 ,(emtg (type action
)(target 2)(qname 'c
))
238 ,(emtg (type action
)(subtype preload-file
)
240 ,(emtg (type action
)(target 1)(qname 'b
))
241 ,(emtg (type action
)(target 2)(qname 'd
))
242 ,(emtg (type action
)(subtype preload-file
)
245 (item ((type segment-list
))
248 ,(emtg (type action
)(target 1)(qname 'a1
))
249 ,(emtg (type action
)(target 1)(qname 'b
)))
252 ,(emtg (type action
)(target 2)(qname 'c
))
253 ,(emtg (type action
)(target 2)(qname 'd
)))
255 ,(emtg (type action
)(subtype preload-file
)
257 ,(emtg (type action
)(subtype preload-file
)
259 ,(emtg (type action
)(subtype preload-file
)
262 ;;List includes some null actions
264 (item ((type action-list
))
267 ,(emtg (type action
)(target 1)(qname 'a1
))
269 ,(emtg (type action
)(target 2)(qname 'c
))
271 ,(emtg (type action
)(target 1)(qname 'b
))
272 ,(emtg (type action
)(target 2)(qname 'd
))))
274 (item ((type segment-list
))
276 ,(emtg (type action
)(target 1)(qname 'a1
))
277 ,(emtg (type action
)(target 1)(qname 'b
)))
279 ,(emtg (type action
)(target 2)(qname 'c
))
280 ,(emtg (type action
)(target 2)(qname 'd
)))))))))
282 ;;;_ . elinstall-remove-autogen-action
283 (emt:deftest-3 elinstall-remove-autogen-action
285 (emtg:with elinstall
:td
:examples
()
286 (emt:doc
"Param: List of actions including an
287 add-file-autoloads for a1.")
288 (emt:doc
"Param: filename a1.")
289 (emt:doc
"Response: The a1 action is removed.")
292 (elinstall-remove-autogen-action
295 (emtg (type action
)(target 1)(name 'a
))
296 (add-file-autoloads "deffile-1" "b1")))
297 '((add-file-autoloads "deffile-1" "b1")))
302 ;;;_ . elinstall-segregate-actions
304 (emt:deftest-3 elinstall-segregate-actions
306 (emtg:with elinstall
:td
:examples
()
310 (elinstall-segregate-actions
311 (emtg (type action-list
)))))
316 (emtg (type segment-list
))
320 (equal (car a
)(car b
))
324 ;;;_ . elinstall-get-relevant-load-path
325 (emt:deftest-3 elinstall-get-relevant-load-path
327 (emtg:with elinstall
:td
:examples
()
328 (emt:doc
"Situation: Some actions are add-to-load-path.")
329 (emt:doc
"Response: Return exactly a list of these.")
330 ;;$$WRITE MY EXAMPLES for results comparison.
331 (elinstall-get-relevant-load-path
332 (emtg (type action-list
) (name 3))))))
336 ;;;_ , Given list of actions, doing the right adds to deffile
337 ;;Similar requirements for `elinstall-do-segment'
338 (emt:deftest-3 elinstall-update-deffile
340 ;;Test that when called multiple times, it updates right:
342 ;;Removes gone files.
344 ;;Autoloads with slash-path if asked to (That requires another setup)
345 ;;That will use function 31a1-1 in 31a1.el
346 ;;Check it by autoloading it.
348 ;;load-path is just to "3/"
350 ;;(For add-to-load-path)
351 ;;Doesn't make the same add-to-load-path section twice
354 (emtg:with elinstall
:td
:examples
356 ((elinsert:th
:found
'())
358 (expand-file-name "2/" elinstall
:th
:examples
))
359 ;;Because the load will sometimes set it.
360 (load-path (list dir
)))
363 (emtb:with-file-f
(:absent
:visited-name
'tmp
) x
364 (emt:doc
"Case: Only one autoload")
365 (emt:doc
"Situation: elinsert:th:found is an empty list
366 and all the autoloads in question push symbols to it.")
367 (emt:doc
"Operation: update the def file")
368 (elinstall-update-deffile x
370 ,(emtg (type action
)(target 1)(qname 'a1
)))
372 (emt:doc
"Operation: load the def file")
374 (emt:doc
"Response: It has done what was expected")
376 (equal elinsert
:th
:found
'(a1))))))))
377 ;;;_ , elinstall-remove-autogen-action
378 ;;Test that it removes on the same sort of filename that
379 ;;elinstall-generate-file-autoloads hands to it.
380 ;;elinstall-get-autogen-action, same requirement.
381 ;;;_ , elinstall-symlink-on-emacs-start
383 (emt:deftest-3 elinstall-symlink-on-emacs-start
385 (emtg:with elinstall
:td
:examples
()
386 (emtmd:with-dirtree
(:repr
'())
387 (emt:doc
"Situation: Directory exists and is empty.")
388 (emt:doc
"Operation: Symlink into it.")
389 (emt:doc
"PARAM: force flag not passed.")
391 (elinstall-symlink-on-emacs-start
392 (emtg (type filename
)(qname 'a1
)) "apreload"
393 default-directory
50)
397 (emtmd:get-repr-contents
".")))
400 "Response: Now contains a symlink of the expected name.")
401 ;;$$IMPROVE MY SUPPORT dirtree doesn't yet allow
402 ;;testing for type = symlink
404 (emtmd:repr-contents-equal
406 (emtmd:make-repr-contents
407 (emtmd:make-repr-file
"50apreload.el")))
410 ;;;_ , elinstall-arrange-preload
412 (emt:deftest-3 elinstall-arrange-preload
414 (emtg:with elinstall
:td
:examples
()
415 (emtmd:with-dirtree
(:repr
'())
416 (emt:doc
"Situation: Directory exists and is empty.")
417 (emt:doc
"Operation: Symlink into it.")
418 (emt:doc
"PARAM: force flag not passed.")
421 ((elinstall-default-preload-target default-directory
))
422 (elinstall-arrange-preload
424 (emtg (type filename
)(qname 'a1
))
430 (emtmd:get-repr-contents
".")))
433 "Response: Now contains a symlink of the expected name.")
434 ;;$$IMPROVE MY SUPPORT dirtree doesn't yet allow
435 ;;testing for type = symlink
437 (emtmd:repr-contents-equal
439 (emtmd:make-repr-contents
440 (emtmd:make-repr-file
"50apreload.el")))
446 (provide 'elinstall
/tests
)
448 ;;;_ * Local emacs vars.
449 ;;;_ + Local variables:
454 ;;; elinstall/tests.el ends here