;;; esh-proc-tests.el --- esh-proc test suite -*- lexical-binding:t -*- ;; Copyright (C) 2022-2023 Free Software Foundation, Inc. ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; 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. ;; GNU Emacs is distributed in the hope that it will be useful, ;; 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 ;; along with GNU Emacs. If not, see . ;;; Code: (require 'tramp) (require 'ert) (require 'esh-mode) (require 'eshell) (require 'eshell-tests-helpers (expand-file-name "eshell-tests-helpers" (file-name-directory (or load-file-name default-directory)))) (defvar esh-proc-test--output-cmd (concat "sh -c '" "echo stdout; " "echo stderr >&2" "'") "A shell command that prints to both stdout and stderr.") (defvar esh-proc-test--detect-pty-cmd (concat "sh -c '" "if [ -t 0 ]; then echo stdin; fi; " "if [ -t 1 ]; then echo stdout; fi; " "if [ -t 2 ]; then echo stderr; fi" "'") "A shell command that prints the standard streams connected as TTYs.") ;;; Tests: ;; Output and redirection ;; Pipelines (ert-deftest esh-proc-test/pipeline-connection-type/first () "Test that only stdin is a PTY when a command starts a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) (eshell-command-result-equal (concat esh-proc-test--detect-pty-cmd " | cat") (unless (eq system-type 'windows-nt) "stdin\n"))) (ert-deftest esh-proc-test/pipeline-connection-type/first0 () "Test that only stdin is a PTY when a command starts a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) (eshell-command-result-equal (concat esh-proc-test--detect-pty-cmd " | cat") (unless (eq system-type 'windows-nt) "stdin\n"))) (ert-deftest esh-proc-test/pipeline-connection-type/first1 () "Test that only stdin is a PTY when a command starts a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) (eshell-command-result-equal (concat esh-proc-test--detect-pty-cmd " | cat") (unless (eq system-type 'windows-nt) "stdin\n"))) (ert-deftest esh-proc-test/pipeline-connection-type/first2 () "Test that only stdin is a PTY when a command starts a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) (eshell-command-result-equal (concat esh-proc-test--detect-pty-cmd " | cat") (unless (eq system-type 'windows-nt) "stdin\n"))) (ert-deftest esh-proc-test/pipeline-connection-type/middle () "Test that all streams are pipes when a command is in the middle of a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd " | cat") nil))) (ert-deftest esh-proc-test/pipeline-connection-type/middle0 () "Test that all streams are pipes when a command is in the middle of a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd " | cat") nil))) (ert-deftest esh-proc-test/pipeline-connection-type/middle1 () "Test that all streams are pipes when a command is in the middle of a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd " | cat") nil))) (ert-deftest esh-proc-test/pipeline-connection-type/middle2 () "Test that all streams are pipes when a command is in the middle of a pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd " | cat") nil))) (ert-deftest esh-proc-test/pipeline-connection-type/last () "Test that only output streams are PTYs when a command ends a pipeline." (skip-unless (executable-find "sh")) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd) (unless (eq system-type 'windows-nt) "stdout\nstderr\n")))) (ert-deftest esh-proc-test/pipeline-connection-type/last0 () "Test that only output streams are PTYs when a command ends a pipeline." (skip-unless (executable-find "sh")) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd) (unless (eq system-type 'windows-nt) "stdout\nstderr\n")))) (ert-deftest esh-proc-test/pipeline-connection-type/last1 () "Test that only output streams are PTYs when a command ends a pipeline." (skip-unless (executable-find "sh")) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd) (unless (eq system-type 'windows-nt) "stdout\nstderr\n")))) (ert-deftest esh-proc-test/pipeline-connection-type/last2 () "Test that only output streams are PTYs when a command ends a pipeline." (skip-unless (executable-find "sh")) ;; An `eshell-pipe-broken' signal might occur internally; let Eshell ;; handle it! (let ((debug-on-error nil)) (eshell-command-result-equal (concat "echo hi | " esh-proc-test--detect-pty-cmd) (unless (eq system-type 'windows-nt) "stdout\nstderr\n")))) ;;; esh-proc-tests.el ends here