From 68ca271bf1315bb2f55f4bf48d7c8d8d448734b5 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Wed, 6 Sep 2023 17:00:59 -0700 Subject: [PATCH 4/5] ; Move some Eshell tests to more-topical files eshell-tests.el should mainly be for code in eshell.el. * test/lisp/eshell/eshell-tests.el (eshell-test/pipe-headproc) (eshell-test/pipe-tailproc, eshell-test/pipe-subcommand) (eshell-test/pipe-subcommand-with-pipe) (eshell-test/subcommand-reset-in-pipeline) (eshell-test/lisp-reset-in-pipeline): Move to... * test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/pipeline-wait/head-proc) (esh-cmd-test/pipeline-wait/tail-proc) (esh-cmd-test/pipeline-wait/subcommand) (esh-cmd-test/pipeline-wait/subcommand-with-pipe) (esh-cmd-test/reset-in-pipeline/subcommand) (esh-cmd-test/reset-in-pipeline/lisp): ... here. * test/lisp/eshell/eshell-tests.el (eshell-test/pipe-headproc-stdin): Move to... * test/lisp/eshell/esh-io-tests.el (esh-io-test/pipeline/stdin-to-head): ... here. --- test/lisp/eshell/esh-cmd-tests.el | 62 +++++++++++++++++++++++++++ test/lisp/eshell/esh-io-tests.el | 11 +++++ test/lisp/eshell/eshell-tests.el | 69 ------------------------------- 3 files changed, 73 insertions(+), 69 deletions(-) diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el index a7208eb3a0b..3967910a53d 100644 --- a/test/lisp/eshell/esh-cmd-tests.el +++ b/test/lisp/eshell/esh-cmd-tests.el @@ -137,6 +137,68 @@ esh-cmd-test/or-operator (eshell-match-command-output "[ foo = bar ] || echo hi" "hi\n"))) + +;; Pipelines + +(ert-deftest esh-cmd-test/pipeline-wait/head-proc () + "Check that piping a non-process to a process command waits for the process." + (skip-unless (executable-find "cat")) + (with-temp-eshell + (eshell-match-command-output "echo hi | *cat" + "hi"))) + +(ert-deftest esh-cmd-test/pipeline-wait/tail-proc () + "Check that piping a process to a non-process command waits for the process." + (skip-unless (executable-find "echo")) + (with-temp-eshell + (eshell-match-command-output "*echo hi | echo bye" + "bye\nhi\n"))) + +(ert-deftest esh-cmd-test/pipeline-wait/subcommand () + "Check that piping with an asynchronous subcommand waits for the subcommand." + (skip-unless (and (executable-find "echo") + (executable-find "cat"))) + (with-temp-eshell + (eshell-match-command-output "echo ${*echo hi} | *cat" + "hi"))) + +(ert-deftest esh-cmd-test/pipeline-wait/subcommand-with-pipe () + "Check that piping with an asynchronous subcommand with its own pipe works. +This should also wait for the subcommand." + (skip-unless (and (executable-find "echo") + (executable-find "cat"))) + (with-temp-eshell + (eshell-match-command-output "echo ${*echo hi | *cat} | *cat" + "hi"))) + +(ert-deftest esh-cmd-test/reset-in-pipeline/subcommand () + "Check that subcommands reset `eshell-in-pipeline-p'." + (skip-unless (executable-find "cat")) + (dolist (template '("echo {%s} | *cat" + "echo ${%s} | *cat" + "*cat $<%s> | *cat")) + (eshell-command-result-equal + (format template "echo $eshell-in-pipeline-p") + nil) + (eshell-command-result-equal + (format template "echo | echo $eshell-in-pipeline-p") + "last") + (eshell-command-result-equal + (format template "echo $eshell-in-pipeline-p | echo") + "first") + (eshell-command-result-equal + (format template "echo | echo $eshell-in-pipeline-p | echo") + "t"))) + +(ert-deftest esh-cmd-test/reset-in-pipeline/lisp () + "Check that interpolated Lisp forms reset `eshell-in-pipeline-p'." + (skip-unless (executable-find "cat")) + (dolist (template '("echo (%s) | *cat" + "echo $(%s) | *cat")) + (eshell-command-result-equal + (format template "format \"%s\" eshell-in-pipeline-p") + "nil"))) + ;; Control flow statements diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el index ce80f3a8f08..0201b6ab650 100644 --- a/test/lisp/eshell/esh-io-tests.el +++ b/test/lisp/eshell/esh-io-tests.el @@ -334,6 +334,17 @@ esh-io-test/pipeline/subcommands (eshell-match-command-output "{echo foo; echo bar} | rev" "\\`raboof\n?"))) +(ert-deftest esh-io-test/pipeline/stdin-to-head () + "Check that standard input is sent to the head process in a pipeline." + (skip-unless (and (executable-find "tr") + (executable-find "rev"))) + (with-temp-eshell + (eshell-insert-command "tr a-z A-Z | rev") + (eshell-insert-command "hello") + (eshell-send-eof-to-process) + (eshell-wait-for-subprocess) + (should (eshell-match-output "OLLEH\n")))) + ;; Virtual targets diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index 46c9482ecf4..777c927c78e 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -38,75 +38,6 @@ eshell-test-value ;;; Tests: -(ert-deftest eshell-test/pipe-headproc () - "Check that piping a non-process to a process command waits for the process" - (skip-unless (executable-find "cat")) - (with-temp-eshell - (eshell-match-command-output "echo hi | *cat" - "hi"))) - -(ert-deftest eshell-test/pipe-tailproc () - "Check that piping a process to a non-process command waits for the process" - (skip-unless (executable-find "echo")) - (with-temp-eshell - (eshell-match-command-output "*echo hi | echo bye" - "bye\nhi\n"))) - -(ert-deftest eshell-test/pipe-headproc-stdin () - "Check that standard input is sent to the head process in a pipeline" - (skip-unless (and (executable-find "tr") - (executable-find "rev"))) - (with-temp-eshell - (eshell-insert-command "tr a-z A-Z | rev") - (eshell-insert-command "hello") - (eshell-send-eof-to-process) - (eshell-wait-for-subprocess) - (should (eshell-match-output "OLLEH\n")))) - -(ert-deftest eshell-test/pipe-subcommand () - "Check that piping with an asynchronous subcommand works" - (skip-unless (and (executable-find "echo") - (executable-find "cat"))) - (with-temp-eshell - (eshell-match-command-output "echo ${*echo hi} | *cat" - "hi"))) - -(ert-deftest eshell-test/pipe-subcommand-with-pipe () - "Check that piping with an asynchronous subcommand with its own pipe works" - (skip-unless (and (executable-find "echo") - (executable-find "cat"))) - (with-temp-eshell - (eshell-match-command-output "echo ${*echo hi | *cat} | *cat" - "hi"))) - -(ert-deftest eshell-test/subcommand-reset-in-pipeline () - "Check that subcommands reset `eshell-in-pipeline-p'." - (skip-unless (executable-find "cat")) - (dolist (template '("echo {%s} | *cat" - "echo ${%s} | *cat" - "*cat $<%s> | *cat")) - (eshell-command-result-equal - (format template "echo $eshell-in-pipeline-p") - nil) - (eshell-command-result-equal - (format template "echo | echo $eshell-in-pipeline-p") - "last") - (eshell-command-result-equal - (format template "echo $eshell-in-pipeline-p | echo") - "first") - (eshell-command-result-equal - (format template "echo | echo $eshell-in-pipeline-p | echo") - "t"))) - -(ert-deftest eshell-test/lisp-reset-in-pipeline () - "Check that interpolated Lisp forms reset `eshell-in-pipeline-p'." - (skip-unless (executable-find "cat")) - (dolist (template '("echo (%s) | *cat" - "echo $(%s) | *cat")) - (eshell-command-result-equal - (format template "format \"%s\" eshell-in-pipeline-p") - "nil"))) - (ert-deftest eshell-test/eshell-command/simple () "Test that the `eshell-command' function writes to the current buffer." (skip-unless (executable-find "echo")) -- 2.25.1