emacsclient-tests.el 2.23 KB
Newer Older
1
;;; emacsclient-tests.el --- Test emacsclient  -*- lexical-binding:t -*-
2

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 2016-2020 Free Software Foundation, Inc.
4

5 6 7
;; This file is part of GNU Emacs.

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

12
;; GNU Emacs is distributed in the hope that it will be useful,
13 14 15 16 17
;; 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
18
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
19 20 21 22 23 24 25 26 27 28

;;; Commentary:

;;

;;; Code:

(require 'ert)

(defconst emacsclient-test-emacs
29 30 31 32
  (if installation-directory
      (expand-file-name "lib-src/emacsclient" installation-directory)
    "emacsclient")
  "The emacsclient binary to test.")
33

34 35 36 37 38 39 40 41 42 43 44 45
(defmacro emacsclient-test-call-emacsclient (editor)
  "Run emacsclient with ALTERNATE_EDITOR set to EDITOR."
  `(let* ((process-environment
           (cons (concat "ALTERNATE_EDITOR=" ,editor) process-environment))
          (stat (call-process emacsclient-test-emacs nil nil nil
                              "--server-file"
                              (expand-file-name "non-existent-file"
                                                invocation-directory)
                              "foo")))
     ;; Skip if emacsclient was compiled with -pg (bug#28319).
     ;; Use ert--skip-unless rather than skip-unless to silence compiler.
     (ert--skip-unless (not (and (stringp stat)
Paul Eggert's avatar
Paul Eggert committed
46
                                 (string-match-p "Profiling" stat))))
47
     (should (eq 0 stat))))
48

49
(ert-deftest emacsclient-test-alternate-editor-allows-arguments ()
50 51
  (emacsclient-test-call-emacsclient
   (concat (expand-file-name invocation-name invocation-directory) " --batch")))
52 53

(ert-deftest emacsclient-test-alternate-editor-allows-quotes ()
54 55 56
  (emacsclient-test-call-emacsclient
   (concat "\"" (expand-file-name invocation-name invocation-directory)
           "\"" " --batch")))
57 58 59

(provide 'emacsclient-tests)
;;; emacsclient-tests.el ends here