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"))))
160 (item ((type action-list
))
162 (item ((type segment-list
))
164 ;;List all pointing towards the same deffile
166 (item ((type action-list
))
168 ,(emtg (type action
)(target 1)(qname 'a1
))
169 ,(emtg (type action
)(target 1)(qname 'b
))))
172 (item ((type segment-list
))
174 ,(emtg (type action
)(target 1)(qname 'a1
))
175 ,(emtg (type action
)(target 1)(qname 'b
))))))
177 ;;List pointing towards two deffiles
179 (item ((type action-list
))
181 ,(emtg (type action
)(target 1)(qname 'a1
))
182 ,(emtg (type action
)(target 2)(qname 'c
))
183 ,(emtg (type action
)(target 1)(qname 'b
))
184 ,(emtg (type action
)(target 2)(qname 'd
))))
186 (item ((type segment-list
))
188 ,(emtg (type action
)(target 1)(qname 'a1
))
189 ,(emtg (type action
)(target 1)(qname 'b
)))
191 ,(emtg (type action
)(target 2)(qname 'c
))
192 ,(emtg (type action
)(target 2)(qname 'd
))))))
194 ;;List including all types except preload actions
196 (item ((type action-list
))
198 ,(emtg (type action
)(subtype add-to-info-path
)
200 ,(emtg (type action
)(subtype add-to-load-path
)
202 ,(emtg (type action
)(target 1)(qname 'a1
))
203 ,(emtg (type action
)(target 2)(qname 'c
))
204 ,(emtg (type action
)(target 1)(qname 'b
))
205 ,(emtg (type action
)(target 2)(qname 'd
))
206 ,(emtg (type action
)(subtype add-to-info-path
)
208 ,(emtg (type action
)(subtype add-to-load-path
)
212 (item ((type segment-list
))
215 ,(emtg (type action
)(subtype add-to-info-path
)
217 ,(emtg (type action
)(subtype add-to-load-path
)
219 ,(emtg (type action
)(target 1)(qname 'a1
))
220 ,(emtg (type action
)(target 1)(qname 'b
)))
222 ,(emtg (type action
)(target 2)(qname 'c
))
223 ,(emtg (type action
)(target 2)(qname 'd
))
224 ,(emtg (type action
)(subtype add-to-info-path
)
226 ,(emtg (type action
)(subtype add-to-load-path
)
229 ;;List including some preload actions
231 (item ((type action-list
))
233 ,(emtg (type action
)(subtype preload-file
)
235 ,(emtg (type action
)(target 1)(qname 'a1
))
236 ,(emtg (type action
)(target 2)(qname 'c
))
237 ,(emtg (type action
)(subtype preload-file
)
239 ,(emtg (type action
)(target 1)(qname 'b
))
240 ,(emtg (type action
)(target 2)(qname 'd
))
241 ,(emtg (type action
)(subtype preload-file
)
244 (item ((type segment-list
))
247 ,(emtg (type action
)(target 1)(qname 'a1
))
248 ,(emtg (type action
)(target 1)(qname 'b
)))
251 ,(emtg (type action
)(target 2)(qname 'c
))
252 ,(emtg (type action
)(target 2)(qname 'd
)))
254 ,(emtg (type action
)(subtype preload-file
)
256 ,(emtg (type action
)(subtype preload-file
)
258 ,(emtg (type action
)(subtype preload-file
)
261 ;;List includes some null actions
263 (item ((type action-list
))
266 ,(emtg (type action
)(target 1)(qname 'a1
))
268 ,(emtg (type action
)(target 2)(qname 'c
))
270 ,(emtg (type action
)(target 1)(qname 'b
))
271 ,(emtg (type action
)(target 2)(qname 'd
))))
273 (item ((type segment-list
))
275 ,(emtg (type action
)(target 1)(qname 'a1
))
276 ,(emtg (type action
)(target 1)(qname 'b
)))
278 ,(emtg (type action
)(target 2)(qname 'c
))
279 ,(emtg (type action
)(target 2)(qname 'd
)))))))))
281 ;;;_ . elinstall-remove-autogen-action
282 (emt:deftest-3 elinstall-remove-autogen-action
284 (emtg:with elinstall
:td
:examples
()
285 (emt:doc
"Param: List of actions including an
286 add-file-autoloads for a1.")
287 (emt:doc
"Param: filename a1.")
288 (emt:doc
"Response: The a1 action is removed.")
291 (elinstall-remove-autogen-action
294 (emtg (type action
)(target 1)(name 'a
))
295 (add-file-autoloads "deffile-1" "b1")))
296 '((add-file-autoloads "deffile-1" "b1")))
301 ;;;_ . elinstall-segregate-actions
303 (emt:deftest-3 elinstall-segregate-actions
305 (emtg:with elinstall
:td
:examples
()
309 (elinstall-segregate-actions
310 (emtg (type action-list
)))))
315 (emtg (type segment-list
))
319 (equal (car a
)(car b
))
323 ;;;_ . elinstall-get-relevant-load-path
324 (emt:deftest-3 elinstall-get-relevant-load-path
326 (emtg:with elinstall
:td
:examples
()
327 (emt:doc
"Situation: Some actions are add-to-load-path.")
328 (emt:doc
"Response: Return exactly a list of these.")
329 ;;$$WRITE MY EXAMPLES for results comparison.
330 (elinstall-get-relevant-load-path
331 (emtg (type action-list
) (name 3))))))
335 ;;;_ , Given list of actions, doing the right adds to deffile
336 ;;Similar requirements for `elinstall-do-segment'
337 (emt:deftest-3 elinstall-update-deffile
339 ;;Test that when called multiple times, it updates right:
341 ;;Removes gone files.
343 ;;Autoloads with slash-path if asked to (That requires another setup)
344 ;;That will use function 31a1-1 in 31a1.el
345 ;;Check it by autoloading it.
347 ;;load-path is just to "3/"
349 ;;(For add-to-load-path)
350 ;;Doesn't make the same add-to-load-path section twice
353 (emtg:with elinstall
:td
:examples
355 ((elinsert:th
:found
'())
357 (expand-file-name "2/" elinstall
:th
:examples
))
358 ;;Because the load will sometimes set it.
359 (load-path (list dir
)))
362 (emtb:with-file-f
(:absent
:visited-name
'tmp
) x
363 (emt:doc
"Case: Only one autoload")
364 (emt:doc
"Situation: elinsert:th:found is an empty list
365 and all the autoloads in question push symbols to it.")
366 (emt:doc
"Operation: update the def file")
367 (elinstall-update-deffile x
369 ,(emtg (type action
)(target 1)(qname 'a1
)))
371 (emt:doc
"Operation: load the def file")
373 (emt:doc
"Response: It has done what was expected")
375 (equal elinsert
:th
:found
'(a1))))))))
376 ;;;_ , elinstall-remove-autogen-action
377 ;;Test that it removes on the same sort of filename that
378 ;;elinstall-generate-file-autoloads hands to it.
379 ;;elinstall-get-autogen-action, same requirement.
380 ;;;_ , elinstall-symlink-on-emacs-start
382 (emt:deftest-3 elinstall-symlink-on-emacs-start
384 (emtg:with elinstall
:td
:examples
()
385 (emtmd:with-dirtree
(:repr
'())
386 (emt:doc
"Situation: Directory exists and is empty.")
387 (emt:doc
"Operation: Symlink into it.")
388 (emt:doc
"PARAM: force flag not passed.")
390 (elinstall-symlink-on-emacs-start
391 (emtg (type filename
)(qname 'a1
)) "apreload"
392 default-directory
50)
396 (emtmd:get-repr-contents
".")))
399 "Response: Now contains a symlink of the expected name.")
400 ;;$$IMPROVE MY SUPPORT dirtree doesn't yet allow
401 ;;testing for type = symlink
403 (emtmd:repr-contents-equal
405 (emtmd:make-repr-contents
406 (emtmd:make-repr-file
"50apreload.el")))
409 ;;;_ , elinstall-arrange-preload
411 (emt:deftest-3 elinstall-arrange-preload
413 (emtg:with elinstall
:td
:examples
()
414 (emtmd:with-dirtree
(:repr
'())
415 (emt:doc
"Situation: Directory exists and is empty.")
416 (emt:doc
"Operation: Symlink into it.")
417 (emt:doc
"PARAM: force flag not passed.")
420 ((elinstall-default-preload-target default-directory
))
421 (elinstall-arrange-preload
422 (emtg (type filename
)(qname 'a1
))
429 (emtmd:get-repr-contents
".")))
432 "Response: Now contains a symlink of the expected name.")
433 ;;$$IMPROVE MY SUPPORT dirtree doesn't yet allow
434 ;;testing for type = symlink
436 (emtmd:repr-contents-equal
438 (emtmd:make-repr-contents
439 (emtmd:make-repr-file
"50apreload.el")))
445 (provide 'elinstall
/tests
)
447 ;;;_ * Local emacs vars.
448 ;;;_ + Local variables:
453 ;;; elinstall/tests.el ends here