Skip to content

Commit

Permalink
Fix tests to not modify top level .dir-locals.el file
Browse files Browse the repository at this point in the history
  • Loading branch information
jtamagnan authored and bbatsov committed Aug 14, 2024
1 parent 0163b33 commit 70d03fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
14 changes: 8 additions & 6 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -2503,9 +2503,10 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
Parameters MODE VARIABLE VALUE are passed directly to `add-dir-local-variable'."
(let ((inhibit-read-only t)
(default-directory (projectile-acquire-root)))
(add-dir-local-variable mode variable value)
(save-buffer)
(kill-buffer)))
(save-selected-window
(add-dir-local-variable mode variable value)
(save-buffer)
(kill-buffer))))

;;;###autoload
(defun projectile-delete-dir-local-variable (mode variable)
Expand All @@ -2515,9 +2516,10 @@ Parameters MODE VARIABLE VALUE are passed directly to
`delete-dir-local-variable'."
(let ((inhibit-read-only t)
(default-directory (projectile-acquire-root)))
(delete-dir-local-variable mode variable)
(save-buffer)
(kill-buffer)))
(save-selected-window
(delete-dir-local-variable mode variable)
(save-buffer)
(kill-buffer))))


;;;; Sorting project files
Expand Down
18 changes: 13 additions & 5 deletions test/projectile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1051,20 +1051,28 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
"project/.projectile")
(append-to-file
"((nil . ((foo . bar))))" nil "project/.dir-locals.el")
(with-current-buffer (find-file-noselect "project/.projectile" t)
(let ((enable-local-variables :all))
(hack-dir-local-variables-non-file-buffer)
(let ((enable-local-variables :all))
(with-current-buffer (find-file-noselect "project/.projectile" t)
;; Reload the file to ensure that this file wasn't already
;; opened from a previous test
(revert-buffer :ignore-auto :noconfirm)
;; Heck that the variable is bound
(expect (boundp 'foo) :to-be 't)

;; Remove the variable
(projectile-delete-dir-local-variable nil 'foo)
(expect (boundp 'foo) :to-be nil) ))))))
;; Reload the file
(revert-buffer :ignore-auto :noconfirm)
;; Check that the variable is unbound
(expect (boundp 'foo) :to-be nil)))))))

(describe "projectile-add-dir-local-variable"
(it "Adds new dir-local variables"
(projectile-test-with-sandbox
(projectile-test-with-files
("project/"
"project/.dir-locals.el"
"project/.projectile")
(append-to-file "()" nil "project/.dir-locals.el")
(with-current-buffer (find-file-noselect "project/.projectile" t)
(let ((enable-local-variables :all))
(expect (boundp 'fooo) :to-be nil)
Expand Down

0 comments on commit 70d03fb

Please sign in to comment.