tag: 1.2
commit 38a27becbb5099a9c9b7e7480d1876c30364cc9e
Author: João Távora <[email protected]>
Commit: João Távora <[email protected]>
Add a test for eglot-ensure. Make
sure it runs last, since a bug in the python-flymake backend may
trigger a sentinel error that interferes with other tests.
* eglot-tests.el (zzz-eglot-ensure): New test.
(python, ert-x): Require it.
---
eglot-tests.el | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/eglot-tests.el b/eglot-tests.el
index 26ddf1f..33d96a5 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -26,7 +26,9 @@
(require 'eglot)
(require 'cl-lib)
(require 'ert)
+(require 'ert-x) ; ert-simulate-command
(require 'edebug)
+(require 'python) ; python-mode-hook
;; Helpers
@@ -431,6 +433,29 @@ Pass TIMEOUT to `eglot--with-timeout'."
(= severity 1))
diagnostics)))))))))
+(ert-deftest zzz-eglot-ensure ()
+ "Test basic `eglot-ensure' functionality"
+ (skip-unless (executable-find "pyls"))
+ (eglot--with-dirs-and-files
+ '(("project" . (("foo.py" . "import sys\nsys.exi")
+ ("bar.py" . "import sys\nsys.exi"))))
+ (let ((saved-python-mode-hook python-mode-hook)
+ server)
+ (unwind-protect
+ (progn
+ (add-hook 'python-mode-hook 'eglot-ensure)
+ ;; need `ert-simulate-command' because `eglot-ensure'
+ ;; relies on `post-command-hook'.
+ (with-current-buffer
+ (ert-simulate-command
+ '(find-file "project/foo.py"))
+ (should (setq server (eglot--current-server))))
+ (with-current-buffer
+ (ert-simulate-command
+ '(find-file "project/bar.py"))
+ (should (eq server (eglot--current-server)))))
+ (setq python-mode-hook saved-python-mode-hook)))))
+
(provide 'eglot-tests)
;;; eglot-tests.el ends here