unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob d06131571421fcd61329343d51be6ae26dbdce02 7972 bytes (raw)
name: test/lisp/custom-tests.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
 
;;; custom-tests.el --- tests for custom.el  -*- lexical-binding: t -*-

;; Copyright (C) 2018-2020 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 this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)

(require 'wid-edit)
(require 'cus-edit)
(require 'seq) ; For `seq-find'.

(ert-deftest custom-theme--load-path ()
  "Test `custom-theme--load-path' behavior."
  (let ((tmpdir (file-name-as-directory (make-temp-file "custom-tests-" t))))
    (unwind-protect
        ;; Create all temporary files under the same deletable parent.
        (let ((temporary-file-directory tmpdir))
          ;; Path is empty.
          (let ((custom-theme-load-path ()))
            (should (null (custom-theme--load-path))))

          ;; Path comprises non-existent file.
          (let* ((name (make-temp-name tmpdir))
                 (custom-theme-load-path (list name)))
            (should (not (file-exists-p name)))
            (should (null (custom-theme--load-path))))

          ;; Path comprises existing file.
          (let* ((file (make-temp-file "file"))
                 (custom-theme-load-path (list file)))
            (should (file-exists-p file))
            (should (not (file-directory-p file)))
            (should (null (custom-theme--load-path))))

          ;; Path comprises existing directory.
          (let* ((dir (make-temp-file "dir" t))
                 (custom-theme-load-path (list dir)))
            (should (file-directory-p dir))
            (should (equal (custom-theme--load-path) custom-theme-load-path)))

          ;; Expand `custom-theme-directory' path element.
          (let ((custom-theme-load-path '(custom-theme-directory)))
            (let ((custom-theme-directory (make-temp-name tmpdir)))
              (should (not (file-exists-p custom-theme-directory)))
              (should (null (custom-theme--load-path))))
            (let ((custom-theme-directory (make-temp-file "file")))
              (should (file-exists-p custom-theme-directory))
              (should (not (file-directory-p custom-theme-directory)))
              (should (null (custom-theme--load-path))))
            (let ((custom-theme-directory (make-temp-file "dir" t)))
              (should (file-directory-p custom-theme-directory))
              (should (equal (custom-theme--load-path)
                             (list custom-theme-directory)))))

          ;; Expand t path element.
          (let ((custom-theme-load-path '(t)))
            (let ((data-directory (make-temp-name tmpdir)))
              (should (not (file-exists-p data-directory)))
              (should (null (custom-theme--load-path))))
            (let ((data-directory tmpdir)
                  (themedir (expand-file-name "themes" tmpdir)))
              (should (not (file-exists-p themedir)))
              (should (null (custom-theme--load-path)))
              (with-temp-file themedir)
              (should (file-exists-p themedir))
              (should (not (file-directory-p themedir)))
              (should (null (custom-theme--load-path)))
              (delete-file themedir)
              (make-directory themedir)
              (should (file-directory-p themedir))
              (should (equal (custom-theme--load-path) (list themedir))))))
      (when (file-directory-p tmpdir)
        (delete-directory tmpdir t)))))

(defcustom custom--test-user-option 'foo
  "User option for test."
  :group 'emacs
  :type 'symbol)

(defvar custom--test-variable 'foo
  "Variable for test.")

;; This is demonstrating bug#34027.
(ert-deftest custom--test-theme-variables ()
  "Test variables setting with enabling / disabling a custom theme."
  ;; We load custom-resources/custom--test-theme.el.
  (let ((custom-theme-load-path
         `(,(expand-file-name "custom-resources" (file-name-directory #$)))))
    (load-theme 'custom--test 'no-confirm 'no-enable)
    ;; The variables have still their initial values.
    (should (equal custom--test-user-option 'foo))
    (should (equal custom--test-variable 'foo))

    (custom-set-variables
     '(custom--test-user-option 'baz)
     '(custom--test-variable 'baz))
    ;; The initial values have been changed.
    (should (equal custom--test-user-option 'baz))
    (should (equal custom--test-variable 'baz))

    ;; Enable and then disable.
    (enable-theme 'custom--test)
    (disable-theme 'custom--test)
    ;; The variables should have the changed values, by reverting.
    (should (equal custom--test-user-option 'baz))
    (should (equal custom--test-variable 'baz))))

;; This tests Bug#5358.
(ert-deftest custom-test-show-comment-preserves-changes ()
  "Test that adding a comment doesn't discard modifications in progress."
  (customize-option 'custom--test-user-option)
  (let* ((field (seq-find (lambda (widget)
                            (eq custom--test-user-option (widget-value widget)))
                          widget-field-list))
         (parent (widget-get field :parent))
	 (origvalue (widget-value field)))
    ;; Move to the end of the text of the widget, and modify it.  This
    ;; modification should be preserved after showing the comment field.
    (goto-char (widget-field-text-end field))
    (insert "bar")
    (custom-comment-show parent)
    ;; From now on, must use `widget-at' to get the value of the widget.
    (should-not (eq origvalue (widget-value (widget-at))))
    (should (eq (widget-get parent :custom-state) 'modified))
    (should (eq (widget-value (widget-at))
                (widget-apply field
                              :value-to-external
                              (concat
                               (widget-apply field :value-to-internal origvalue)
                               "bar"))))))

(ert-deftest custom-test-unlispify-tag-name-propertizing ()
  "Test that propertizing tag name for variables and faces works as intended."
  ;; Customize a group that has a dash.
  ;; The buffer name should have the group name unlispified.
  (customize-group 'custom-browse)
  (should (string= (buffer-name) "*Customize Group: Custom Browse*"))
  ;; Advance to the group tag.
  (search-forward (get 'custom-browse 'group-documentation))
  (beginning-of-line)
  ;; The display property should be the group name unlispified.
  (should (string= (get-text-property (point) 'display) "Custom Browse"))
  ;; And we should be able to detect a symbol at point, the group name,
  ;; lispified.
  (should (eq (symbol-at-point) 'custom-browse))

  ;; We use the first user option, for testing.
  (let ((w (car (widget-get (car custom-options) :children))))
    ;; The symbol name should be the same string stored in :tag, not counting
    ;; text properties.
    (should (string= (symbol-name (widget-get w :value))
                     (widget-get w :tag)))
    ;; And the 'display text property should be the unlispified symbol name.
    (should (string= (custom-unlispify-tag-name (widget-get w :value))
                     (get-text-property 0 'display (widget-get w :tag)))))

  ;; Now try with a face.
  (customize-face 'scroll-bar)
  (let ((w (car custom-options)))
    (should (string= (symbol-name (widget-get w :value))
                     (widget-get w :tag)))
    (should (string= (custom-unlispify-tag-name (widget-get w :value))
                     (get-text-property 0 'display (widget-get w :tag))))))

;;; custom-tests.el ends here

debug log:

solving d061315714 ...
found d061315714 in https://yhetil.org/emacs-bugs/CABczVwektDiST4WH9U8wb678PdF8M4yG-UAOQzwFzbiYTFXtiQ@mail.gmail.com/
found 7853c84bb6 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 7853c84bb69e66c3694e5b2d9d7173d6f61ae390	test/lisp/custom-tests.el

applying [1/1] https://yhetil.org/emacs-bugs/CABczVwektDiST4WH9U8wb678PdF8M4yG-UAOQzwFzbiYTFXtiQ@mail.gmail.com/
diff --git a/test/lisp/custom-tests.el b/test/lisp/custom-tests.el
index 7853c84bb6..d061315714 100644

Checking patch test/lisp/custom-tests.el...
Applied patch test/lisp/custom-tests.el cleanly.

index at:
100644 d06131571421fcd61329343d51be6ae26dbdce02	test/lisp/custom-tests.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).