Merge branch 'bldchn/diag' into next
[sxemacs] / tests / automated / os-tests.el
1 ;;; os-tests.el --- test support for OS interaction
2
3 ;; Copyright (C) 2004 Free Software Foundation
4
5 ;; Author: Stephen J. Turnbull <stephen@xemacs.org>
6 ;; Maintainer: Stephen J. Turnbull <stephen@xemacs.org>
7 ;; Created: 2004 October 28
8 ;; Keywords: tests, process support
9
10 ;; This file is part of SXEmacs.
11
12 ;; SXEmacs is free software: you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by the
14 ;; Free Software Foundation, either version 3 of the License, or (at your
15 ;; option) any later version.
16
17 ;; SXEmacs is distributed in the hope that it will be
18 ;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>. 
24
25 ;;; Synched up with: Not in FSF.
26
27 ;;; Commentary:
28
29 ;; Test OS support.  Processes, environment variables, etc.
30 ;; See test-harness.el for instructions on how to run these tests.
31
32 ;; call-process-region bug reported by Katsumi Yamaoka on 2004-10-26
33 ;; in <b9yvfcyuscf.fsf@jpl.org>, who suggested the basic test scheme
34 ;; in <b9yoeipvwn0.fsf@jpl.org>.
35
36 (and-fboundp 'executable-find
37   ;; tac works by lines, unfortunately
38   (let* ((original-string "a\nb\nc\nd\n")
39          (tac-cases (if (executable-find "tac")
40                         '((1 . "c\nb\na\nd\n")
41                           (3 . "a\nc\nb\nd\n")
42                           (5 . "a\nc\nb\nd\n")
43                           (7 . "a\nc\nb\nd\n")
44                           (9 . "a\nd\nc\nb\n"))
45                       nil))
46          (cat-cases (if (executable-find "cat")
47                         '((1 . "b\nc\na\nd\n")
48                           (3 . "a\nb\nc\nd\n")
49                           (5 . "a\nb\nc\nd\n")
50                           (7 . "a\nb\nc\nd\n")
51                           (9 . "a\nd\nb\nc\n"))
52                       nil))
53          cases case)
54     (with-temp-buffer
55       (Skip-Test-Unless tac-cases
56                         "tac executable not found"
57                         "Tests of call-process-region with region deleted after inserting
58 tac process output."
59                         (setq cases tac-cases)
60                         (while cases
61                           (setq case (car cases)
62                                 cases (cdr cases))
63                           (flet ((do-test (pos result)
64                                    (erase-buffer)
65                                    (insert original-string)
66                                    (goto-char pos)
67                                    (call-process-region 3 7 "tac" t t)
68                                    (goto-char (point-min))
69                                    (Assert (looking-at result))))
70                             (do-test (car case) (cdr case)))))
71       ;; if you're in that much of a hurry you can blow cat off
72       ;; if you've done tac, but I'm not going to bother
73       (Skip-Test-Unless cat-cases
74                         "cat executable not found"
75                         "Tests of call-process-region with region deleted after inserting
76 cat process output."
77                         (setq cases cat-cases)
78                         (while cases
79                           (setq case (car cases)
80                                 cases (cdr cases))
81                           (flet ((do-test (pos result)
82                                    (erase-buffer)
83                                    (insert original-string)
84                                    (goto-char pos)
85                                    (call-process-region 3 7 "cat" t t)
86                                    (goto-char (point-min))
87                                    (Assert (looking-at result))))
88                             (do-test (car case) (cdr case))))))))
89
90 ;;; end of os-tests.el