|
| 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