1 ;;; vc-tests.el --- Tests of different backends of vc.el
3 ;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
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.
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.
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/'.
22 ;; For every supported VC on the machine, different test cases are
23 ;; generated automatically.
25 ;; Functions to be tested (see Commentary of vc.el). Mandatory
26 ;; functions are marked with `*', optional functions are marked with `-':
30 ;; * revision-granularity DONE
32 ;; STATE-QUERYING FUNCTIONS
34 ;; * registered (file) DONE
35 ;; * state (file) DONE
36 ;; - dir-status (dir update-function)
37 ;; - dir-status-files (dir files default-state update-function)
38 ;; - dir-extra-headers (dir)
39 ;; - dir-printer (fileinfo)
40 ;; - status-fileinfo-extra (file)
41 ;; * working-revision (file) DONE
42 ;; - latest-on-branch-p (file)
43 ;; * checkout-model (files) DONE
44 ;; - mode-line-string (file)
46 ;; STATE-CHANGING FUNCTIONS
48 ;; * create-repo (backend) DONE
49 ;; * register (files &optional comment) DONE
50 ;; - responsible-p (file)
51 ;; - receive-file (file rev)
52 ;; - unregister (file) DONE
53 ;; * checkin (files comment)
54 ;; * find-revision (file rev buffer)
55 ;; * checkout (file &optional rev)
56 ;; * revert (file &optional contents-done)
58 ;; - merge-file (file rev1 rev2)
60 ;; - merge-news (file)
62 ;; - steal-lock (file &optional revision)
63 ;; - modify-change-comment (files rev comment)
64 ;; - mark-resolved (files)
65 ;; - find-admin-dir (file)
69 ;; * print-log (files buffer &optional shortlog start-revision limit)
70 ;; * log-outgoing (backend remote-location)
71 ;; * log-incoming (backend remote-location)
73 ;; - show-log-entry (revision)
74 ;; - comment-history (file)
75 ;; - update-changelog (files)
76 ;; * diff (files &optional async rev1 rev2 buffer)
77 ;; - revision-completion-table (files)
78 ;; - annotate-command (file buf &optional rev)
80 ;; - annotate-current-time ()
81 ;; - annotate-extract-revision-at-line ()
82 ;; - region-history (FILE BUFFER LFROM LTO)
83 ;; - region-history-mode ()
87 ;; - create-tag (dir name branchp)
88 ;; - retrieve-tag (dir name update)
92 ;; - make-version-backups-p (file)
94 ;; - ignore (file &optional directory)
95 ;; - ignore-completion-table
96 ;; - previous-revision (file rev)
97 ;; - next-revision (file rev)
100 ;; - delete-file (file)
101 ;; - rename-file (old new)
102 ;; - find-file-hook ()
104 ;; - extra-dir-menu ()
105 ;; - conflicted-files (dir)
112 ;; The working horses.
114 (defvar vc-test--cleanup-hook nil
115 "Functions for cleanup at the end of an ert test.
116 Don't set it globally, the functions shall be let-bound.")
118 (defun vc-test--revision-granularity-function (backend)
119 "Run the `vc-revision-granularity' backend function."
120 (funcall (intern (downcase (format "vc-%s-revision-granularity" backend)))))
122 (defun vc-test--create-repo-function (backend)
123 "Run the `vc-create-repo' backend function.
124 For backends which dont support it, it is emulated."
130 (make-temp-name "vc-test") temporary-file-directory)))
131 (make-directory (expand-file-name "module" tmp-dir) 'parents)
132 (make-directory (expand-file-name "CVSROOT" tmp-dir) 'parents)
133 (if (not (fboundp 'w32-application-type))
134 (shell-command-to-string (format "cvs -Q -d:local:%s co module"
136 (let ((cvs-prog (executable-find "cvs"))
138 ;; If CVS executable is an MSYS program, reformat the file
139 ;; name of TMP-DIR to have the /d/foo/bar form supported by
140 ;; MSYS programs. (FIXME: What about Cygwin cvs.exe?)
141 (if (eq (w32-application-type cvs-prog) 'msys)
143 (concat "/" (substring tmp-dir 0 1) (substring tmp-dir 2))))
144 (shell-command-to-string (format "cvs -Q -d:local:%s co module"
146 (rename-file "module/CVS" default-directory)
147 (delete-directory "module" 'recursive)
148 ;; We must cleanup the "remote" CVS repo as well.
149 (add-hook 'vc-test--cleanup-hook
150 `(lambda () (delete-directory ,tmp-dir 'recursive)))))
153 (let ((archive-name (format "%s--%s" user-mail-address (random))))
155 "no arch user id set" (shell-command-to-string "tla my-id"))
156 (shell-command-to-string
157 (format "tla my-id \"<%s>\"" user-mail-address)))
158 (shell-command-to-string
159 (format "tla make-archive %s %s" archive-name default-directory))
160 (shell-command-to-string
161 (format "tla my-default-archive %s" archive-name))))
164 (let ((archive-name "foo.mtn"))
165 (shell-command-to-string
167 "mtn db init --db=%s"
168 (expand-file-name archive-name default-directory)))
169 (shell-command-to-string
170 (format "mtn --db=%s --branch=foo setup ." archive-name))))
172 (t (vc-create-repo backend))))
174 (defun vc-test--create-repo (backend)
175 "Create a test repository in `default-directory', a temporary directory."
177 (let ((vc-handled-backends `(,backend))
179 (file-name-as-directory
181 (make-temp-name "vc-test") temporary-file-directory)))
182 vc-test--cleanup-hook)
188 'vc-test--cleanup-hook
189 `(lambda () (delete-directory ,default-directory 'recursive)))
191 ;; Check the revision granularity.
192 (should (memq (vc-test--revision-granularity-function backend)
195 ;; Create empty repository.
196 (make-directory default-directory)
197 (should (file-directory-p default-directory))
198 (vc-test--create-repo-function backend)
199 (should (eq (vc-responsible-backend default-directory) backend)))
202 (ignore-errors (run-hooks 'vc-test--cleanup-hook)))))
204 ;; Why isn't there `vc-unregister'?
205 (defun vc-test--unregister-function (backend file)
206 "Run the `vc-unregister' backend function.
207 For backends which dont support it, `vc-not-supported' is signalled."
209 (let ((symbol (intern (downcase (format "vc-%s-unregister" backend)))))
210 (if (functionp symbol)
211 (funcall symbol file)
212 ;; CVS, SVN, SCCS, SRC and Mtn are not supported.
213 (signal 'vc-not-supported (list 'unregister backend)))))
215 (defun vc-test--register (backend)
216 "Register and unregister a file."
218 (let ((vc-handled-backends `(,backend))
220 (file-name-as-directory
222 (make-temp-name "vc-test") temporary-file-directory)))
223 vc-test--cleanup-hook)
229 'vc-test--cleanup-hook
230 `(lambda () (delete-directory ,default-directory 'recursive)))
232 ;; Create empty repository.
233 (make-directory default-directory)
234 (vc-test--create-repo-function backend)
236 (let ((tmp-name1 (expand-file-name "foo" default-directory))
238 ;; Register files. Check for it.
239 (write-region "foo" nil tmp-name1 nil 'nomessage)
240 (should (file-exists-p tmp-name1))
241 (should-not (vc-registered tmp-name1))
242 (write-region "bla" nil tmp-name2 nil 'nomessage)
243 (should (file-exists-p tmp-name2))
244 (should-not (vc-registered tmp-name2))
245 (vc-register (list backend (list tmp-name1 tmp-name2)))
246 (should (file-exists-p tmp-name1))
247 (should (vc-registered tmp-name1))
248 (should (file-exists-p tmp-name2))
249 (should (vc-registered tmp-name2))
251 ;; Unregister the files.
254 (vc-test--unregister-function backend tmp-name1)
255 (should-not (vc-registered tmp-name1))
256 (vc-test--unregister-function backend tmp-name2)
257 (should-not (vc-registered tmp-name2)))
258 ;; CVS, SVN, SCCS, SRC and Mtn are not supported.
259 (vc-not-supported t))
260 ;; The files shall still exist.
261 (should (file-exists-p tmp-name1))
262 (should (file-exists-p tmp-name2))))
265 (ignore-errors (run-hooks 'vc-test--cleanup-hook)))))
267 (defun vc-test--state (backend)
268 "Check the different states of a file."
270 (let ((vc-handled-backends `(,backend))
272 (file-name-as-directory
274 (make-temp-name "vc-test") temporary-file-directory)))
275 vc-test--cleanup-hook)
281 'vc-test--cleanup-hook
282 `(lambda () (delete-directory ,default-directory 'recursive)))
284 ;; Create empty repository. Check repository state.
285 (make-directory default-directory)
286 (vc-test--create-repo-function backend)
290 ;; unregistered: CVS SCCS SRC
291 ;; up-to-date: Bzr SVN
292 (message "vc-state1 %s" (vc-state default-directory))
293 (should (eq (vc-state default-directory)
294 (vc-state default-directory backend)))
295 (should (memq (vc-state default-directory)
296 '(nil added unregistered up-to-date)))
298 (let ((tmp-name (expand-file-name "foo" default-directory)))
299 ;; Check state of an empty file.
301 ;; nil: Hg Mtn SRC SVN
303 ;; unregistered: RCS SCCS
304 ;; up-to-date: Bzr CVS
305 (message "vc-state2 %s" (vc-state tmp-name))
306 (should (eq (vc-state tmp-name) (vc-state tmp-name backend)))
307 (should (memq (vc-state tmp-name)
308 '(nil added unregistered up-to-date)))
310 ;; Write a new file. Check state.
311 (write-region "foo" nil tmp-name nil 'nomessage)
315 ;; unregistered: Hg RCS SCCS SRC SVN
316 ;; up-to-date: Bzr CVS
317 (message "vc-state3 %s" (vc-state tmp-name))
318 (should (eq (vc-state tmp-name) (vc-state tmp-name backend)))
319 (should (memq (vc-state tmp-name)
320 '(nil added unregistered up-to-date)))
322 ;; Register a file. Check state.
324 (list backend (list (file-name-nondirectory tmp-name))))
327 ;; unregistered: Hg RCS SCCS SRC SVN
328 ;; up-to-date: Bzr CVS
329 (message "vc-state4 %s" (vc-state tmp-name))
330 (should (eq (vc-state tmp-name) (vc-state tmp-name backend)))
331 (should (memq (vc-state tmp-name) '(added unregistered up-to-date)))
333 ;; Unregister the file. Check state.
336 (vc-test--unregister-function backend tmp-name)
339 ;; unregistered: Hg RCS
340 ;; unsupported: CVS Mtn SCCS SRC SVN
342 (message "vc-state5 %s" (vc-state tmp-name))
343 (should (eq (vc-state tmp-name) (vc-state tmp-name backend)))
344 (should (memq (vc-state tmp-name)
345 '(added unregistered up-to-date))))
346 (vc-not-supported (message "vc-state5 unsupported")))))
349 (ignore-errors (run-hooks 'vc-test--cleanup-hook)))))
351 (defun vc-test--working-revision (backend)
352 "Check the working revision of a repository."
354 (let ((vc-handled-backends `(,backend))
356 (file-name-as-directory
358 (make-temp-name "vc-test") temporary-file-directory)))
359 vc-test--cleanup-hook)
365 'vc-test--cleanup-hook
366 `(lambda () (delete-directory ,default-directory 'recursive)))
368 ;; Create empty repository. Check working revision of
369 ;; repository, should be nil.
370 (make-directory default-directory)
371 (vc-test--create-repo-function backend)
373 ;; nil: CVS Git Mtn RCS SCCS
374 ;; "0": Bzr Hg SRC SVN
376 "vc-working-revision1 %s" (vc-working-revision default-directory))
377 (should (eq (vc-working-revision default-directory)
378 (vc-working-revision default-directory backend)))
379 (should (member (vc-working-revision default-directory) '(nil "0")))
381 (let ((tmp-name (expand-file-name "foo" default-directory)))
382 ;; Check initial working revision, should be nil until
385 ;; nil: CVS Git Mtn RCS SCCS SVN
387 (message "vc-working-revision2 %s" (vc-working-revision tmp-name))
388 (should (eq (vc-working-revision tmp-name)
389 (vc-working-revision tmp-name backend)))
390 (should (member (vc-working-revision tmp-name) '(nil "0")))
392 ;; Write a new file. Check working revision.
393 (write-region "foo" nil tmp-name nil 'nomessage)
395 ;; nil: CVS Git Mtn RCS SCCS SVN
397 (message "vc-working-revision3 %s" (vc-working-revision tmp-name))
398 (should (eq (vc-working-revision tmp-name)
399 (vc-working-revision tmp-name backend)))
400 (should (member (vc-working-revision tmp-name) '(nil "0")))
402 ;; Register a file. Check working revision.
404 (list backend (list (file-name-nondirectory tmp-name))))
406 ;; nil: Mtn Git RCS SCCS
407 ;; "0": Bzr CVS Hg SRC SVN
408 (message "vc-working-revision4 %s" (vc-working-revision tmp-name))
409 (should (eq (vc-working-revision tmp-name)
410 (vc-working-revision tmp-name backend)))
411 (should (member (vc-working-revision tmp-name) '(nil "0")))
413 ;; Unregister the file. Check working revision.
416 (vc-test--unregister-function backend tmp-name)
420 ;; unsupported: CVS Mtn SCCS SRC SVN
422 "vc-working-revision5 %s" (vc-working-revision tmp-name))
423 (should (eq (vc-working-revision tmp-name)
424 (vc-working-revision tmp-name backend)))
425 (should (member (vc-working-revision tmp-name) '(nil "0"))))
426 (vc-not-supported (message "vc-working-revision5 unsupported")))))
429 (ignore-errors (run-hooks 'vc-test--cleanup-hook)))))
431 (defun vc-test--checkout-model (backend)
432 "Check the checkout model of a repository."
434 (let ((vc-handled-backends `(,backend))
436 (file-name-as-directory
438 (make-temp-name "vc-test") temporary-file-directory)))
439 vc-test--cleanup-hook)
445 'vc-test--cleanup-hook
446 `(lambda () (delete-directory ,default-directory 'recursive)))
448 ;; Create empty repository. Check repository checkout model.
449 (make-directory default-directory)
450 (vc-test--create-repo-function backend)
452 ;; Surprisingly, none of the backends returns 'announce.
454 ;; implicit: Bzr CVS Git Hg Mtn SRC SVN
457 "vc-checkout-model1 %s"
458 (vc-checkout-model backend default-directory))
459 (should (memq (vc-checkout-model backend default-directory)
460 '(announce implicit locking)))
462 (let ((tmp-name (expand-file-name "foo" default-directory)))
463 ;; Check checkout model of an empty file.
466 ;; implicit: Bzr CVS Git Hg Mtn SRC SVN
469 "vc-checkout-model2 %s" (vc-checkout-model backend tmp-name))
470 (should (memq (vc-checkout-model backend tmp-name)
471 '(announce implicit locking)))
473 ;; Write a new file. Check checkout model.
474 (write-region "foo" nil tmp-name nil 'nomessage)
477 ;; implicit: Bzr CVS Git Hg Mtn SRC SVN
480 "vc-checkout-model3 %s" (vc-checkout-model backend tmp-name))
481 (should (memq (vc-checkout-model backend tmp-name)
482 '(announce implicit locking)))
484 ;; Register a file. Check checkout model.
486 (list backend (list (file-name-nondirectory tmp-name))))
489 ;; implicit: Bzr CVS Git Hg Mtn SRC SVN
492 "vc-checkout-model4 %s" (vc-checkout-model backend tmp-name))
493 (should (memq (vc-checkout-model backend tmp-name)
494 '(announce implicit locking)))
496 ;; Unregister the file. Check checkout model.
499 (vc-test--unregister-function backend tmp-name)
502 ;; implicit: Bzr Git Hg
503 ;; unsupported: CVS Mtn SCCS SRC SVN
505 "vc-checkout-model5 %s" (vc-checkout-model backend tmp-name))
506 (should (memq (vc-checkout-model backend tmp-name)
507 '(announce implicit locking))))
508 (vc-not-supported (message "vc-checkout-model5 unsupported")))))
511 (ignore-errors (run-hooks 'vc-test--cleanup-hook)))))
513 ;; Create the test cases.
515 (defun vc-test--rcs-enabled ()
516 (executable-find "rcs"))
518 (defun vc-test--cvs-enabled ()
519 (executable-find "cvs"))
521 (defvar vc-svn-program)
522 (defun vc-test--svn-enabled ()
523 (executable-find vc-svn-program))
525 (defun vc-test--sccs-enabled ()
526 (executable-find "sccs"))
528 (defvar vc-src-program)
529 (defun vc-test--src-enabled ()
530 (executable-find vc-src-program))
532 (defvar vc-bzr-program)
533 (defun vc-test--bzr-enabled ()
534 (executable-find vc-bzr-program))
536 (defvar vc-git-program)
537 (defun vc-test--git-enabled ()
538 (executable-find vc-git-program))
540 (defvar vc-hg-program)
541 (defun vc-test--hg-enabled ()
542 (executable-find vc-hg-program))
544 (defvar vc-mtn-program)
545 (defun vc-test--mtn-enabled ()
546 (executable-find vc-mtn-program))
549 (defvar vc-arch-program)
550 (defun vc-test--arch-enabled ()
551 (executable-find vc-arch-program))
553 ;; Create the test cases.
554 (dolist (backend vc-handled-backends)
555 (let ((backend-string (downcase (symbol-name backend))))
556 (require (intern (format "vc-%s" backend-string)))
558 ;; Check, whether the backend is supported.
559 `(when (funcall ',(intern (format "vc-test--%s-enabled" backend-string)))
562 ,(intern (format "vc-test-%s00-create-repo" backend-string)) ()
563 ,(format "Check `vc-create-repo' for the %s backend."
565 (vc-test--create-repo ',backend))
568 ,(intern (format "vc-test-%s01-register" backend-string)) ()
570 "Check `vc-register' and `vc-registered' for the %s backend."
574 (ert-test-most-recent-result
577 (format "vc-test-%s00-create-repo" backend-string))))))
578 (vc-test--register ',backend))
581 ,(intern (format "vc-test-%s02-state" backend-string)) ()
582 ,(format "Check `vc-state' for the %s backend." backend-string)
585 (ert-test-most-recent-result
588 (format "vc-test-%s01-register" backend-string))))))
589 (vc-test--state ',backend))
592 ,(intern (format "vc-test-%s03-working-revision" backend-string)) ()
593 ,(format "Check `vc-working-revision' for the %s backend."
597 (ert-test-most-recent-result
600 (format "vc-test-%s01-register" backend-string))))))
601 (vc-test--working-revision ',backend))
604 ,(intern (format "vc-test-%s04-checkout-model" backend-string)) ()
605 ,(format "Check `vc-checkout-model' for the %s backend."
607 ;; FIXME make this pass.
608 :expected-result ,(if (equal backend 'RCS) :failed :passed)
611 (ert-test-most-recent-result
614 (format "vc-test-%s01-register" backend-string))))))
615 (vc-test--checkout-model ',backend))))))
618 ;;; vc-tests.el ends here