unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 789fb013803d7c44e1103fc72a72bafb767a552b 9206 bytes (raw)
name: test/automated/files.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
 
;;; files.el --- tests for file handling.

;; Copyright (C) 2012-2015 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)

;; Set to t if the local variable was set, `query' if the query was
;; triggered.
(defvar files-test-result nil)

(defvar files-test-safe-result nil)
(put 'files-test-safe-result 'safe-local-variable 'booleanp)

(defun files-test-fun1 ()
  (setq files-test-result t))

;; Test combinations:
;; `enable-local-variables' t, nil, :safe, :all, or something else.
;; `enable-local-eval' t, nil, or something else.

(defvar files-test-local-variable-data
  ;; Unsafe eval form
  '((("eval: (files-test-fun1)")
     (t t         (eq files-test-result t))
     (t nil       (eq files-test-result nil))
     (t maybe     (eq files-test-result 'query))
     (nil t       (eq files-test-result nil))
     (nil nil     (eq files-test-result nil))
     (nil maybe   (eq files-test-result nil))
     (:safe t     (eq files-test-result nil))
     (:safe nil   (eq files-test-result nil))
     (:safe maybe (eq files-test-result nil))
     (:all t      (eq files-test-result t))
     (:all nil    (eq files-test-result nil))
     (:all maybe  (eq files-test-result t)) ; This combination is ambiguous.
     (maybe t     (eq files-test-result 'query))
     (maybe nil   (eq files-test-result nil))
     (maybe maybe (eq files-test-result 'query)))
    ;; Unsafe local variable value
    (("files-test-result: t")
     (t t         (eq files-test-result 'query))
     (t nil       (eq files-test-result 'query))
     (t maybe     (eq files-test-result 'query))
     (nil t       (eq files-test-result nil))
     (nil nil     (eq files-test-result nil))
     (nil maybe   (eq files-test-result nil))
     (:safe t     (eq files-test-result nil))
     (:safe nil   (eq files-test-result nil))
     (:safe maybe (eq files-test-result nil))
     (:all t      (eq files-test-result t))
     (:all nil    (eq files-test-result t))
     (:all maybe  (eq files-test-result t))
     (maybe t     (eq files-test-result 'query))
     (maybe nil   (eq files-test-result 'query))
     (maybe maybe (eq files-test-result 'query)))
    ;; Safe local variable
    (("files-test-safe-result: t")
     (t t         (eq files-test-safe-result t))
     (t nil       (eq files-test-safe-result t))
     (t maybe     (eq files-test-safe-result t))
     (nil t       (eq files-test-safe-result nil))
     (nil nil     (eq files-test-safe-result nil))
     (nil maybe   (eq files-test-safe-result nil))
     (:safe t     (eq files-test-safe-result t))
     (:safe nil   (eq files-test-safe-result t))
     (:safe maybe (eq files-test-safe-result t))
     (:all t      (eq files-test-safe-result t))
     (:all nil    (eq files-test-safe-result t))
     (:all maybe  (eq files-test-safe-result t))
     (maybe t     (eq files-test-result 'query))
     (maybe nil   (eq files-test-result 'query))
     (maybe maybe (eq files-test-result 'query)))
    ;; Safe local variable with unsafe value
    (("files-test-safe-result: 1")
     (t t         (eq files-test-result 'query))
     (t nil       (eq files-test-result 'query))
     (t maybe     (eq files-test-result 'query))
     (nil t       (eq files-test-safe-result nil))
     (nil nil     (eq files-test-safe-result nil))
     (nil maybe   (eq files-test-safe-result nil))
     (:safe t     (eq files-test-safe-result nil))
     (:safe nil   (eq files-test-safe-result nil))
     (:safe maybe (eq files-test-safe-result nil))
     (:all t      (eq files-test-safe-result 1))
     (:all nil    (eq files-test-safe-result 1))
     (:all maybe  (eq files-test-safe-result 1))
     (maybe t     (eq files-test-result 'query))
     (maybe nil   (eq files-test-result 'query))
     (maybe maybe (eq files-test-result 'query))))
  "List of file-local variable tests.
Each list element should have the form

  (LOCAL-VARS-LIST . TEST-LIST)

where LOCAL-VARS-LISTS should be a list of local variable
definitions (strings) and TEST-LIST is a list of tests to
perform.  Each entry of TEST-LIST should have the form

 (ENABLE-LOCAL-VARIABLES ENABLE-LOCAL-EVAL FORM)

where ENABLE-LOCAL-VARIABLES is the value to assign to
`enable-local-variables', ENABLE-LOCAL-EVAL is the value to
assign to `enable-local-eval', and FORM is a desired `should'
form.")

(defun file-test--do-local-variables-test (str test-settings)
  (with-temp-buffer
    (insert str)
    (setq files-test-result nil
	  files-test-safe-result nil)
    (let ((enable-local-variables (nth 0 test-settings))
	  (enable-local-eval      (nth 1 test-settings))
	  ;; Prevent any dir-locals file interfering with the tests.
	  (enable-dir-local-variables nil)
	  (files-test-queried nil))
      (hack-local-variables)
      (eval (nth 2 test-settings)))))

