1 ;;; async-test.el --- async.el-related tests
3 ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
5 ;; Author: John Wiegley <jwiegley@gmail.com>
6 ;; Created: 10 Jul 2012
9 ;; X-URL: https://github.com/jwiegley/emacs-async
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.
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.
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.
28 ;; Contains tests for all the async modules.
38 (defun async-test-1 ()
40 (message "Starting async-test-1...")
42 ;; What to do in the child process
44 (message "This is a test")
48 ;; What to do when it finishes
50 (message "Async process done, result should be 222: %s" result)))
51 (message "Starting async-test-1...done"))
53 (defun async-test-2 ()
55 (message "Starting async-test-2...")
56 (let ((proc (async-start
57 ;; What to do in the child process
59 (message "This is a test")
62 (message "I'm going to do some work here")
64 (message "Async process done, result should be 222: %s"
67 (defun async-test-3 ()
69 (message "Starting async-test-3...")
71 ;; What to do in the child process
73 (message "This is a test")
75 (error "Error in child process")
78 ;; What to do when it finishes
80 (message "Async process done, result should be 222: %s" result)))
81 (message "Starting async-test-1...done"))
83 (defun async-test-4 ()
85 (message "Starting async-test-4...")
86 (async-start-process "sleep" "sleep"
87 ;; What to do when it finishes
89 (message "Sleep done, exit code was %d"
90 (process-exit-status proc)))
92 (message "Starting async-test-4...done"))
94 (defun async-test-5 ()
96 (message "Starting async-test-5...")
99 ;; What to do in the child process
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)))
110 ;; What to do when it finishes
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"
117 (async-send proc :goodbye "everyone"))
118 (message "Starting async-test-5...done"))
120 (defun async-test-6 ()
122 (message "Starting async-test-6...")
124 ;; What to do in the child process
126 ,(async-inject-variables "\\`user-mail-address\\'")
127 (format "user-mail-address = %s" user-mail-address))
129 ;; What to do when it finishes
131 (message "Async process done: %s" result))))
134 (provide 'async-test)
136 ;;; async-test.el ends here
139 ;; no-byte-compile: t