Skip to content

Commit d2abed2

Browse files
authored
Move common test utilities into a separate file. (#4266)
* This avoids loading an ERT test unit directly and causing ERT test redefined error. * Also drop "provide" from test units to avoid loading an ERT test unit directly. * More details - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66782 - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1052939
1 parent 5b2f374 commit d2abed2

8 files changed

+44
-19
lines changed

test/lsp-benchmarks.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@
7676
lsp-benchmark-data))
7777
(garbage-collect)))
7878

79-
(provide 'lsp-benchmarks)
79+
;;; lsp-benchmarks.el ends here

test/lsp-clangd-test.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
(require 'ert)
2525
(require 'lsp-clangd)
26-
(require 'lsp-integration-test)
26+
(require 'lsp-test-utils)
2727

2828
(ert-deftest lsp-clangd-extract-signature-on-hover ()
2929
(should (string= (lsp-clients-extract-signature-on-hover

test/lsp-completion-test.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,4 @@
129129
(should (equal (do-test-trigger-kind t t) 2))) ;; and the session is the same: expect a new trigger-character completion
130130
))
131131

132-
(provide 'lsp-completion-test)
133132
;;; lsp-completion-test.el ends here

test/lsp-file-watch-test.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,4 @@
368368
(should (null lsp--test-events))
369369
(should (ht-empty? (lsp-session-watches)))))
370370

371-
(provide 'lsp-file-watch-test)
372371
;;; lsp-file-watch-test.el ends here

test/lsp-integration-test.el

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@
3939

4040
(defconst lsp-test-location (file-name-directory (or load-file-name buffer-file-name)))
4141

42-
(defun lsp-test--wait-for (form &optional d)
43-
(--doto (or d (deferred:new #'identity))
44-
(run-with-timer
45-
0.001 nil
46-
(lambda ()
47-
(if-let ((result (eval form)))
48-
(deferred:callback-post it result)
49-
(lsp-test--wait-for form it))))))
50-
51-
(defmacro lsp-test-wait (form)
52-
`(lsp-test--wait-for '(progn ,form)))
53-
5442
(defun lsp-def-request-async (method params &rest args)
5543
(--doto (deferred:new #'identity)
5644
(apply #'lsp-request-async method params (-partial #'deferred:callback-post it)
@@ -671,5 +659,4 @@
671659
(replace-match "foobar")))
672660
(deferred:sync!))))
673661

674-
(provide 'lsp-integration-test)
675662
;;; lsp-integration-test.el ends here

test/lsp-mode-test.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,4 @@
175175
"textDocument/hover")))
176176
2)))
177177

178-
(provide 'lsp-mode-test)
179178
;;; lsp-mode-test.el ends here

test/lsp-protocol-test.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,4 @@
167167
(lsp-put input :import_for_trait_assoc_item :json-false)
168168
(should (eq (lsp-get input :import_for_trait_assoc_item) :json-false))))
169169

170-
(provide 'lsp-protocol-test)
171170
;;; lsp-protocol-test.el ends here

test/lsp-test-utils.el

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
;;; lsp-test-utils.el --- unit test utilities -*- lexical-binding: t -*-
2+
3+
;; Copyright (C) emacs-lsp maintainers
4+
5+
;; This program is free software: you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation, either version 3 of the License, or
8+
;; (at your option) any later version.
9+
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
;;; Commentary:
19+
20+
;; This file contains definitions required by other test units. Reusable
21+
;; utilities like functions, macros, and customizables should prefer to be
22+
;; defined here to avoid having to load a unit test directly, because Emacs
23+
;; checks for reused ERT test names since 29.1, which may also be caused by
24+
;; loading the same test unit multiple times. See also discussion in
25+
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66782
26+
27+
;;; Code:
28+
29+
(defun lsp-test--wait-for (form &optional d)
30+
(--doto (or d (deferred:new #'identity))
31+
(run-with-timer
32+
0.001 nil
33+
(lambda ()
34+
(if-let ((result (eval form)))
35+
(deferred:callback-post it result)
36+
(lsp-test--wait-for form it))))))
37+
38+
(defmacro lsp-test-wait (form)
39+
`(lsp-test--wait-for '(progn ,form)))
40+
41+
(provide 'lsp-test-utils)
42+
;;; lsp-test-utils.el ends here

0 commit comments

Comments
 (0)