Type checking for `define-widget'
[emacs.git] / test / automated / process-tests.el
blobdabfbc56b78dd9eb5a13756c49e45c3f40b02c21
1 ;;; process-tests.el --- Testing the process facilities
3 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
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.
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.
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/>.
18 ;;; Commentary:
22 ;;; Code:
24 (require 'ert)
26 ;; Timeout in seconds; the test fails if the timeout is reached.
27 (defvar process-test-sentinel-wait-timeout 2.0)
29 ;; Start a process that exits immediately. Call WAIT-FUNCTION,
30 ;; possibly multiple times, to wait for the process to complete.
31 (defun process-test-sentinel-wait-function-working-p (wait-function)
32 (let ((proc (start-process "test" nil "bash" "-c" "exit 20"))
33 (sentinel-called nil)
34 (start-time (float-time)))
35 (set-process-sentinel proc (lambda (proc msg)
36 (setq sentinel-called t)))
37 (while (not (or sentinel-called
38 (> (- (float-time) start-time)
39 process-test-sentinel-wait-timeout)))
40 (funcall wait-function))
41 (cl-assert (eq (process-status proc) 'exit))
42 (cl-assert (= (process-exit-status proc) 20))
43 sentinel-called))
45 (ert-deftest process-test-sentinel-accept-process-output ()
46 (should (process-test-sentinel-wait-function-working-p
47 #'accept-process-output)))
49 (ert-deftest process-test-sentinel-sit-for ()
50 (should
51 (process-test-sentinel-wait-function-working-p (lambda () (sit-for 0.01 t)))))
53 (when (eq system-type 'windows-nt)
54 (ert-deftest process-test-quoted-batfile ()
55 "Check that Emacs hides CreateProcess deficiency (bug#18745)."
56 (let (batfile)
57 (unwind-protect
58 (progn
59 ;; CreateProcess will fail when both the bat file and 1st
60 ;; argument are quoted, so include spaces in both of those
61 ;; to force quoting.
62 (setq batfile (make-temp-file "echo args" nil ".bat"))
63 (with-temp-file batfile
64 (insert "@echo arg1 = %1, arg2 = %2\n"))
65 (with-temp-buffer
66 (call-process batfile nil '(t t) t "x &y")
67 (should (string= (buffer-string) "arg1 = \"x &y\", arg2 = \n")))
68 (with-temp-buffer
69 (call-process-shell-command
70 (mapconcat #'shell-quote-argument (list batfile "x &y") " ")
71 nil '(t t) t)
72 (should (string= (buffer-string) "arg1 = \"x &y\", arg2 = \n"))))
73 (when batfile (delete-file batfile))))))
75 (provide 'process-tests)