aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMauro Aranda2021-05-10 13:33:32 +0200
committerLars Ingebrigtsen2021-05-10 13:33:32 +0200
commit779c615f333a01d11ab930b030d61545fb048f3d (patch)
tree493738307f960d58d525af7e1b825ec901dda12e /test
parent5bedbe6b1d5f4b801abf91b4d023d5c4e66418f0 (diff)
downloademacs-779c615f333a01d11ab930b030d61545fb048f3d.tar.gz
emacs-779c615f333a01d11ab930b030d61545fb048f3d.zip
Avoid saving session customizations in the custom-file
* lisp/custom.el (custom-theme-recalc-variable): Only stash theme settings for void variables. (custom-declare-variable): After initializing a variable, unstash a theme setting, if present. (disable-theme): When disabling a theme, maybe unstash a theme setting. * test/lisp/custom-resources/custom--test-theme.el: Add two settings for testing the fix.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/custom-resources/custom--test-theme.el4
-rw-r--r--test/lisp/custom-tests.el104
2 files changed, 107 insertions, 1 deletions
diff --git a/test/lisp/custom-resources/custom--test-theme.el b/test/lisp/custom-resources/custom--test-theme.el
index 122bd795692..36424cdfcc3 100644
--- a/test/lisp/custom-resources/custom--test-theme.el
+++ b/test/lisp/custom-resources/custom--test-theme.el
@@ -6,6 +6,8 @@
6(custom-theme-set-variables 6(custom-theme-set-variables
7 'custom--test 7 'custom--test
8 '(custom--test-user-option 'bar) 8 '(custom--test-user-option 'bar)
9 '(custom--test-variable 'bar)) 9 '(custom--test-variable 'bar)
10 '(custom--test-bug-21355-before 'before)
11 '(custom--test-bug-21355-after 'after))
10 12
11(provide-theme 'custom--test) 13(provide-theme 'custom--test)
diff --git a/test/lisp/custom-tests.el b/test/lisp/custom-tests.el
index 02a9239824d..e93c96e1d93 100644
--- a/test/lisp/custom-tests.el
+++ b/test/lisp/custom-tests.el
@@ -230,4 +230,108 @@ Ensure the directory is recursively deleted after the fact."
230 (should (eq (default-value 'custom--test-local-option) 'initial)) 230 (should (eq (default-value 'custom--test-local-option) 'initial))
231 (should (eq (default-value 'custom--test-permanent-option) 'initial))))) 231 (should (eq (default-value 'custom--test-permanent-option) 'initial)))))
232 232
233;; The following three tests demonstrate Bug#21355.
234;; In this one, we set an user option for the current session and then
235;; we enable a theme that doesn't have a setting for it, ending up with
236;; a non-nil saved-value property. Since the `caar' of the theme-value
237;; property is user (i.e., the user theme setting is active), we might
238;; save the setting to the custom-file, even though it was meant for the
239;; current session only. So there should be a nil saved-value property
240;; for this test to pass.
241(ert-deftest custom-test-no-saved-value-after-enabling-theme ()
242 "Test that we don't record a saved-value property when we shouldn't."
243 (let ((custom-theme-load-path `(,(ert-resource-directory))))
244 (customize-option 'mark-ring-max)
245 (let* ((field (seq-find (lambda (widget)
246 (eq mark-ring-max (widget-value widget)))
247 widget-field-list))
248 (parent (widget-get field :parent)))
249 ;; Move to the editable widget, modify the value and save it.
250 (goto-char (widget-field-text-end field))
251 (insert "0")
252 (widget-apply parent :custom-set)
253 ;; Just setting for the current session should not store a saved-value
254 ;; property.
255 (should-not (get 'mark-ring-max 'saved-value))
256 ;; Now enable and disable the test theme.
257 (load-theme 'custom--test 'no-confirm)
258 (disable-theme 'custom--test)
259 ;; Since the user customized the option, this is OK.
260 (should (eq (caar (get 'mark-ring-max 'theme-value)) 'user))
261 ;; The saved-value property should still be nil.
262 (should-not (get 'mark-ring-max 'saved-value)))))
263
264;; In this second test, we load a theme that has a setting for the user option
265;; above. We must check that we don't end up with a non-nil saved-value
266;; property and a user setting active in the theme-value property, which
267;; means we might inadvertently save the session setting in the custom-file.
268(defcustom custom--test-bug-21355-before 'foo
269 "User option for `custom-test-no-saved-value-after-enabling-theme-2'."
270 :type 'symbol :group 'emacs)
271
272(ert-deftest custom-test-no-saved-value-after-enabling-theme-2 ()
273 "Test that we don't record a saved-value property when we shouldn't."
274 (let ((custom-theme-load-path `(,(ert-resource-directory))))
275 (customize-option 'custom--test-bug-21355-before)
276 (let* ((field (seq-find
277 (lambda (widget)
278 (eq custom--test-bug-21355-before (widget-value widget)))
279 widget-field-list))
280 (parent (widget-get field :parent)))
281 ;; Move to the editable widget, modify the value and save it.
282 (goto-char (widget-field-text-end field))
283 (insert "bar")
284 (widget-apply parent :custom-set)
285 ;; Just setting for the current session should not store a saved-value
286 ;; property.
287 (should-not (get 'custom--test-bug-21355-before 'saved-value))
288 ;; Now load our test theme, which has a setting for
289 ;; `custom--test-bug-21355-before'.
290 (load-theme 'custom--test 'no-confirm 'no-enable)
291 (enable-theme 'custom--test)
292 ;; Since the user customized the option, this is OK.
293 (should (eq (caar (get 'custom--test-bug-21355-before 'theme-value))
294 'user))
295 ;; But the saved-value property has to be nil, since the user didn't mark
296 ;; this variable to save for future sessions.
297 (should-not (get 'custom--test-bug-21355-before 'saved-value)))))
298
299(defvar custom--test-bug-21355-after)
300
301;; In this test, we check that stashing a theme value for a not yet defined
302;; option works, but that later on if the user customizes the option for the
303;; current session, we might save the theme setting in the custom file.
304(ert-deftest custom-test-no-saved-value-after-customizing-option ()
305 "Test for a nil saved-value after setting an option for the current session."
306 (let ((custom-theme-load-path `(,(ert-resource-directory))))
307 ;; Check that we correctly stashed the value.
308 (load-theme 'custom--test 'no-confirm 'no-enable)
309 (enable-theme 'custom--test)
310 (should (and (not (boundp 'custom--test-bug-21355-after))
311 (eq (eval
312 (car (get 'custom--test-bug-21355-after 'saved-value)))
313 'after)))
314 ;; Now Emacs finds the defcustom.
315 (defcustom custom--test-bug-21355-after 'initially "..."
316 :type 'symbol :group 'emacs)
317 ;; And we used the stashed value correctly.
318 (should (and (boundp 'custom--test-bug-21355-after)
319 (eq custom--test-bug-21355-after 'after)))
320 ;; Now customize it.
321 (customize-option 'custom--test-bug-21355-after)
322 (let* ((field (seq-find (lambda (widget)
323 (eq custom--test-bug-21355-after
324 (widget-value widget)))
325 widget-field-list))
326 (parent (widget-get field :parent)))
327 ;; Move to the editable widget, modify the value and save it.
328 (goto-char (widget-field-text-end field))
329 (insert "bar")
330 (widget-apply parent :custom-set)
331 ;; The user customized the variable, so this is OK.
332 (should (eq (caar (get 'custom--test-bug-21355-after 'theme-value))
333 'user))
334 ;; But it was only for the current session, so this should not happen.
335 (should-not (get 'custom--test-bug-21355-after 'saved-value)))))
336
233;;; custom-tests.el ends here 337;;; custom-tests.el ends here