aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorNoam Postavsky2018-05-25 08:40:55 -0400
committerNoam Postavsky2018-06-12 07:40:33 -0400
commitc912db0836f6975519dea57fb0a4adc2988da1b1 (patch)
tree8a58bce003464b5f367beb9e7a4f8555f843d88b /test/src
parent2634d867b66ddff568048ce664f003ae8950bdfa (diff)
downloademacs-c912db0836f6975519dea57fb0a4adc2988da1b1.tar.gz
emacs-c912db0836f6975519dea57fb0a4adc2988da1b1.zip
Give warning if losing value to defvaralias (Bug#5950)
* src/eval.c (Fdefvaralias): Call `display-warning' if the alias target has a non-eq value to the variable being aliased. * test/src/eval-tests.el (defvaralias-overwrite-warning): New test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/eval-tests.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el
index 319dd91c86a..281d959b530 100644
--- a/test/src/eval-tests.el
+++ b/test/src/eval-tests.el
@@ -26,6 +26,7 @@
26;;; Code: 26;;; Code:
27 27
28(require 'ert) 28(require 'ert)
29(eval-when-compile (require 'cl-lib))
29 30
30(ert-deftest eval-tests--bug24673 () 31(ert-deftest eval-tests--bug24673 ()
31 "Check that Bug#24673 has been fixed." 32 "Check that Bug#24673 has been fixed."
@@ -117,4 +118,25 @@ crash/abort/malloc assert failure on the next test."
117 "Check that Bug#31072 is fixed." 118 "Check that Bug#31072 is fixed."
118 (should-error (eval '(defvar 1) t) :type 'wrong-type-argument)) 119 (should-error (eval '(defvar 1) t) :type 'wrong-type-argument))
119 120
121(ert-deftest defvaralias-overwrite-warning ()
122 "Test for Bug#5950."
123 (defvar eval-tests--foo)
124 (setq eval-tests--foo 2)
125 (defvar eval-tests--foo-alias)
126 (setq eval-tests--foo-alias 1)
127 (cl-letf (((symbol-function 'display-warning)
128 (lambda (type &rest _)
129 (throw 'got-warning type))))
130 ;; Warn if we lose a value through aliasing.
131 (should (equal
132 '(defvaralias losing-value eval-tests--foo-alias)
133 (catch 'got-warning
134 (defvaralias 'eval-tests--foo-alias 'eval-tests--foo))))
135 ;; Don't warn if we don't.
136 (makunbound 'eval-tests--foo-alias)
137 (should (eq 'no-warning
138 (catch 'got-warning
139 (defvaralias 'eval-tests--foo-alias 'eval-tests--foo)
140 'no-warning)))))
141
120;;; eval-tests.el ends here 142;;; eval-tests.el ends here