unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob bcff3b08105879cd25bc166c03e46f8f2c743c4e 3122 bytes (raw)
name: packages/context-coloring/libraries/ert-async.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
;;; ert-async.el --- Async support for ERT -*- lexical-binding: t; -*-

;; Copyright (C) 2014 Johan Andersson

;; Author: Johan Andersson <johan.rejeep@gmail.com>
;; Maintainer: Johan Andersson <johan.rejeep@gmail.com>
;; Version: 0.1.1
;; Keywords: test
;; URL: http://github.com/rejeep/ert-async.el

;; This file is NOT part of GNU Emacs.

;;; License:

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;;; Code:

(require 'ert)

(defvar ert-async-timeout 10
  "Number of seconds to wait for callbacks before failing.")

(defun ert-async-activate-font-lock-keywords ()
  "Activate font-lock keywords for `ert-deftest-async'."
  (font-lock-add-keywords
   nil
   '(("(\\(\\<ert-deftest\\(?:-async\\)?\\)\\>\\s *\\(\\(?:\\sw\\|\\s_\\)+\\)?"
      (1 font-lock-keyword-face nil t)
      (2 font-lock-function-name-face nil t)))))

(defmacro ert-deftest-async (name callbacks &rest body)
  "Like `ert-deftest' but with support for async.

NAME is the name of the test, which is the first argument to
`ert-deftest'.

CALLBACKS is a list of callback functions that all must be called
before `ert-async-timeout'.  If all callback functions have not
been called before the timeout, the test fails.

The callback functions should be called without any argument.  If
a callback function is called with a string as argument, the test
will fail with that error string.

BODY is the actual test."
  (declare (indent 2))
  (let ((varlist
         (cons
          'callbacked
          (mapcar
           (lambda (callback)
             (list
              callback
              `(lambda (&optional error-message)
                 (if error-message
                     (ert-fail (format "Callback %s invoked with argument: %s" ',callback error-message))
                   (if (member ',callback callbacked)
                       (ert-fail (format "Callback %s called multiple times" ',callback))
                     (push ',callback callbacked))))))
           callbacks))))
    `(ert-deftest ,name ()
       (let* ,varlist
         (with-timeout
             (ert-async-timeout
              (ert-fail (format "Timeout of %ds exceeded" ert-async-timeout)))
           ,@body
           (while (not (equal (sort (mapcar 'symbol-name callbacked) 'string<)
                              (sort (mapcar 'symbol-name ',callbacks) 'string<)))
             (accept-process-output nil 0.05)))))))

(provide 'ert-async)

;;; ert-async.el ends here

debug log:

solving bcff3b0 ...
found bcff3b0 in https://yhetil.org/emacs-devel/CAGiE8Az6kAQTNuhrZO_dGB1O9hOMqeSbxMOH0bG+RDLPUY0z=A@mail.gmail.com/

applying [1/1] https://yhetil.org/emacs-devel/CAGiE8Az6kAQTNuhrZO_dGB1O9hOMqeSbxMOH0bG+RDLPUY0z=A@mail.gmail.com/
diff --git a/packages/context-coloring/libraries/ert-async.el b/packages/context-coloring/libraries/ert-async.el
new file mode 100644
index 0000000..bcff3b0

Checking patch packages/context-coloring/libraries/ert-async.el...
Applied patch packages/context-coloring/libraries/ert-async.el cleanly.

index at:
100644 bcff3b08105879cd25bc166c03e46f8f2c743c4e	packages/context-coloring/libraries/ert-async.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).