]> code.delx.au - gnu-emacs-elpa/blob - async-test.el
Handle errors file by file instead of returning on first error.
[gnu-emacs-elpa] / async-test.el
1 ;;; async-test.el --- async.el-related tests
2
3 ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
4
5 ;; Author: John Wiegley <jwiegley@gmail.com>
6 ;; Created: 10 Jul 2012
7 ;; Version: 1.0
8 ;; Keywords: async
9 ;; X-URL: https://github.com/jwiegley/emacs-async
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25 \f
26 ;;; Commentary:
27
28 ;; Contains tests for all the async modules.
29 \f
30 ;;; Code:
31
32 (require 'async)
33
34
35 (eval-when-compile
36 (require 'cl))
37
38 (defun async-test-1 ()
39 (interactive)
40 (message "Starting async-test-1...")
41 (async-start
42 ;; What to do in the child process
43 (lambda ()
44 (message "This is a test")
45 (sleep-for 3)
46 222)
47
48 ;; What to do when it finishes
49 (lambda (result)
50 (message "Async process done, result should be 222: %s" result)))
51 (message "Starting async-test-1...done"))
52
53 (defun async-test-2 ()
54 (interactive)
55 (message "Starting async-test-2...")
56 (let ((proc (async-start
57 ;; What to do in the child process
58 (lambda ()
59 (message "This is a test")
60 (sleep-for 3)
61 222))))
62 (message "I'm going to do some work here")
63 ;; ....
64 (message "Async process done, result should be 222: %s"
65 (async-get proc))))
66
67 (defun async-test-3 ()
68 (interactive)
69 (message "Starting async-test-3...")
70 (async-start
71 ;; What to do in the child process
72 (lambda ()
73 (message "This is a test")
74 (sleep-for 3)
75 (error "Error in child process")
76 222)
77
78 ;; What to do when it finishes
79 (lambda (result)
80 (message "Async process done, result should be 222: %s" result)))
81 (message "Starting async-test-1...done"))
82
83 (defun async-test-4 ()
84 (interactive)
85 (message "Starting async-test-4...")
86 (async-start-process "sleep" "sleep"
87 ;; What to do when it finishes
88 (lambda (proc)
89 (message "Sleep done, exit code was %d"
90 (process-exit-status proc)))
91 "3")
92 (message "Starting async-test-4...done"))
93
94 (defun async-test-5 ()
95 (interactive)
96 (message "Starting async-test-5...")
97 (let ((proc
98 (async-start
99 ;; What to do in the child process
100 (lambda ()
101 (message "This is a test, sending message")
102 (async-send :hello "world")
103 ;; wait for a message
104 (let ((msg (async-receive)))
105 (message "Child got message: %s"
106 (plist-get msg :goodbye)))
107 (sleep-for 3)
108 222)
109
110 ;; What to do when it finishes
111 (lambda (result)
112 (if (async-message-p result)
113 (message "Got hello from child process: %s"
114 (plist-get result :hello))
115 (message "Async process done, result should be 222: %s"
116 result))))))
117 (async-send proc :goodbye "everyone"))
118 (message "Starting async-test-5...done"))
119
120 (defun async-test-6 ()
121 (interactive)
122 (message "Starting async-test-6...")
123 (async-start
124 ;; What to do in the child process
125 `(lambda ()
126 ,(async-inject-variables "\\`user-mail-address\\'")
127 (format "user-mail-address = %s" user-mail-address))
128
129 ;; What to do when it finishes
130 (lambda (result)
131 (message "Async process done: %s" result))))
132
133
134 (provide 'async-test)
135
136 ;;; async-test.el ends here
137
138 ;; Local Variables:
139 ;; no-byte-compile: t
140 ;; End: