summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoão Távora <joaotavora@gmail.com>2024-04-23 08:43:06 -0500
committerJoão Távora <joaotavora@gmail.com>2024-04-23 08:44:43 -0500
commit418cade2390e4d6cd7ead1122e62742282e7b2cd (patch)
treec4ef7622cc94edf845e111ff4fd6e897de93443b /test
parent3a4583baf679289857150ee8ecf20b61e59b9d37 (diff)
downloademacs-418cade2390e4d6cd7ead1122e62742282e7b2cd.tar.gz
Eglot: robustify eglot-test-basic-symlink test (bug#70036)
The previous version of this test was brittle, unstable and didn't really fail when supposed to (because we need main.cpp to not be visited when visiting mainlink.cpp). This new version is faster and more secure. * test/lisp/progmodes/eglot-tests.el (eglot--sniffing): Add to the jsonrpc-event-hook at the end. (eglot-test-basic-symlink): Robustify test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/eglot-tests.el47
1 files changed, 36 insertions, 11 deletions
diff --git a/test/lisp/progmodes/eglot-tests.el b/test/lisp/progmodes/eglot-tests.el
index 914f23bc9e3..4a75a1c5147 100644
--- a/test/lisp/progmodes/eglot-tests.el
+++ b/test/lisp/progmodes/eglot-tests.el
@@ -230,7 +230,7 @@ directory hierarchy."
`(push message ,client-replies)))))))))
(unwind-protect
(progn
- (add-hook 'jsonrpc-event-hook #',log-event-hook-sym)
+ (add-hook 'jsonrpc-event-hook #',log-event-hook-sym t)
,@body)
(remove-hook 'jsonrpc-event-hook #',log-event-hook-sym))))))
@@ -452,17 +452,42 @@ directory hierarchy."
(find-file-noselect "symlink-project/main.cpp")
(make-symbolic-link "main.cpp" "mainlink.cpp")
(eglot--tests-connect)
- (find-file-noselect "mainlink.cpp")
+ (eglot--sniffing (:client-notifications c-notifs)
+ (let ((eglot-autoshutdown nil)) (kill-buffer (current-buffer)))
+ (eglot--wait-for (c-notifs 10)
+ (&key method &allow-other-keys)
+ (and (string= method "textDocument/didClose")))))
+ (eglot--sniffing (:client-notifications c-notifs)
(with-current-buffer
- (find-file-noselect "foo.h")
- (goto-char 5)
- (xref-find-references "foo")
- (with-current-buffer (get-buffer "*xref*")
- (goto-char (point-max))
- ;; Expect xref buffer to not contain duplicate references to
- ;; main.c and mainlink.c. If it did, total lines would be 7.
- ;; FIXME: make less brittle by counting actual references.
- (should (= (line-number-at-pos (point)) 5)))))))
+ (find-file-noselect "symlink-project/main.cpp")
+ (should (eglot-current-server)))
+ (eglot--wait-for (c-notifs 10)
+ (&rest whole &key params method &allow-other-keys)
+ (and (string= method "textDocument/didOpen")
+ (string-match "main.cpp$"
+ (plist-get (plist-get params :textDocument)
+ :uri)))))
+ ;; This last segment is deactivated, because it's likely not needed.
+ ;; The only way the server would answer with '3' references is if we
+ ;; had erroneously sent a 'didOpen' for anything other than
+ ;; `main.cpp', but if we got this far is because we've just asserted
+ ;; that we didn't.
+ (when nil
+ (with-current-buffer
+ (find-file-noselect "symlink-project/foo.h")
+ ;; Give clangd some time to settle its analysis so it can
+ ;; accurately respond to `textDocument/references'
+ (sleep-for 3)
+ (search-forward "foo")
+ (eglot--sniffing (:server-replies s-replies)
+ (call-interactively 'xref-find-references)
+ (eglot--wait-for (s-replies 10)
+ (&key method result &allow-other-keys)
+ ;; Expect xref buffer to not contain duplicate references to
+ ;; main.cpp and mainlink.cpp. If it did, 'result's length
+ ;; would be 3.
+ (and (string= method "textDocument/references")
+ (= (length result) 2))))))))
(ert-deftest eglot-test-diagnostic-tags-unnecessary-code ()
"Test rendering of diagnostics tagged \"unnecessary\"."