emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 418cade2390 2/2: Eglot: robustify eglot-test-basic-symlink test (


From: João Távora
Subject: master 418cade2390 2/2: Eglot: robustify eglot-test-basic-symlink test (bug#70036)
Date: Tue, 23 Apr 2024 09:53:16 -0400 (EDT)

branch: master
commit 418cade2390e4d6cd7ead1122e62742282e7b2cd
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    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.
---
 test/lisp/progmodes/eglot-tests.el | 47 +++++++++++++++++++++++++++++---------
 1 file 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\"."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]