(ert-deftest files-test-local-variables ()
  "Test the file-local variables implementation."
  (unwind-protect
      (progn
	(defadvice hack-local-variables-confirm (around files-test activate)
	  (setq files-test-result 'query)
	  nil)
	(dolist (test files-test-local-variable-data)
	  (let ((str (concat "text\n\n;; Local Variables:\n;; "
			     (mapconcat 'identity (car test) "\n;; ")
			     "\n;; End:\n")))
	    (dolist (subtest (cdr test))
	      (should (file-test--do-local-variables-test str subtest))))))
    (ad-disable-advice 'hack-local-variables-confirm 'around 'files-test)))

(defvar files-test-bug-18141-file
  (expand-file-name "data/files-bug18141.el.gz" (getenv "EMACS_TEST_DIRECTORY"))
  "Test file for bug#18141.")

(ert-deftest files-test-bug-18141 ()
  "Test for http://debbugs.gnu.org/18141 ."
  (skip-unless (executable-find "gzip"))
  (let ((tempfile (make-temp-file "files-test-bug-18141" nil ".gz")))
    (unwind-protect
	(progn
	  (copy-file files-test-bug-18141-file tempfile t)
	  (with-current-buffer (find-file-noselect tempfile)
	    (set-buffer-modified-p t)
	    (save-buffer)
	    (should (eq buffer-file-coding-system 'iso-2022-7bit-unix))))
      (delete-file tempfile))))


(ert-deftest find-file-path-completion-table-duplicates ()
  "Test completion when there are two files with the same name in
different directories on path."
  (let* ((root (make-temp-file "find-file-path-test" t))
	 (dir1 (concat root "/dir1"))
	 (dir2 (concat root "/dir2")))

    (mkdir dir1)
    (mkdir dir2)

    (with-temp-file (concat dir1 "/file1.el")
      (insert "dir1/file1.el"))
    (with-temp-file (concat dir1 "/file2.el")
      (insert "dir1/file2.el"))

    (with-temp-file (concat dir2 "/file1.el")
      (insert "dir2/file1.el"))
    (with-temp-file (concat dir2 "/file3.el")
      (insert "dir2/file3.el"))

    ;; multiple completions, some with same name
    (should (equal (find-file-path-completion-table (list dir1 dir2) nil "fi")
		   '("file1.el<dir1>" "file1.el<dir2>" "file2.el" "file3.el")))

    ;; only one completion (after user selects first of the above)
    (should (equal (find-file-path-completion-table (list dir1 dir2) nil "file1.el<dir1>")
		   '("file1.el<dir1>")))
    ))

(ert-deftest find-file-path-completion-table-predicate ()
  "Test completion when there are two files with the same name in
different directories on path, and a predicate."
  (let* ((root (make-temp-file "find-file-path-test" t))
	 (dir1 (concat root "/dir1"))
	 (dir2 (concat root "/dir2"))
         (regexp (dired-glob-regexp "*.elc"))
	 (pred (lambda (name) (not (string-match regexp name)))))

    (mkdir dir1)
    (mkdir dir2)

    (with-temp-file (concat dir1 "/file1.el")
      (insert "dir1/file1.el"))
    (with-temp-file (concat dir1 "/file1.elc")
      (insert "dir1/file1.elc"))
    (with-temp-file (concat dir1 "/file2.el")
      (insert "dir1/file2.el"))
    (with-temp-file (concat dir1 "/file2.elc")
      (insert "dir1/file2.elc"))

    (with-temp-file (concat dir2 "/file1.el")
      (insert "dir2/file1.el"))
    (with-temp-file (concat dir2 "/file1.elc")
      (insert "dir2/file1.elc"))
    (with-temp-file (concat dir2 "/file3.el")
      (insert "dir2/file3.el"))
    (with-temp-file (concat dir2 "/file3.elc")
      (insert "dir2/file3.elc"))

    ;; multiple completions, some with same name, predicate eliminates some
    (should (equal (find-file-path-completion-table (list dir1 dir2) pred "fi")
		   '("file1.el<dir1>" "file1.el<dir2>" "file2.el" "file3.el")))

    ;; only one completion (after user selects first of the above)
    (should (equal (find-file-path-completion-table (list dir1 dir2) pred "file1.el<dir1>")
		   '("file1.el<dir1>")))
    ))
;; Stop the above "Local Var..." confusing Emacs.
\f

;;; files.el ends here

debug log:

solving 789fb01 ...
found 789fb01 in https://yhetil.org/emacs-devel/86pp1j4ejm.fsf@stephe-leake.org/
found 0522e0c in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 0522e0c5c79428ef773b070a22344d3f2c6002f5	test/automated/files.el

applying [1/1] https://yhetil.org/emacs-devel/86pp1j4ejm.fsf@stephe-leake.org/
diff --git a/test/automated/files.el b/test/automated/files.el
index 0522e0c..789fb01 100644

Checking patch test/automated/files.el...
Applied patch test/automated/files.el cleanly.

index at:
100644 789fb013803d7c44e1103fc72a72bafb767a552b	test/automated/files.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).