From e51ae63ec28c46f37436f649d6421859c1ad0077 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 3 Jul 2022 20:05:29 -0700 Subject: Improve tests/organization for built-in variables * lisp/eshell/em-dirs.el (eshell-inside-emacs) (eshell-dirs-initialize): Move 'INSIDE_EMACS' from here... * lisp/eshell/esh-var.el (eshell-inside-emacs) (eshell-variable-aliases-alist): ... to here, and improve doc string. * test/lisp/eshell/eshell-tests.el (eshell-test/inside-emacs-var): Move from here... * test/lisp/eshell/esh-var-tests.el (esh-var-test/inside-emacs-var): ... to here. (esh-var-test/last-arg-var-indices) (esh-var-test/last-arg-var-split-indices): New tests. * test/lisp/eshell/em-alias-tests.el: * test/lisp/eshell/em-dirs-tests.el: * test/lisp/eshell-em-script-tests.el: New files. * doc/misc/eshell.texi (Built-ins): Fix 'cd' documentation; it works with the directory ring, not the directory stack. Move built-in variables documentation from here... (Variables): ... to here, and add documentation for missing built-in variables. --- test/lisp/eshell/em-dirs-tests.el | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 test/lisp/eshell/em-dirs-tests.el (limited to 'test/lisp/eshell/em-dirs-tests.el') diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el new file mode 100644 index 00000000000..eb27acd208e --- /dev/null +++ b/test/lisp/eshell/em-dirs-tests.el @@ -0,0 +1,72 @@ +;;; em-dirs-tests.el --- em-dirs test suite -*- lexical-binding:t -*- + +;; Copyright (C) 2022 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 . + +;;; Commentary: + +;; Tests for Eshell's dirs module. + +;;; Code: + +(require 'ert) +(require 'esh-mode) +(require 'eshell) +(require 'em-dirs) + +(require 'eshell-tests-helpers + (expand-file-name "eshell-tests-helpers" + (file-name-directory (or load-file-name + default-directory)))) +;;; Tests: + +(ert-deftest em-dirs-test/pwd-var () + "Test using the $PWD variable." + (should (equal (eshell-test-command-result "echo $PWD") + (expand-file-name (eshell/pwd))))) + +(ert-deftest em-dirs-test/short-pwd-var () + "Test using the $+ (current directory) variable." + (should (equal (eshell-test-command-result "echo $+") + (expand-file-name (eshell/pwd))))) + +(ert-deftest em-dirs-test/oldpwd-var () + "Test using the $OLDPWD variable." + (let (eshell-last-dir-ring-file-name) + (with-temp-eshell + (eshell-command-result-p "echo $OLDPWD" + "\\`\\'") + (ring-insert eshell-last-dir-ring "/some/path") + (eshell-command-result-p "echo $OLDPWD" + "/some/path\n")))) + +(ert-deftest em-dirs-test/directory-ring-var () + "Test using the $- (directory ring) variable." + (let (eshell-last-dir-ring-file-name) + (with-temp-eshell + (eshell-command-result-p "echo $-" + "\\`\\'") + (ring-insert eshell-last-dir-ring "/some/path") + (ring-insert eshell-last-dir-ring "/other/path") + (eshell-command-result-p "echo $-" + "/other/path\n") + (eshell-command-result-p "echo $-[0]" + "/other/path\n") + (eshell-command-result-p "echo $-[1]" + "/some/path\n")))) + +;; em-dirs-tests.el ends here -- cgit v1.2.3 From ba1923f1f1bba69bc13620042a00e315946ba82a Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Fri, 8 Jul 2022 18:41:07 -0700 Subject: Allow Eshell variable aliases to point to other aliases In particular, this resolves an issue where '$+' referenced the real environment variable '$PWD' instead of the Eshell variable alias of the same name. This meant that changing directories in Eshell wouldn't update the value of '$+'. * lisp/eshell/esh-var.el (eshell-get-variable): Allow Eshell variable aliaes to point to other aliases. * test/lisp/eshell/em-dirs-tests.el (em-dirs-test/pwd-var) (em-dirs-test/short-pwd-var): Adapt tests to check this case (bug#56509). --- lisp/eshell/esh-var.el | 41 +++++++++++++++++++-------------------- test/lisp/eshell/em-dirs-tests.el | 10 ++++++---- 2 files changed, 26 insertions(+), 25 deletions(-) (limited to 'test/lisp/eshell/em-dirs-tests.el') diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index 5092d2c6a50..e1535c1c5d5 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -549,27 +549,26 @@ For example, \"[0 1][2]\" becomes: "Get the value for the variable NAME. INDICES is a list of index-lists (see `eshell-parse-indices'). If QUOTED is non-nil, this was invoked inside double-quotes." - (let* ((alias (assoc name eshell-variable-aliases-list)) - (var (if alias - (cadr alias) - name))) - (if (and alias (functionp var)) - (funcall var indices) - (eshell-apply-indices - (cond - ((stringp var) - (let ((sym (intern-soft var))) - (if (and sym (boundp sym) - (or eshell-prefer-lisp-variables - (memq sym eshell--local-vars) ; bug#15372 - (not (getenv var)))) - (symbol-value sym) - (getenv var)))) - ((symbolp var) - (symbol-value var)) - (t - (error "Unknown variable `%s'" (eshell-stringify var)))) - indices quoted)))) + (if-let ((alias (assoc name eshell-variable-aliases-list))) + (let ((target (cadr alias))) + (cond + ((functionp target) + (funcall target indices)) + ((symbolp target) + (eshell-apply-indices (symbol-value target) indices quoted)) + (t + (eshell-get-variable target indices quoted)))) + (unless (stringp name) + (error "Unknown variable `%s'" (eshell-stringify name))) + (eshell-apply-indices + (let ((sym (intern-soft name))) + (if (and sym (boundp sym) + (or eshell-prefer-lisp-variables + (memq sym eshell--local-vars) ; bug#15372 + (not (getenv name)))) + (symbol-value sym) + (getenv name))) + indices quoted))) (defun eshell-apply-indices (value indices &optional quoted) "Apply to VALUE all of the given INDICES, returning the sub-result. diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el index eb27acd208e..69480051e49 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el @@ -36,13 +36,15 @@ (ert-deftest em-dirs-test/pwd-var () "Test using the $PWD variable." - (should (equal (eshell-test-command-result "echo $PWD") - (expand-file-name (eshell/pwd))))) + (let ((default-directory "/some/path")) + (should (equal (eshell-test-command-result "echo $PWD") + (expand-file-name default-directory))))) (ert-deftest em-dirs-test/short-pwd-var () "Test using the $+ (current directory) variable." - (should (equal (eshell-test-command-result "echo $+") - (expand-file-name (eshell/pwd))))) + (let ((default-directory "/some/path")) + (should (equal (eshell-test-command-result "echo $+") + (expand-file-name default-directory))))) (ert-deftest em-dirs-test/oldpwd-var () "Test using the $OLDPWD variable." -- cgit v1.2.3 From 18d83b94528c503f2cd6d0a89f2c5db2d5d48165 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Wed, 6 Jul 2022 21:59:11 -0700 Subject: Ensure Eshell variable aliases properly handle indexing * lisp/eshell/em-dirs.el (eshell-dirs-initialize): Properly handle indexing for variable aliases. * lisp/eshell/esh-var (eshell-variable-aliases-list): Properly handle indexing for variable aliases, and add SIMPLE-FUNCTION entry for aliases. (eshell-get-variable): Update how variable alias functions are called. * test/lisp/eshell/em-alias-tests.el (em-alias-test/alias-arg-vars-indices) (em-alias-test/alias-arg-vars-split-indices) (em-alias-test/alias-all-args-var-split-indices): * test/lisp/eshell/em-dirs-tests.el (em-dirs-test/pwd-var-indices) (em-dirs-test/oldpwd-var-indices) (em-dirs-test/directory-ring-var-indices): * test/lisp/eshell/esh-var-tests.el (esh-var-test/inside-emacs-var-split-indices) (esh-var-test/last-result-var-split-indices): New tests. (esh-var-test/last-arg-var-split-indices): Expand test to check conversion behavior inside double quotes (bug#56509). --- lisp/eshell/em-dirs.el | 36 ++++++++++--------- lisp/eshell/esh-var.el | 73 ++++++++++++++++++++++---------------- test/lisp/eshell/em-alias-tests.el | 23 ++++++++++++ test/lisp/eshell/em-dirs-tests.el | 28 +++++++++++++++ test/lisp/eshell/esh-var-tests.el | 22 ++++++++++-- 5 files changed, 134 insertions(+), 48 deletions(-) (limited to 'test/lisp/eshell/em-dirs-tests.el') diff --git a/lisp/eshell/em-dirs.el b/lisp/eshell/em-dirs.el index a3cf0b91314..00880b9f281 100644 --- a/lisp/eshell/em-dirs.el +++ b/lisp/eshell/em-dirs.el @@ -175,22 +175,26 @@ Thus, this does not include the current directory.") (setq-local eshell-variable-aliases-list (append eshell-variable-aliases-list - `(("-" ,(lambda (indices) - (if (not indices) - (unless (ring-empty-p eshell-last-dir-ring) - (expand-file-name - (ring-ref eshell-last-dir-ring 0))) - (expand-file-name - (eshell-apply-indices eshell-last-dir-ring indices))))) - ("+" "PWD") - ("PWD" ,(lambda (_indices) - (expand-file-name (eshell/pwd))) - t) - ("OLDPWD" ,(lambda (_indices) - (unless (ring-empty-p eshell-last-dir-ring) - (expand-file-name - (ring-ref eshell-last-dir-ring 0)))) - t)))) + `(("-" ,(lambda (indices quoted) + (if (not indices) + (unless (ring-empty-p eshell-last-dir-ring) + (expand-file-name + (ring-ref eshell-last-dir-ring 0))) + ;; Apply the first index, expand the file name, + ;; and then apply the rest of the indices. + (eshell-apply-indices + (expand-file-name + (eshell-apply-indices eshell-last-dir-ring + (list (car indices)) quoted)) + (cdr indices) quoted)))) + ("+" "PWD") + ("PWD" ,(lambda () (expand-file-name (eshell/pwd))) + t t) + ("OLDPWD" ,(lambda () + (unless (ring-empty-p eshell-last-dir-ring) + (expand-file-name + (ring-ref eshell-last-dir-ring 0)))) + t t)))) (when eshell-cd-on-directory (setq-local eshell-interpreter-alist diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index e1535c1c5d5..cbd7942de47 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -152,59 +152,63 @@ if they are quoted with a backslash." (defcustom eshell-variable-aliases-list `(;; for eshell.el - ("COLUMNS" ,(lambda (_indices) (window-body-width nil 'remap)) t) - ("LINES" ,(lambda (_indices) (window-body-height nil 'remap)) t) + ("COLUMNS" ,(lambda () (window-body-width nil 'remap)) t t) + ("LINES" ,(lambda () (window-body-height nil 'remap)) t t) ("INSIDE_EMACS" eshell-inside-emacs t) ;; for eshell-cmd.el - ("_" ,(lambda (indices) + ("_" ,(lambda (indices quoted) (if (not indices) (car (last eshell-last-arguments)) (eshell-apply-indices eshell-last-arguments - indices)))) + indices quoted)))) ("?" eshell-last-command-status) ("$" eshell-last-command-result) ;; for em-alias.el and em-script.el ("0" eshell-command-name) - ("1" ,(lambda (_indices) (nth 0 eshell-command-arguments))) - ("2" ,(lambda (_indices) (nth 1 eshell-command-arguments))) - ("3" ,(lambda (_indices) (nth 2 eshell-command-arguments))) - ("4" ,(lambda (_indices) (nth 3 eshell-command-arguments))) - ("5" ,(lambda (_indices) (nth 4 eshell-command-arguments))) - ("6" ,(lambda (_indices) (nth 5 eshell-command-arguments))) - ("7" ,(lambda (_indices) (nth 6 eshell-command-arguments))) - ("8" ,(lambda (_indices) (nth 7 eshell-command-arguments))) - ("9" ,(lambda (_indices) (nth 8 eshell-command-arguments))) - ("*" ,(lambda (indices) - (if (not indices) - eshell-command-arguments - (eshell-apply-indices eshell-command-arguments - indices))))) + ("1" ,(lambda () (nth 0 eshell-command-arguments)) nil t) + ("2" ,(lambda () (nth 1 eshell-command-arguments)) nil t) + ("3" ,(lambda () (nth 2 eshell-command-arguments)) nil t) + ("4" ,(lambda () (nth 3 eshell-command-arguments)) nil t) + ("5" ,(lambda () (nth 4 eshell-command-arguments)) nil t) + ("6" ,(lambda () (nth 5 eshell-command-arguments)) nil t) + ("7" ,(lambda () (nth 6 eshell-command-arguments)) nil t) + ("8" ,(lambda () (nth 7 eshell-command-arguments)) nil t) + ("9" ,(lambda () (nth 8 eshell-command-arguments)) nil t) + ("*" eshell-command-arguments)) "This list provides aliasing for variable references. -Each member defines the name of a variable, and a Lisp value used to +Each member is of the following form: + + (NAME VALUE [COPY-TO-ENVIRONMENT] [SIMPLE-FUNCTION]) + +NAME defines the name of the variable, VALUE is a Lisp value used to compute the string value that will be returned when the variable is accessed via the syntax `$NAME'. -If the value is a function, call that function with one argument: the -list of the indices that was used in the reference. For example, if +If VALUE is a function, its behavior depends on the value of +SIMPLE-FUNCTION. If SIMPLE-FUNCTION is nil, call VALUE with two +arguments: the list of the indices that was used in the reference and +whether the variable was used within double quotes. For example, if `NAME' were aliased to a function, a reference of `$NAME[10][20]' -would result in that function being called with the argument -`((\"10\") (\"20\"))'. (For more details, see `eshell-apply-indices'). +would result in that function being called with the arguments +`((\"10\") (\"20\"))' and nil. If SIMPLE-FUNCTION is non-nil, call +the function with no arguments and then pass its result to +`eshell-apply-indices'. -If the value is a string, return the value for the variable with that +If VALUE is a string, return the value for the variable with that name in the current environment. If no variable with that name exists in the environment, but if a symbol with that same name exists and has a value bound to it, return its value instead. You can prioritize symbol values over environment values by setting `eshell-prefer-lisp-variables' to t. -If the value is a symbol, return the value bound to it. +If VALUE is a symbol, return the value bound to it. -If the value has any other type, signal an error. +If VALUE has any other type, signal an error. -Additionally, each member may specify if it should be copied to the -environment of created subprocesses." +Additionally, if COPY-TO-ENVIRONMENT is non-nil, the alias should be +copied to the environment of created subprocesses." :type '(repeat (list string sexp (choice (const :tag "Copy to environment" t) (const :tag "Use only in Eshell" nil)))) @@ -550,10 +554,19 @@ For example, \"[0 1][2]\" becomes: INDICES is a list of index-lists (see `eshell-parse-indices'). If QUOTED is non-nil, this was invoked inside double-quotes." (if-let ((alias (assoc name eshell-variable-aliases-list))) - (let ((target (cadr alias))) + (let ((target (nth 1 alias))) (cond ((functionp target) - (funcall target indices)) + (if (nth 3 alias) + (eshell-apply-indices (funcall target) indices quoted) + (condition-case nil + (funcall target indices quoted) + (wrong-number-of-arguments + (display-warning + :warning (concat "Function for `eshell-variable-aliases-list' " + "entry should accept two arguments: INDICES " + "and QUOTED.'")) + (funcall target indices))))) ((symbolp target) (eshell-apply-indices (symbol-value target) indices quoted)) (t diff --git a/test/lisp/eshell/em-alias-tests.el b/test/lisp/eshell/em-alias-tests.el index 762f125a786..497159e3460 100644 --- a/test/lisp/eshell/em-alias-tests.el +++ b/test/lisp/eshell/em-alias-tests.el @@ -47,6 +47,23 @@ (eshell-insert-command "alias show-args 'printnl $0 \"$1 $2\"'") (eshell-command-result-p "show-args one two" "show-args\none two\n"))) +(ert-deftest em-alias-test/alias-arg-vars-indices () + "Test alias with $1, $2, ... variables using indices" + (with-temp-eshell + (eshell-insert-command "alias funny-sum '+ $1[0] $2[1]'") + (eshell-command-result-p "funny-sum (list 1 2) (list 3 4)" + "5\n"))) + +(ert-deftest em-alias-test/alias-arg-vars-split-indices () + "Test alias with $0, $1, ... variables using split indices" + (with-temp-eshell + (eshell-insert-command "alias my-prefix 'echo $0[- 0]'") + (eshell-command-result-p "my-prefix" + "my\n") + (eshell-insert-command "alias funny-sum '+ $1[: 0] $2[: 1]'") + (eshell-command-result-p "funny-sum 1:2 3:4" + "5\n"))) + (ert-deftest em-alias-test/alias-all-args-var () "Test alias with the $* variable" (with-temp-eshell @@ -61,4 +78,10 @@ (eshell-insert-command "alias add-pair '+ $*[0] $*[1]'") (eshell-command-result-p "add-pair 1 2" "3\n"))) +(ert-deftest em-alias-test/alias-all-args-var-split-indices () + "Test alias with the $* variable using split indices" + (with-temp-eshell + (eshell-insert-command "alias add-funny-pair '+ $*[0][: 0] $*[1][: 1]'") + (eshell-command-result-p "add-funny-pair 1:2 3:4" "5\n"))) + ;; em-alias-tests.el ends here diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el index 69480051e49..8e96cc07471 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el @@ -40,6 +40,14 @@ (should (equal (eshell-test-command-result "echo $PWD") (expand-file-name default-directory))))) +(ert-deftest em-dirs-test/pwd-var-indices () + "Test using the $PWD variable with indices." + (let ((default-directory "/some/path/here")) + (should (equal (eshell-test-command-result "echo $PWD[/ 1]") + "some")) + (should (equal (eshell-test-command-result "echo $PWD[/ 1 3]") + '("some" "here"))))) + (ert-deftest em-dirs-test/short-pwd-var () "Test using the $+ (current directory) variable." (let ((default-directory "/some/path")) @@ -56,6 +64,16 @@ (eshell-command-result-p "echo $OLDPWD" "/some/path\n")))) +(ert-deftest em-dirs-test/oldpwd-var-indices () + "Test using the $OLDPWD variable with indices." + (let (eshell-last-dir-ring-file-name) + (with-temp-eshell + (ring-insert eshell-last-dir-ring "/some/path/here") + (eshell-command-result-p "echo $OLDPWD[/ 1]" + "some\n") + (eshell-command-result-p "echo $OLDPWD[/ 1 3]" + "(\"some\" \"here\")\n")))) + (ert-deftest em-dirs-test/directory-ring-var () "Test using the $- (directory ring) variable." (let (eshell-last-dir-ring-file-name) @@ -71,4 +89,14 @@ (eshell-command-result-p "echo $-[1]" "/some/path\n")))) +(ert-deftest em-dirs-test/directory-ring-var-indices () + "Test using the $- (directory ring) variable with multiple indices." + (let (eshell-last-dir-ring-file-name) + (with-temp-eshell + (ring-insert eshell-last-dir-ring "/some/path/here") + (eshell-command-result-p "echo $-[0][/ 1]" + "some\n") + (eshell-command-result-p "echo $-[1][/ 1 3]" + "(\"some\" \"here\")\n")))) + ;; em-dirs-tests.el ends here diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index 955190aee0b..54e701a6aab 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el @@ -494,6 +494,12 @@ inside double-quotes" (format "INSIDE_EMACS=%s,eshell" emacs-version)))) +(ert-deftest esh-var-test/inside-emacs-var-split-indices () + "Test using \"INSIDE_EMACS\" with split indices" + (with-temp-eshell + (eshell-command-result-p "echo $INSIDE_EMACS[, 1]" + "eshell"))) + (ert-deftest esh-var-test/last-result-var () "Test using the \"last result\" ($$) variable" (with-temp-eshell @@ -506,6 +512,16 @@ inside double-quotes" (eshell-command-result-p "+ 1 2; + $$ $$" "3\n6\n"))) +(ert-deftest esh-var-test/last-result-var-split-indices () + "Test using the \"last result\" ($$) variable with split indices" + (with-temp-eshell + (eshell-command-result-p + "string-join (list \"01\" \"02\") :; + $$[: 1] 3" + "01:02\n5\n") + (eshell-command-result-p + "string-join (list \"01\" \"02\") :; echo \"$$[: 1]\"" + "01:02\n02\n"))) + (ert-deftest esh-var-test/last-arg-var () "Test using the \"last arg\" ($_) variable" (with-temp-eshell @@ -523,7 +539,9 @@ inside double-quotes" (ert-deftest esh-var-test/last-arg-var-split-indices () "Test using the \"last arg\" ($_) variable with split indices" (with-temp-eshell - (eshell-command-result-p "concat 01:02 03:04; echo $_[0][: 1]" - "01:0203:04\n2\n"))) + (eshell-command-result-p "concat 01:02 03:04; + $_[0][: 1] 5" + "01:0203:04\n7\n") + (eshell-command-result-p "concat 01:02 03:04; echo \"$_[0][: 1]\"" + "01:0203:04\n02\n"))) ;; esh-var-tests.el ends here -- cgit v1.2.3 From 07b8fb197a3057a3419be0335236547e4d7a326b Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sat, 13 Aug 2022 20:31:11 -0700 Subject: Provide ERT explainer for 'eshell-match-command-output' This was formerly named 'eshell-command-result-p', but "result" isn't quite the right terminology, since this function specifically tested the output of a command, not its Lisp result (as 'eshell-command-result' would return). * test/lisp/eshell/eshell-tests-helpers.el (eshell-insert-command): Provide a more-complete docstring. (eshell-match-result): Rename to... (eshell-match-output): ... this. (eshell-match-output--explainer): New function. (eshell-command-result-p): Rename to... (eshell-match-command-output): ... this. * test/lisp/eshell/em-alias-tests.el * test/lisp/eshell/em-dirs-tests.el * test/lisp/eshell/em-extpipe-tests.el * test/lisp/eshell/em-script-tests.el * test/lisp/eshell/esh-cmd-tests.el * test/lisp/eshell/esh-proc-tests.el * test/lisp/eshell/esh-var-tests.el * test/lisp/eshell/eshell-tests-helpers.el * test/lisp/eshell/eshell-tests.el: Use 'eshell-match-command-output'. --- test/lisp/eshell/em-alias-tests.el | 28 +++---- test/lisp/eshell/em-dirs-tests.el | 40 +++++----- test/lisp/eshell/em-extpipe-tests.el | 18 ++--- test/lisp/eshell/em-script-tests.el | 20 ++--- test/lisp/eshell/esh-cmd-tests.el | 128 ++++++++++++++++--------------- test/lisp/eshell/esh-proc-tests.el | 4 +- test/lisp/eshell/esh-var-tests.el | 110 +++++++++++++------------- test/lisp/eshell/eshell-tests-helpers.el | 38 +++++---- test/lisp/eshell/eshell-tests.el | 44 +++++------ 9 files changed, 222 insertions(+), 208 deletions(-) (limited to 'test/lisp/eshell/em-dirs-tests.el') diff --git a/test/lisp/eshell/em-alias-tests.el b/test/lisp/eshell/em-alias-tests.el index 497159e3460..aca622220e3 100644 --- a/test/lisp/eshell/em-alias-tests.el +++ b/test/lisp/eshell/em-alias-tests.el @@ -38,50 +38,50 @@ "Test a simple alias with no arguments" (with-temp-eshell (eshell-insert-command "alias say-hi 'echo hi'") - (eshell-command-result-p "say-hi" "hi\n") - (eshell-command-result-p "say-hi bye" "hi\n"))) + (eshell-match-command-output "say-hi" "hi\n") + (eshell-match-command-output "say-hi bye" "hi\n"))) (ert-deftest em-alias-test/alias-arg-vars () "Test alias with $0, $1, ... variables" (with-temp-eshell (eshell-insert-command "alias show-args 'printnl $0 \"$1 $2\"'") - (eshell-command-result-p "show-args one two" "show-args\none two\n"))) + (eshell-match-command-output "show-args one two" "show-args\none two\n"))) (ert-deftest em-alias-test/alias-arg-vars-indices () "Test alias with $1, $2, ... variables using indices" (with-temp-eshell (eshell-insert-command "alias funny-sum '+ $1[0] $2[1]'") - (eshell-command-result-p "funny-sum (list 1 2) (list 3 4)" - "5\n"))) + (eshell-match-command-output "funny-sum (list 1 2) (list 3 4)" + "5\n"))) (ert-deftest em-alias-test/alias-arg-vars-split-indices () "Test alias with $0, $1, ... variables using split indices" (with-temp-eshell (eshell-insert-command "alias my-prefix 'echo $0[- 0]'") - (eshell-command-result-p "my-prefix" - "my\n") + (eshell-match-command-output "my-prefix" + "my\n") (eshell-insert-command "alias funny-sum '+ $1[: 0] $2[: 1]'") - (eshell-command-result-p "funny-sum 1:2 3:4" - "5\n"))) + (eshell-match-command-output "funny-sum 1:2 3:4" + "5\n"))) (ert-deftest em-alias-test/alias-all-args-var () "Test alias with the $* variable" (with-temp-eshell (eshell-insert-command "alias show-all-args 'printnl $*'") - (eshell-command-result-p "show-all-args" "\\`\\'") - (eshell-command-result-p "show-all-args a" "a\n") - (eshell-command-result-p "show-all-args a b c" "a\nb\nc\n"))) + (eshell-match-command-output "show-all-args" "\\`\\'") + (eshell-match-command-output "show-all-args a" "a\n") + (eshell-match-command-output "show-all-args a b c" "a\nb\nc\n"))) (ert-deftest em-alias-test/alias-all-args-var-indices () "Test alias with the $* variable using indices" (with-temp-eshell (eshell-insert-command "alias add-pair '+ $*[0] $*[1]'") - (eshell-command-result-p "add-pair 1 2" "3\n"))) + (eshell-match-command-output "add-pair 1 2" "3\n"))) (ert-deftest em-alias-test/alias-all-args-var-split-indices () "Test alias with the $* variable using split indices" (with-temp-eshell (eshell-insert-command "alias add-funny-pair '+ $*[0][: 0] $*[1][: 1]'") - (eshell-command-result-p "add-funny-pair 1:2 3:4" "5\n"))) + (eshell-match-command-output "add-funny-pair 1:2 3:4" "5\n"))) ;; em-alias-tests.el ends here diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el index 8e96cc07471..9e44ef98512 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el @@ -58,45 +58,45 @@ "Test using the $OLDPWD variable." (let (eshell-last-dir-ring-file-name) (with-temp-eshell - (eshell-command-result-p "echo $OLDPWD" - "\\`\\'") + (eshell-match-command-output "echo $OLDPWD" + "\\`\\'") (ring-insert eshell-last-dir-ring "/some/path") - (eshell-command-result-p "echo $OLDPWD" - "/some/path\n")))) + (eshell-match-command-output "echo $OLDPWD" + "/some/path\n")))) (ert-deftest em-dirs-test/oldpwd-var-indices () "Test using the $OLDPWD variable with indices." (let (eshell-last-dir-ring-file-name) (with-temp-eshell (ring-insert eshell-last-dir-ring "/some/path/here") - (eshell-command-result-p "echo $OLDPWD[/ 1]" - "some\n") - (eshell-command-result-p "echo $OLDPWD[/ 1 3]" - "(\"some\" \"here\")\n")))) + (eshell-match-command-output "echo $OLDPWD[/ 1]" + "some\n") + (eshell-match-command-output "echo $OLDPWD[/ 1 3]" + "(\"some\" \"here\")\n")))) (ert-deftest em-dirs-test/directory-ring-var () "Test using the $- (directory ring) variable." (let (eshell-last-dir-ring-file-name) (with-temp-eshell - (eshell-command-result-p "echo $-" - "\\`\\'") + (eshell-match-command-output "echo $-" + "\\`\\'") (ring-insert eshell-last-dir-ring "/some/path") (ring-insert eshell-last-dir-ring "/other/path") - (eshell-command-result-p "echo $-" - "/other/path\n") - (eshell-command-result-p "echo $-[0]" - "/other/path\n") - (eshell-command-result-p "echo $-[1]" - "/some/path\n")))) + (eshell-match-command-output "echo $-" + "/other/path\n") + (eshell-match-command-output "echo $-[0]" + "/other/path\n") + (eshell-match-command-output "echo $-[1]" + "/some/path\n")))) (ert-deftest em-dirs-test/directory-ring-var-indices () "Test using the $- (directory ring) variable with multiple indices." (let (eshell-last-dir-ring-file-name) (with-temp-eshell (ring-insert eshell-last-dir-ring "/some/path/here") - (eshell-command-result-p "echo $-[0][/ 1]" - "some\n") - (eshell-command-result-p "echo $-[1][/ 1 3]" - "(\"some\" \"here\")\n")))) + (eshell-match-command-output "echo $-[0][/ 1]" + "some\n") + (eshell-match-command-output "echo $-[1][/ 1 3]" + "(\"some\" \"here\")\n")))) ;; em-dirs-tests.el ends here diff --git a/test/lisp/eshell/em-extpipe-tests.el b/test/lisp/eshell/em-extpipe-tests.el index 29f5dc05512..04e78279427 100644 --- a/test/lisp/eshell/em-extpipe-tests.el +++ b/test/lisp/eshell/em-extpipe-tests.el @@ -80,7 +80,7 @@ (should-parse '(eshell-named-command "sh" (list "-c" "echo \"bar\" | rev >temp"))) (with-substitute-for-temp - (eshell-command-result-p input "^$") + (eshell-match-command-output input "^$") (temp-should-string= "rab"))) (em-extpipe-tests--deftest em-extpipe-test-2 @@ -91,7 +91,7 @@ '((eshell-named-command "echo" (list (eshell-escape-arg "bar"))) (eshell-named-command "sh" (list "-c" "rev >temp"))))) (with-substitute-for-temp - (eshell-command-result-p input "^$") + (eshell-match-command-output input "^$") (temp-should-string= "rab"))) (em-extpipe-tests--deftest em-extpipe-test-3 "foo *| bar | baz -d" @@ -111,7 +111,7 @@ (eshell-named-command "sh" (list "-c" "echo \"bar\" | rev")))) (with-substitute-for-temp - (eshell-command-result-p input "^$") + (eshell-match-command-output input "^$") (temp-buffer-should-string= "rab"))) (em-extpipe-tests--deftest em-extpipe-test-5 @@ -177,7 +177,7 @@ (should-parse '(eshell-named-command "sh" (list "-c" "tac 3" "Test logical && operator." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "[ foo = foo ] && echo hi" - "hi\n") - (eshell-command-result-p "[ foo = bar ] && echo hi" - "\\`\\'"))) + (eshell-match-command-output "[ foo = foo ] && echo hi" + "hi\n") + (eshell-match-command-output "[ foo = bar ] && echo hi" + "\\`\\'"))) (ert-deftest esh-cmd-test/or-operator () "Test logical || operator." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "[ foo = foo ] || echo hi" - "\\`\\'") - (eshell-command-result-p "[ foo = bar ] || echo hi" - "hi\n"))) + (eshell-match-command-output "[ foo = foo ] || echo hi" + "\\`\\'") + (eshell-match-command-output "[ foo = bar ] || echo hi" + "hi\n"))) ;; Control flow statements @@ -100,20 +100,20 @@ e.g. \"{(+ 1 2)} 3\" => 3" (ert-deftest esh-cmd-test/for-loop () "Test invocation of a for loop." (with-temp-eshell - (eshell-command-result-p "for i in 5 { echo $i }" - "5\n"))) + (eshell-match-command-output "for i in 5 { echo $i }" + "5\n"))) (ert-deftest esh-cmd-test/for-loop-list () "Test invocation of a for loop iterating over a list." (with-temp-eshell - (eshell-command-result-p "for i in (list 1 2 (list 3 4)) { echo $i }" - "1\n2\n(3 4)\n"))) + (eshell-match-command-output "for i in (list 1 2 (list 3 4)) { echo $i }" + "1\n2\n(3 4)\n"))) (ert-deftest esh-cmd-test/for-loop-multiple-args () "Test invocation of a for loop iterating over multiple arguments." (with-temp-eshell - (eshell-command-result-p "for i in 1 2 (list 3 4) { echo $i }" - "1\n2\n3\n4\n"))) + (eshell-match-command-output "for i in 1 2 (list 3 4) { echo $i }" + "1\n2\n3\n4\n"))) (ert-deftest esh-cmd-test/for-name-loop () ; bug#15231 "Test invocation of a for loop using `name'." @@ -126,7 +126,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of a for loop using an env-var." (let ((process-environment (cons "name=env-value" process-environment))) (with-temp-eshell - (eshell-command-result-p + (eshell-match-command-output "echo $name; for name in 3 { echo $name }; echo $name" "env-value\n3\nenv-value\n")))) @@ -134,7 +134,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of a while loop." (with-temp-eshell (let ((eshell-test-value '(0 1 2))) - (eshell-command-result-p + (eshell-match-command-output (concat "while $eshell-test-value " "{ setq eshell-test-value (cdr eshell-test-value) }") "(1 2)\n(2)\n")))) @@ -143,7 +143,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of a while loop using a Lisp form." (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "while (/= eshell-test-value 3) " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -153,7 +153,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" (skip-unless (executable-find "[")) (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "while {[ $eshell-test-value -ne 3 ]} " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -162,7 +162,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of an until loop." (with-temp-eshell (let ((eshell-test-value nil)) - (eshell-command-result-p + (eshell-match-command-output (concat "until $eshell-test-value " "{ setq eshell-test-value t }") "t\n")))) @@ -172,7 +172,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" (skip-unless (executable-find "[")) (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "until (= eshell-test-value 3) " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -182,7 +182,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" (skip-unless (executable-find "[")) (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "until {[ $eshell-test-value -eq 3 ]} " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -191,93 +191,95 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of an if statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "if $eshell-test-value {echo yes}" - "yes\n")) + (eshell-match-command-output "if $eshell-test-value {echo yes}" + "yes\n")) (let ((eshell-test-value nil)) - (eshell-command-result-p "if $eshell-test-value {echo yes}" - "\\`\\'")))) + (eshell-match-command-output "if $eshell-test-value {echo yes}" + "\\`\\'")))) (ert-deftest esh-cmd-test/if-else-statement () "Test invocation of an if/else statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "if $eshell-test-value {echo yes} {echo no}" - "yes\n")) + (eshell-match-command-output "if $eshell-test-value {echo yes} {echo no}" + "yes\n")) (let ((eshell-test-value nil)) - (eshell-command-result-p "if $eshell-test-value {echo yes} {echo no}" - "no\n")))) + (eshell-match-command-output "if $eshell-test-value {echo yes} {echo no}" + "no\n")))) (ert-deftest esh-cmd-test/if-else-statement-lisp-form () "Test invocation of an if/else statement using a Lisp form." (with-temp-eshell - (eshell-command-result-p "if (zerop 0) {echo yes} {echo no}" - "yes\n") - (eshell-command-result-p "if (zerop 1) {echo yes} {echo no}" - "no\n") + (eshell-match-command-output "if (zerop 0) {echo yes} {echo no}" + "yes\n") + (eshell-match-command-output "if (zerop 1) {echo yes} {echo no}" + "no\n") (let ((debug-on-error nil)) - (eshell-command-result-p "if (zerop \"foo\") {echo yes} {echo no}" - "no\n")))) + (eshell-match-command-output "if (zerop \"foo\") {echo yes} {echo no}" + "no\n")))) (ert-deftest esh-cmd-test/if-else-statement-lisp-form-2 () "Test invocation of an if/else statement using a Lisp form. This tests when `eshell-lisp-form-nil-is-failure' is nil." (let ((eshell-lisp-form-nil-is-failure nil)) (with-temp-eshell - (eshell-command-result-p "if (zerop 0) {echo yes} {echo no}" - "yes\n") - (eshell-command-result-p "if (zerop 1) {echo yes} {echo no}" - "yes\n") + (eshell-match-command-output "if (zerop 0) {echo yes} {echo no}" + "yes\n") + (eshell-match-command-output "if (zerop 1) {echo yes} {echo no}" + "yes\n") (let ((debug-on-error nil)) - (eshell-command-result-p "if (zerop \"foo\") {echo yes} {echo no}" - "no\n"))))) + (eshell-match-command-output "if (zerop \"foo\") {echo yes} {echo no}" + "no\n"))))) (ert-deftest esh-cmd-test/if-else-statement-ext-cmd () "Test invocation of an if/else statement using an external command." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "if {[ foo = foo ]} {echo yes} {echo no}" - "yes\n") - (eshell-command-result-p "if {[ foo = bar ]} {echo yes} {echo no}" - "no\n"))) + (eshell-match-command-output "if {[ foo = foo ]} {echo yes} {echo no}" + "yes\n") + (eshell-match-command-output "if {[ foo = bar ]} {echo yes} {echo no}" + "no\n"))) (ert-deftest esh-cmd-test/unless-statement () "Test invocation of an unless statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "unless $eshell-test-value {echo no}" - "\\`\\'")) + (eshell-match-command-output "unless $eshell-test-value {echo no}" + "\\`\\'")) (let ((eshell-test-value nil)) - (eshell-command-result-p "unless $eshell-test-value {echo no}" - "no\n")))) + (eshell-match-command-output "unless $eshell-test-value {echo no}" + "no\n")))) (ert-deftest esh-cmd-test/unless-else-statement () "Test invocation of an unless/else statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "unless $eshell-test-value {echo no} {echo yes}" - "yes\n")) + (eshell-match-command-output + "unless $eshell-test-value {echo no} {echo yes}" + "yes\n")) (let ((eshell-test-value nil)) - (eshell-command-result-p "unless $eshell-test-value {echo no} {echo yes}" - "no\n")))) + (eshell-match-command-output + "unless $eshell-test-value {echo no} {echo yes}" + "no\n")))) (ert-deftest esh-cmd-test/unless-else-statement-lisp-form () "Test invocation of an unless/else statement using a Lisp form." (with-temp-eshell - (eshell-command-result-p "unless (zerop 0) {echo no} {echo yes}" - "yes\n") - (eshell-command-result-p "unless (zerop 1) {echo no} {echo yes}" - "no\n") + (eshell-match-command-output "unless (zerop 0) {echo no} {echo yes}" + "yes\n") + (eshell-match-command-output "unless (zerop 1) {echo no} {echo yes}" + "no\n") (let ((debug-on-error nil)) - (eshell-command-result-p "unless (zerop \"foo\") {echo no} {echo yes}" - "no\n")))) + (eshell-match-command-output "unless (zerop \"foo\") {echo no} {echo yes}" + "no\n")))) (ert-deftest esh-cmd-test/unless-else-statement-ext-cmd () "Test invocation of an unless/else statement using an external command." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "unless {[ foo = foo ]} {echo no} {echo yes}" - "yes\n") - (eshell-command-result-p "unless {[ foo = bar ]} {echo no} {echo yes}" - "no\n"))) + (eshell-match-command-output "unless {[ foo = foo ]} {echo no} {echo yes}" + "yes\n") + (eshell-match-command-output "unless {[ foo = bar ]} {echo no} {echo yes}" + "no\n"))) ;; esh-cmd-tests.el ends here diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el index 734bb91a6a5..f538e8c43a0 100644 --- a/test/lisp/eshell/esh-proc-tests.el +++ b/test/lisp/eshell/esh-proc-tests.el @@ -43,7 +43,7 @@ (executable-find "echo") (executable-find "sleep"))) (with-temp-eshell - (eshell-command-result-p + (eshell-match-command-output ;; The first command is like `yes' but slower. This is to prevent ;; it from taxing Emacs's process filter too much and causing a ;; hang. @@ -136,4 +136,4 @@ prompt. See bug#54136." (kill-process (caar eshell-process-list)) ;; Give `eshell-sentinel' a chance to run. (sit-for 0.1) - (eshell-match-result "\\[sh\\(\\.exe\\)?\\] [[:digit:]]+\n"))) + (should (eshell-match-output "\\[sh\\(\\.exe\\)?\\] [[:digit:]]+\n")))) diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index 0c094ee5a79..ca74ad1959d 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el @@ -153,15 +153,15 @@ "Interpolate command result from external command" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "echo ${*echo hi}" - "hi\n"))) + (eshell-match-command-output "echo ${*echo hi}" + "hi\n"))) (ert-deftest esh-var-test/interp-cmd-external-indices () "Interpolate command result from external command with index" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "echo ${*echo \"hi\nbye\"}[1]" - "bye\n"))) + (eshell-match-command-output "echo ${*echo \"hi\nbye\"}[1]" + "bye\n"))) (ert-deftest esh-var-test/interp-temp-cmd () "Interpolate command result redirected to temp file" @@ -196,8 +196,8 @@ "Interpolate command result from external command with concatenation" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "echo ${echo hi}-${*echo there}" - "hi-there\n"))) + (eshell-match-command-output "echo ${echo hi}-${*echo there}" + "hi-there\n"))) (ert-deftest esh-var-test/quoted-interp-var () "Interpolate variable inside double-quotes" @@ -490,72 +490,72 @@ inside double-quotes" (ert-deftest esh-var-test/inside-emacs-var () "Test presence of \"INSIDE_EMACS\" in subprocesses" (with-temp-eshell - (eshell-command-result-p "env" - (format "INSIDE_EMACS=%s,eshell" - emacs-version)))) + (eshell-match-command-output "env" + (format "INSIDE_EMACS=%s,eshell" + emacs-version)))) (ert-deftest esh-var-test/inside-emacs-var-split-indices () "Test using \"INSIDE_EMACS\" with split indices" (with-temp-eshell - (eshell-command-result-p "echo $INSIDE_EMACS[, 1]" - "eshell"))) + (eshell-match-command-output "echo $INSIDE_EMACS[, 1]" + "eshell"))) (ert-deftest esh-var-test/last-status-var-lisp-command () "Test using the \"last exit status\" ($?) variable with a Lisp command" (with-temp-eshell - (eshell-command-result-p "zerop 0; echo $?" - "t\n0\n") - (eshell-command-result-p "zerop 1; echo $?" - "0\n") + (eshell-match-command-output "zerop 0; echo $?" + "t\n0\n") + (eshell-match-command-output "zerop 1; echo $?" + "0\n") (let ((debug-on-error nil)) - (eshell-command-result-p "zerop foo; echo $?" - "1\n")))) + (eshell-match-command-output "zerop foo; echo $?" + "1\n")))) (ert-deftest esh-var-test/last-status-var-lisp-form () "Test using the \"last exit status\" ($?) variable with a Lisp form" (let ((eshell-lisp-form-nil-is-failure t)) - (with-temp-eshell - (eshell-command-result-p "(zerop 0); echo $?" - "t\n0\n") - (eshell-command-result-p "(zerop 1); echo $?" - "2\n") - (let ((debug-on-error nil)) - (eshell-command-result-p "(zerop \"foo\"); echo $?" - "1\n"))))) + (with-temp-eshell + (eshell-match-command-output "(zerop 0); echo $?" + "t\n0\n") + (eshell-match-command-output "(zerop 1); echo $?" + "2\n") + (let ((debug-on-error nil)) + (eshell-match-command-output "(zerop \"foo\"); echo $?" + "1\n"))))) (ert-deftest esh-var-test/last-status-var-lisp-form-2 () "Test using the \"last exit status\" ($?) variable with a Lisp form. This tests when `eshell-lisp-form-nil-is-failure' is nil." (let ((eshell-lisp-form-nil-is-failure nil)) (with-temp-eshell - (eshell-command-result-p "(zerop 0); echo $?" - "0\n") - (eshell-command-result-p "(zerop 0); echo $?" - "0\n") + (eshell-match-command-output "(zerop 0); echo $?" + "0\n") + (eshell-match-command-output "(zerop 0); echo $?" + "0\n") (let ((debug-on-error nil)) - (eshell-command-result-p "(zerop \"foo\"); echo $?" - "1\n"))))) + (eshell-match-command-output "(zerop \"foo\"); echo $?" + "1\n"))))) (ert-deftest esh-var-test/last-status-var-ext-cmd () "Test using the \"last exit status\" ($?) variable with an external command" (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "[ foo = foo ]; echo $?" - "0\n") - (eshell-command-result-p "[ foo = bar ]; echo $?" - "1\n"))) + (eshell-match-command-output "[ foo = foo ]; echo $?" + "0\n") + (eshell-match-command-output "[ foo = bar ]; echo $?" + "1\n"))) (ert-deftest esh-var-test/last-result-var () "Test using the \"last result\" ($$) variable" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $$ 2" - "3\n5\n"))) + (eshell-match-command-output "+ 1 2; + $$ 2" + "3\n5\n"))) (ert-deftest esh-var-test/last-result-var-twice () "Test using the \"last result\" ($$) variable twice" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $$ $$" - "3\n6\n"))) + (eshell-match-command-output "+ 1 2; + $$ $$" + "3\n6\n"))) (ert-deftest esh-var-test/last-result-var-ext-cmd () "Test using the \"last result\" ($$) variable with an external command" @@ -564,41 +564,41 @@ This tests when `eshell-lisp-form-nil-is-failure' is nil." ;; MS-DOS/MS-Windows have an external command 'format', which we ;; don't want here. (let ((eshell-prefer-lisp-functions t)) - (eshell-command-result-p "[ foo = foo ]; format \"%s\" $$" - "t\n") - (eshell-command-result-p "[ foo = bar ]; format \"%s\" $$" - "nil\n")))) + (eshell-match-command-output "[ foo = foo ]; format \"%s\" $$" + "t\n") + (eshell-match-command-output "[ foo = bar ]; format \"%s\" $$" + "nil\n")))) (ert-deftest esh-var-test/last-result-var-split-indices () "Test using the \"last result\" ($$) variable with split indices" (with-temp-eshell - (eshell-command-result-p + (eshell-match-command-output "string-join (list \"01\" \"02\") :; + $$[: 1] 3" "01:02\n5\n") - (eshell-command-result-p + (eshell-match-command-output "string-join (list \"01\" \"02\") :; echo \"$$[: 1]\"" "01:02\n02\n"))) (ert-deftest esh-var-test/last-arg-var () "Test using the \"last arg\" ($_) variable" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $_ 4" - "3\n6\n"))) + (eshell-match-command-output "+ 1 2; + $_ 4" + "3\n6\n"))) (ert-deftest esh-var-test/last-arg-var-indices () "Test using the \"last arg\" ($_) variable with indices" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $_[0] 4" - "3\n5\n") - (eshell-command-result-p "+ 1 2; + $_[1] 4" - "3\n6\n"))) + (eshell-match-command-output "+ 1 2; + $_[0] 4" + "3\n5\n") + (eshell-match-command-output "+ 1 2; + $_[1] 4" + "3\n6\n"))) (ert-deftest esh-var-test/last-arg-var-split-indices () "Test using the \"last arg\" ($_) variable with split indices" (with-temp-eshell - (eshell-command-result-p "concat 01:02 03:04; + $_[0][: 1] 5" - "01:0203:04\n7\n") - (eshell-command-result-p "concat 01:02 03:04; echo \"$_[0][: 1]\"" - "01:0203:04\n02\n"))) + (eshell-match-command-output "concat 01:02 03:04; + $_[0][: 1] 5" + "01:0203:04\n7\n") + (eshell-match-command-output "concat 01:02 03:04; echo \"$_[0][: 1]\"" + "01:0203:04\n02\n"))) ;; esh-var-tests.el ends here diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el index 4ad76ca6978..778087bd755 100644 --- a/test/lisp/eshell/eshell-tests-helpers.el +++ b/test/lisp/eshell/eshell-tests-helpers.el @@ -65,24 +65,36 @@ raise an error." (error "timed out waiting for subprocess(es)")) (sit-for 0.1)))) -(defun eshell-insert-command (text &optional func) - "Insert a command at the end of the buffer." +(defun eshell-insert-command (command &optional func) + "Insert a COMMAND at the end of the buffer. +After inserting, call FUNC. If FUNC is nil, instead call +`eshell-send-input'." (goto-char eshell-last-output-end) - (insert-and-inherit text) + (insert-and-inherit command) (funcall (or func 'eshell-send-input))) -(defun eshell-match-result (regexp) - "Check that output of last command matches REGEXP." - (should - (string-match-p +(defun eshell-match-output (regexp) + "Test whether the output of the last command matches REGEXP." + (string-match-p regexp (buffer-substring-no-properties - (eshell-beginning-of-output) (eshell-end-of-output))))) - -(defun eshell-command-result-p (text regexp &optional func) - "Insert a command at the end of the buffer." - (eshell-insert-command text func) + (eshell-beginning-of-output) (eshell-end-of-output)))) + +(defun eshell-match-output--explainer (regexp) + "Explain the result of `eshell-match-output'." + `(mismatched-output + (command ,(buffer-substring-no-properties + eshell-last-input-start eshell-last-input-end)) + (output ,(buffer-substring-no-properties + (eshell-beginning-of-output) (eshell-end-of-output))) + (regexp ,regexp))) + +(put 'eshell-match-output 'ert-explainer #'eshell-match-output--explainer) + +(defun eshell-match-command-output (command regexp &optional func) + "Insert a COMMAND at the end of the buffer and match the output with REGEXP." + (eshell-insert-command command func) (eshell-wait-for-subprocess) - (eshell-match-result regexp)) + (should (eshell-match-output regexp))) (defvar eshell-history-file-name) diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index 8423500ea7d..c7a9516bea4 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -40,15 +40,15 @@ "Check that piping a non-process to a process command waits for the process" (skip-unless (executable-find "cat")) (with-temp-eshell - (eshell-command-result-p "echo hi | *cat" - "hi"))) + (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-command-result-p "*echo hi | echo bye" - "bye\nhi\n"))) + (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" @@ -59,23 +59,23 @@ (eshell-insert-command "hello") (eshell-send-eof-to-process) (eshell-wait-for-subprocess) - (eshell-match-result "OLLEH\n"))) + (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-command-result-p "echo ${*echo hi} | *cat" - "hi"))) + (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-command-result-p "echo ${*echo hi | *cat} | *cat" - "hi"))) + (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'." @@ -129,32 +129,32 @@ "Test that \"\\c\" and \"c\" are equivalent when \"c\" is not a special character." (with-temp-eshell - (eshell-command-result-p "echo he\\llo" - "hello\n"))) + (eshell-match-command-output "echo he\\llo" + "hello\n"))) (ert-deftest eshell-test/escape-nonspecial-unicode () "Test that \"\\c\" and \"c\" are equivalent when \"c\" is a unicode character (unicode characters are nonspecial by definition)." (with-temp-eshell - (eshell-command-result-p "echo Vid\\éos" - "Vidéos\n"))) + (eshell-match-command-output "echo Vid\\éos" + "Vidéos\n"))) (ert-deftest eshell-test/escape-nonspecial-quoted () "Test that the backslash is preserved for escaped nonspecial chars" (with-temp-eshell - (eshell-command-result-p "echo \"h\\i\"" - ;; Backslashes are doubled for regexp. - "h\\\\i\n"))) + (eshell-match-command-output "echo \"h\\i\"" + ;; Backslashes are doubled for regexp. + "h\\\\i\n"))) (ert-deftest eshell-test/escape-special-quoted () "Test that the backslash is not preserved for escaped special chars" (with-temp-eshell - (eshell-command-result-p "echo \"\\\"hi\\\\\"" - ;; Backslashes are doubled for regexp. - "\\\"hi\\\\\n"))) + (eshell-match-command-output "echo \"\\\"hi\\\\\"" + ;; Backslashes are doubled for regexp. + "\\\"hi\\\\\n"))) (ert-deftest eshell-test/command-running-p () "Modeline should show no command running" @@ -188,15 +188,15 @@ chars" (> count 0)) (sit-for 1) (setq count (1- count)))) - (eshell-match-result "alpha\n"))) + (should (eshell-match-output "alpha\n")))) (ert-deftest eshell-test/flush-output () "Test flushing of previous output" (with-temp-eshell (eshell-insert-command "echo alpha") (eshell-kill-output) - (eshell-match-result - (concat "^" (regexp-quote "*** output flushed ***\n") "$")))) + (should (eshell-match-output + (concat "^" (regexp-quote "*** output flushed ***\n") "$"))))) (ert-deftest eshell-test/run-old-command () "Re-run an old command" -- cgit v1.2.3 From c1f1be4b73072440518f02356998cf58ba127ebd Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 14 Aug 2022 13:44:04 -0700 Subject: Add 'eshell-command-result-equal' with an ERT explainer * test/lisp/eshell/eshell-tests-helpers.el (eshell-command-result--equal, eshell-command-result--equal-explainer) (eshell-command-result-equal): New functions. * test/lisp/eshell/em-basic-tests.el * test/lisp/eshell/em-dirs-tests.el * test/lisp/eshell/esh-cmd-tests.el * test/lisp/eshell/esh-proc-tests.el * test/lisp/eshell/esh-var-tests.el * test/lisp/eshell/eshell-tests.el: Use 'eshell-command-result-equal'. --- test/lisp/eshell/em-basic-tests.el | 18 +- test/lisp/eshell/em-dirs-tests.el | 16 +- test/lisp/eshell/esh-cmd-tests.el | 19 +- test/lisp/eshell/esh-proc-tests.el | 31 +-- test/lisp/eshell/esh-var-tests.el | 391 ++++++++++++++----------------- test/lisp/eshell/eshell-tests-helpers.el | 21 ++ test/lisp/eshell/eshell-tests.el | 31 ++- 7 files changed, 254 insertions(+), 273 deletions(-) (limited to 'test/lisp/eshell/em-dirs-tests.el') diff --git a/test/lisp/eshell/em-basic-tests.el b/test/lisp/eshell/em-basic-tests.el index 7a24f8b46c3..bc8baeaa035 100644 --- a/test/lisp/eshell/em-basic-tests.el +++ b/test/lisp/eshell/em-basic-tests.el @@ -36,25 +36,25 @@ (ert-deftest em-basic-test/umask-print-numeric () "Test printing umask numerically." (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) - (should (equal (eshell-test-command-result "umask") "002\n"))) + (eshell-command-result-equal "umask" "002\n")) (cl-letf (((symbol-function 'default-file-modes) (lambda () #o654))) - (should (equal (eshell-test-command-result "umask") "123\n"))) + (eshell-command-result-equal "umask" "123\n")) ;; Make sure larger numbers don't cause problems. (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775))) - (should (equal (eshell-test-command-result "umask") "002\n")))) + (eshell-command-result-equal "umask" "002\n"))) (ert-deftest em-basic-test/umask-read-symbolic () "Test printing umask symbolically." (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) - (should (equal (eshell-test-command-result "umask -S") - "u=rwx,g=rwx,o=rx\n"))) + (eshell-command-result-equal "umask -S" + "u=rwx,g=rwx,o=rx\n")) (cl-letf (((symbol-function 'default-file-modes) (lambda () #o654))) - (should (equal (eshell-test-command-result "umask -S") - "u=wx,g=rx,o=x\n"))) + (eshell-command-result-equal "umask -S" + "u=wx,g=rx,o=x\n")) ;; Make sure larger numbers don't cause problems. (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775))) - (should (equal (eshell-test-command-result "umask -S") - "u=rwx,g=rwx,o=rx\n")))) + (eshell-command-result-equal "umask -S" + "u=rwx,g=rwx,o=rx\n"))) (ert-deftest em-basic-test/umask-set () "Test setting umask." diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el index 9e44ef98512..f72d708dcae 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el @@ -37,22 +37,22 @@ (ert-deftest em-dirs-test/pwd-var () "Test using the $PWD variable." (let ((default-directory "/some/path")) - (should (equal (eshell-test-command-result "echo $PWD") - (expand-file-name default-directory))))) + (eshell-command-result-equal "echo $PWD" + (expand-file-name default-directory)))) (ert-deftest em-dirs-test/pwd-var-indices () "Test using the $PWD variable with indices." (let ((default-directory "/some/path/here")) - (should (equal (eshell-test-command-result "echo $PWD[/ 1]") - "some")) - (should (equal (eshell-test-command-result "echo $PWD[/ 1 3]") - '("some" "here"))))) + (eshell-command-result-equal "echo $PWD[/ 1]" + "some") + (eshell-command-result-equal "echo $PWD[/ 1 3]" + '("some" "here")))) (ert-deftest em-dirs-test/short-pwd-var () "Test using the $+ (current directory) variable." (let ((default-directory "/some/path")) - (should (equal (eshell-test-command-result "echo $+") - (expand-file-name default-directory))))) + (eshell-command-result-equal "echo $+" + (expand-file-name default-directory)))) (ert-deftest em-dirs-test/oldpwd-var () "Test using the $OLDPWD variable." diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el index 05635e8a7b5..c5d780a399d 100644 --- a/test/lisp/eshell/esh-cmd-tests.el +++ b/test/lisp/eshell/esh-cmd-tests.el @@ -41,37 +41,37 @@ (ert-deftest esh-cmd-test/simple-command-result () "Test invocation with a simple command." - (should (equal (eshell-test-command-result "+ 1 2") 3))) + (eshell-command-result-equal "+ 1 2" 3)) (ert-deftest esh-cmd-test/lisp-command () "Test invocation with an elisp command." - (should (equal (eshell-test-command-result "(+ 1 2)") 3))) + (eshell-command-result-equal "(+ 1 2)" 3)) (ert-deftest esh-cmd-test/lisp-command-with-quote () "Test invocation with an elisp command containing a quote." - (should (equal (eshell-test-command-result "(eq 'foo nil)") nil))) + (eshell-command-result-equal "(eq 'foo nil)" nil)) (ert-deftest esh-cmd-test/lisp-command-args () "Test invocation with elisp and trailing args. Test that trailing arguments outside the S-expression are ignored. e.g. \"(+ 1 2) 3\" => 3" - (should (equal (eshell-test-command-result "(+ 1 2) 3") 3))) + (eshell-command-result-equal "(+ 1 2) 3" 3)) (ert-deftest esh-cmd-test/subcommand () "Test invocation with a simple subcommand." - (should (equal (eshell-test-command-result "{+ 1 2}") 3))) + (eshell-command-result-equal "{+ 1 2}" 3)) (ert-deftest esh-cmd-test/subcommand-args () "Test invocation with a subcommand and trailing args. Test that trailing arguments outside the subcommand are ignored. e.g. \"{+ 1 2} 3\" => 3" - (should (equal (eshell-test-command-result "{+ 1 2} 3") 3))) + (eshell-command-result-equal "{+ 1 2} 3" 3)) (ert-deftest esh-cmd-test/subcommand-lisp () "Test invocation with an elisp subcommand and trailing args. Test that trailing arguments outside the subcommand are ignored. e.g. \"{(+ 1 2)} 3\" => 3" - (should (equal (eshell-test-command-result "{(+ 1 2)} 3") 3))) + (eshell-command-result-equal "{(+ 1 2)} 3" 3)) ;; Logical operators @@ -118,9 +118,8 @@ e.g. \"{(+ 1 2)} 3\" => 3" (ert-deftest esh-cmd-test/for-name-loop () ; bug#15231 "Test invocation of a for loop using `name'." (let ((process-environment (cons "name" process-environment))) - (should (equal (eshell-test-command-result - "for name in 3 { echo $name }") - 3)))) + (eshell-command-result-equal "for name in 3 { echo $name }" + 3))) (ert-deftest esh-cmd-test/for-name-shadow-loop () ; bug#15372 "Test invocation of a for loop using an env-var." diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el index f538e8c43a0..2369bb5cc00 100644 --- a/test/lisp/eshell/esh-proc-tests.el +++ b/test/lisp/eshell/esh-proc-tests.el @@ -56,36 +56,37 @@ (ert-deftest esh-proc-test/pipeline-connection-type/no-pipeline () "Test that all streams are PTYs when a command is not in a pipeline." (skip-unless (executable-find "sh")) - (should (equal (eshell-test-command-result esh-proc-test--detect-pty-cmd) - ;; PTYs aren't supported on MS-Windows. - (unless (eq system-type 'windows-nt) - "stdin\nstdout\nstderr\n")))) + (eshell-command-result-equal + esh-proc-test--detect-pty-cmd + ;; PTYs aren't supported on MS-Windows. + (unless (eq system-type 'windows-nt) + "stdin\nstdout\nstderr\n"))) (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"))) - (should (equal (eshell-test-command-result - (concat esh-proc-test--detect-pty-cmd " | cat")) - (unless (eq system-type 'windows-nt) - "stdin\n")))) + (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"))) - (should (equal (eshell-test-command-result - (concat "echo | " esh-proc-test--detect-pty-cmd " | cat")) - nil))) + (eshell-command-result-equal + (concat "echo | " 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")) - (should (equal (eshell-test-command-result - (concat "echo | " esh-proc-test--detect-pty-cmd)) - (unless (eq system-type 'windows-nt) - "stdout\nstderr\n")))) + (eshell-command-result-equal + (concat "echo | " esh-proc-test--detect-pty-cmd) + (unless (eq system-type 'windows-nt) + "stdout\nstderr\n"))) (ert-deftest esh-proc-test/kill-pipeline () "Test that killing a pipeline of processes only emits a single diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index ca74ad1959d..bebc57d3592 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el @@ -41,113 +41,107 @@ (ert-deftest esh-var-test/interp-var () "Interpolate variable" - (should (equal (eshell-test-command-result "echo $user-login-name") - user-login-name))) + (eshell-command-result-equal "echo $user-login-name" + user-login-name)) (ert-deftest esh-var-test/interp-quoted-var () "Interpolate quoted variable" - (should (equal (eshell-test-command-result "echo $'user-login-name'") - user-login-name)) - (should (equal (eshell-test-command-result "echo $\"user-login-name\"") - user-login-name))) + (eshell-command-result-equal "echo $'user-login-name'" + user-login-name) + (eshell-command-result-equal "echo $\"user-login-name\"" + user-login-name)) (ert-deftest esh-var-test/interp-quoted-var-concat () "Interpolate and concat quoted variable" - (should (equal (eshell-test-command-result "echo $'user-login-name'-foo") - (concat user-login-name "-foo"))) - (should (equal (eshell-test-command-result "echo $\"user-login-name\"-foo") - (concat user-login-name "-foo")))) + (eshell-command-result-equal "echo $'user-login-name'-foo" + (concat user-login-name "-foo")) + (eshell-command-result-equal "echo $\"user-login-name\"-foo" + (concat user-login-name "-foo"))) (ert-deftest esh-var-test/interp-var-indices () "Interpolate list variable with indices" (let ((eshell-test-value '("zero" "one" "two" "three" "four"))) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0]") - "zero")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]") - '("zero" "two"))) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2 4]") - '("zero" "two" "four"))))) + (eshell-command-result-equal "echo $eshell-test-value[0]" + "zero") + (eshell-command-result-equal "echo $eshell-test-value[0 2]" + '("zero" "two")) + (eshell-command-result-equal "echo $eshell-test-value[0 2 4]" + '("zero" "two" "four")))) (ert-deftest esh-var-test/interp-var-split-indices () "Interpolate string variable with indices" (let ((eshell-test-value "zero one two three four")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0]") - "zero")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]") - '("zero" "two"))) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2 4]") - '("zero" "two" "four"))))) + (eshell-command-result-equal "echo $eshell-test-value[0]" + "zero") + (eshell-command-result-equal "echo $eshell-test-value[0 2]" + '("zero" "two")) + (eshell-command-result-equal "echo $eshell-test-value[0 2 4]" + '("zero" "two" "four")))) (ert-deftest esh-var-test/interp-var-string-split-indices () "Interpolate string variable with string splitter and indices" (let ((eshell-test-value "zero:one:two:three:four")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0]") - "zero")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0 2]") - '("zero" "two")))) + (eshell-command-result-equal "echo $eshell-test-value[: 0]" + "zero") + (eshell-command-result-equal "echo $eshell-test-value[: 0 2]" + '("zero" "two"))) (let ((eshell-test-value "zeroXoneXtwoXthreeXfour")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[X 0]") - "zero")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[X 0 2]") - '("zero" "two"))))) + (eshell-command-result-equal "echo $eshell-test-value[X 0]" + "zero") + (eshell-command-result-equal "echo $eshell-test-value[X 0 2]" + '("zero" "two")))) (ert-deftest esh-var-test/interp-var-regexp-split-indices () "Interpolate string variable with regexp splitter and indices" (let ((eshell-test-value "zero:one!two:three!four")) - (should (equal (eshell-test-command-result - "echo $eshell-test-value['[:!]' 0]") - "zero")) - (should (equal (eshell-test-command-result - "echo $eshell-test-value['[:!]' 0 2]") - '("zero" "two"))) - (should (equal (eshell-test-command-result - "echo $eshell-test-value[\"[:!]\" 0]") - "zero")) - (should (equal (eshell-test-command-result - "echo $eshell-test-value[\"[:!]\" 0 2]") - '("zero" "two"))))) + (eshell-command-result-equal "echo $eshell-test-value['[:!]' 0]" + "zero") + (eshell-command-result-equal "echo $eshell-test-value['[:!]' 0 2]" + '("zero" "two")) + (eshell-command-result-equal "echo $eshell-test-value[\"[:!]\" 0]" + "zero") + (eshell-command-result-equal "echo $eshell-test-value[\"[:!]\" 0 2]" + '("zero" "two")))) (ert-deftest esh-var-test/interp-var-assoc () "Interpolate alist variable with index" (let ((eshell-test-value '(("foo" . 1)))) - (should (eq (eshell-test-command-result "echo $eshell-test-value[foo]") - 1)))) + (eshell-command-result-equal "echo $eshell-test-value[foo]" + 1))) (ert-deftest esh-var-test/interp-var-length-list () "Interpolate length of list variable" (let ((eshell-test-value '((1 2) (3) (5 (6 7 8 9))))) - (should (eq (eshell-test-command-result "echo $#eshell-test-value") 3)) - (should (eq (eshell-test-command-result "echo $#eshell-test-value[1]") 1)) - (should (eq (eshell-test-command-result "echo $#eshell-test-value[2][1]") - 4)))) + (eshell-command-result-equal "echo $#eshell-test-value" 3) + (eshell-command-result-equal "echo $#eshell-test-value[1]" 1) + (eshell-command-result-equal "echo $#eshell-test-value[2][1]" 4))) (ert-deftest esh-var-test/interp-var-length-string () "Interpolate length of string variable" (let ((eshell-test-value "foobar")) - (should (eq (eshell-test-command-result "echo $#eshell-test-value") 6)))) + (eshell-command-result-equal "echo $#eshell-test-value" 6))) (ert-deftest esh-var-test/interp-var-length-alist () "Interpolate length of alist variable" (let ((eshell-test-value '(("foo" . (1 2 3))))) - (should (eq (eshell-test-command-result "echo $#eshell-test-value") 1)) - (should (eq (eshell-test-command-result "echo $#eshell-test-value[foo]") - 3)))) + (eshell-command-result-equal "echo $#eshell-test-value" 1) + (eshell-command-result-equal "echo $#eshell-test-value[foo]" 3))) (ert-deftest esh-var-test/interp-lisp () "Interpolate Lisp form evaluation" - (should (equal (eshell-test-command-result "+ $(+ 1 2) 3") 6))) + (eshell-command-result-equal "+ $(+ 1 2) 3" 6)) (ert-deftest esh-var-test/interp-lisp-indices () "Interpolate Lisp form evaluation with index" - (should (equal (eshell-test-command-result "+ $(list 1 2)[1] 3") 5))) + (eshell-command-result-equal "+ $(list 1 2)[1] 3" 5)) (ert-deftest esh-var-test/interp-cmd () "Interpolate command result" - (should (equal (eshell-test-command-result "+ ${+ 1 2} 3") 6))) + (eshell-command-result-equal "+ ${+ 1 2} 3" 6)) (ert-deftest esh-var-test/interp-cmd-indices () "Interpolate command result with index" - (should (equal (eshell-test-command-result "+ ${listify 1 2}[1] 3") 5))) + (eshell-command-result-equal "+ ${listify 1 2}[1] 3" 5)) (ert-deftest esh-var-test/interp-cmd-external () "Interpolate command result from external command" @@ -165,32 +159,32 @@ (ert-deftest esh-var-test/interp-temp-cmd () "Interpolate command result redirected to temp file" - (should (equal (eshell-test-command-result "cat $") "hi"))) + (eshell-command-result-equal "cat $" "hi")) (ert-deftest esh-var-test/interp-concat-lisp () "Interpolate and concat Lisp form" - (should (equal (eshell-test-command-result "+ $(+ 1 2)3 3") 36))) + (eshell-command-result-equal "+ $(+ 1 2)3 3" 36)) (ert-deftest esh-var-test/interp-concat-lisp2 () "Interpolate and concat two Lisp forms" - (should (equal (eshell-test-command-result "+ $(+ 1 2)$(+ 1 2) 3") 36))) + (eshell-command-result-equal "+ $(+ 1 2)$(+ 1 2) 3" 36)) (ert-deftest esh-var-test/interp-concat-cmd () "Interpolate and concat command with literal" - (should (equal (eshell-test-command-result "+ ${+ 1 2}3 3") 36)) - (should (equal (eshell-test-command-result "echo ${*echo \"foo\nbar\"}-baz") - '("foo" "bar-baz"))) + (eshell-command-result-equal "+ ${+ 1 2}3 3" 36) + (eshell-command-result-equal "echo ${*echo \"foo\nbar\"}-baz" + '("foo" "bar-baz")) ;; Concatenating to a number in a list should produce a number... - (should (equal (eshell-test-command-result "echo ${*echo \"1\n2\"}3") - '(1 23))) + (eshell-command-result-equal "echo ${*echo \"1\n2\"}3" + '(1 23)) ;; ... but concatenating to a string that looks like a number in a list ;; should produce a string. - (should (equal (eshell-test-command-result "echo ${*echo \"hi\n2\"}3") - '("hi" "23")))) + (eshell-command-result-equal "echo ${*echo \"hi\n2\"}3" + '("hi" "23"))) (ert-deftest esh-var-test/interp-concat-cmd2 () "Interpolate and concat two commands" - (should (equal (eshell-test-command-result "+ ${+ 1 2}${+ 1 2} 3") 36))) + (eshell-command-result-equal "+ ${+ 1 2}${+ 1 2} 3" 36)) (ert-deftest esh-var-test/interp-concat-cmd-external () "Interpolate command result from external command with concatenation" @@ -201,151 +195,128 @@ (ert-deftest esh-var-test/quoted-interp-var () "Interpolate variable inside double-quotes" - (should (equal (eshell-test-command-result "echo \"$user-login-name\"") - user-login-name))) + (eshell-command-result-equal "echo \"$user-login-name\"" + user-login-name)) (ert-deftest esh-var-test/quoted-interp-quoted-var () "Interpolate quoted variable inside double-quotes" - (should (equal (eshell-test-command-result - "echo \"hi, $'user-login-name'\"") - (concat "hi, " user-login-name))) - (should (equal (eshell-test-command-result - "echo \"hi, $\\\"user-login-name\\\"\"") - (concat "hi, " user-login-name)))) + (eshell-command-result-equal "echo \"hi, $'user-login-name'\"" + (concat "hi, " user-login-name)) + (eshell-command-result-equal "echo \"hi, $\\\"user-login-name\\\"\"" + (concat "hi, " user-login-name))) (ert-deftest esh-var-test/quoted-interp-var-indices () "Interpolate string variable with indices inside double-quotes" (let ((eshell-test-value '("zero" "one" "two" "three" "four"))) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0]\"") - "zero")) + (eshell-command-result-equal "echo \"$eshell-test-value[0]\"" + "zero") ;; FIXME: These tests would use the 0th index like the other tests ;; here, but evaluating the command just above adds an `escaped' ;; property to the string "zero". This results in the output ;; printing the string properties, which is probably the wrong ;; behavior. See bug#54486. - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[1 2]\"") - "(\"one\" \"two\")")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[1 2 4]\"") - "(\"one\" \"two\" \"four\")")))) + (eshell-command-result-equal "echo \"$eshell-test-value[1 2]\"" + "(\"one\" \"two\")") + (eshell-command-result-equal "echo \"$eshell-test-value[1 2 4]\"" + "(\"one\" \"two\" \"four\")"))) (ert-deftest esh-var-test/quoted-interp-var-split-indices () "Interpolate string variable with indices inside double-quotes" (let ((eshell-test-value "zero one two three four")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0]\"") - "zero")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0 2]\"") - "(\"zero\" \"two\")")))) + (eshell-command-result-equal "echo \"$eshell-test-value[0]\"" + "zero") + (eshell-command-result-equal "echo \"$eshell-test-value[0 2]\"" + "(\"zero\" \"two\")"))) (ert-deftest esh-var-test/quoted-interp-var-string-split-indices () "Interpolate string variable with string splitter and indices inside double-quotes" (let ((eshell-test-value "zero:one:two:three:four")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[: 0]\"") - "zero")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[: 0 2]\"") - "(\"zero\" \"two\")"))) + (eshell-command-result-equal "echo \"$eshell-test-value[: 0]\"" + "zero") + (eshell-command-result-equal "echo \"$eshell-test-value[: 0 2]\"" + "(\"zero\" \"two\")")) (let ((eshell-test-value "zeroXoneXtwoXthreeXfour")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[X 0]\"") - "zero")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[X 0 2]\"") - "(\"zero\" \"two\")")))) + (eshell-command-result-equal "echo \"$eshell-test-value[X 0]\"" + "zero") + (eshell-command-result-equal "echo \"$eshell-test-value[X 0 2]\"" + "(\"zero\" \"two\")"))) (ert-deftest esh-var-test/quoted-interp-var-regexp-split-indices () "Interpolate string variable with regexp splitter and indices" (let ((eshell-test-value "zero:one!two:three!four")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value['[:!]' 0]\"") - "zero")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value['[:!]' 0 2]\"") - "(\"zero\" \"two\")")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[\\\"[:!]\\\" 0]\"") - "zero")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[\\\"[:!]\\\" 0 2]\"") - "(\"zero\" \"two\")")))) + (eshell-command-result-equal "echo \"$eshell-test-value['[:!]' 0]\"" + "zero") + (eshell-command-result-equal "echo \"$eshell-test-value['[:!]' 0 2]\"" + "(\"zero\" \"two\")") + (eshell-command-result-equal "echo \"$eshell-test-value[\\\"[:!]\\\" 0]\"" + "zero") + (eshell-command-result-equal + "echo \"$eshell-test-value[\\\"[:!]\\\" 0 2]\"" + "(\"zero\" \"two\")"))) (ert-deftest esh-var-test/quoted-interp-var-assoc () "Interpolate alist variable with index inside double-quotes" (let ((eshell-test-value '(("foo" . 1)))) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[foo]\"") - "1")))) + (eshell-command-result-equal "echo \"$eshell-test-value[foo]\"" + "1"))) (ert-deftest esh-var-test/quoted-interp-var-length-list () "Interpolate length of list variable inside double-quotes" (let ((eshell-test-value '((1 2) (3) (5 (6 7 8 9))))) - (should (equal (eshell-test-command-result "echo \"$#eshell-test-value\"") - "3")) - (should (equal (eshell-test-command-result - "echo \"$#eshell-test-value[1]\"") - "1")) - (should (equal (eshell-test-command-result - "echo \"$#eshell-test-value[2][1]\"") - "4")))) + (eshell-command-result-equal "echo \"$#eshell-test-value\"" + "3") + (eshell-command-result-equal "echo \"$#eshell-test-value[1]\"" + "1") + (eshell-command-result-equal "echo \"$#eshell-test-value[2][1]\"" + "4"))) (ert-deftest esh-var-test/quoted-interp-var-length-string () "Interpolate length of string variable inside double-quotes" (let ((eshell-test-value "foobar")) - (should (equal (eshell-test-command-result "echo \"$#eshell-test-value\"") - "6")))) + (eshell-command-result-equal "echo \"$#eshell-test-value\"" + "6"))) (ert-deftest esh-var-test/quoted-interp-var-length-alist () "Interpolate length of alist variable inside double-quotes" (let ((eshell-test-value '(("foo" . (1 2 3))))) - (should (equal (eshell-test-command-result "echo \"$#eshell-test-value\"") - "1")) - (should (equal (eshell-test-command-result - "echo \"$#eshell-test-value[foo]\"") - "3")))) + (eshell-command-result-equal "echo \"$#eshell-test-value\"" + "1") + (eshell-command-result-equal "echo \"$#eshell-test-value[foo]\"" + "3")) (ert-deftest esh-var-test/quoted-interp-lisp () "Interpolate Lisp form evaluation inside double-quotes" - (should (equal (eshell-test-command-result - "echo \"hi $(concat \\\"the\\\" \\\"re\\\")\"") - "hi there"))) + (eshell-command-result-equal "echo \"hi $(concat \\\"the\\\" \\\"re\\\")\"" + "hi there")) (ert-deftest esh-var-test/quoted-interp-lisp-indices () "Interpolate Lisp form evaluation with index" - (should (equal (eshell-test-command-result "concat \"$(list 1 2)[1]\" cool") - "2cool"))) + (eshell-command-result-equal "concat \"$(list 1 2)[1]\" cool" + "2cool")) (ert-deftest esh-var-test/quoted-interp-cmd () "Interpolate command result inside double-quotes" - (should (equal (eshell-test-command-result - "echo \"hi ${echo \\\"there\\\"}\"") - "hi there"))) + (eshell-command-result-equal "echo \"hi ${echo \\\"there\\\"}\"" + "hi there")) (ert-deftest esh-var-test/quoted-interp-cmd-indices () "Interpolate command result with index inside double-quotes" - (should (equal (eshell-test-command-result - "concat \"${listify 1 2}[1]\" cool") - "2cool"))) + (eshell-command-result-equal "concat \"${listify 1 2}[1]\" cool" + "2cool")) (ert-deftest esh-var-test/quoted-interp-temp-cmd () "Interpolate command result redirected to temp file inside double-quotes" (let ((temporary-file-directory (file-name-as-directory (make-temp-file "esh-vars-tests" t)))) (unwind-protect - (should (equal (eshell-test-command-result "cat \"$\"") - "hi")) + (eshell-command-result-equal "cat \"$\"" "hi")) (delete-directory temporary-file-directory t)))) (ert-deftest esh-var-test/quoted-interp-concat-cmd () "Interpolate and concat command with literal" - (should (equal (eshell-test-command-result - "echo \"${echo \\\"foo\nbar\\\"} baz\"") - "foo\nbar baz"))) + (eshell-command-result-equal "echo \"${echo \\\"foo\nbar\\\"} baz\"" + "foo\nbar baz")) ;; Interpolated variable conversion @@ -353,139 +324,129 @@ inside double-quotes" (ert-deftest esh-var-test/interp-convert-var-number () "Interpolate numeric variable" (let ((eshell-test-value 123)) - (should (equal (eshell-test-command-result "type-of $eshell-test-value") - 'integer)))) + (eshell-command-result-equal "type-of $eshell-test-value" + 'integer))) (ert-deftest esh-var-test/interp-convert-var-split-indices () "Interpolate and convert string variable with indices" ;; Check that numeric forms are converted to numbers. (let ((eshell-test-value "000 010 020 030 040")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0]") - 0)) - (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]") - '(0 20)))) + (eshell-command-result-equal "echo $eshell-test-value[0]" + 0) + (eshell-command-result-equal "echo $eshell-test-value[0 2]" + '(0 20))) ;; Check that multiline forms are preserved as-is. (let ((eshell-test-value "foo\nbar:baz\n")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0]") - "foo\nbar")) - (should (equal (eshell-test-command-result "echo $eshell-test-value[: 1]") - "baz\n")))) + (eshell-command-result-equal "echo $eshell-test-value[: 0]" + "foo\nbar") + (eshell-command-result-equal "echo $eshell-test-value[: 1]" + "baz\n"))) (ert-deftest esh-var-test/interp-convert-quoted-var-number () "Interpolate numeric quoted numeric variable" (let ((eshell-test-value 123)) - (should (equal (eshell-test-command-result "type-of $'eshell-test-value'") - 'integer)) - (should (equal (eshell-test-command-result "type-of $\"eshell-test-value\"") - 'integer)))) + (eshell-command-result-equal "type-of $'eshell-test-value'" + 'integer) + (eshell-command-result-equal "type-of $\"eshell-test-value\"" + 'integer))) (ert-deftest esh-var-test/interp-convert-quoted-var-split-indices () "Interpolate and convert quoted string variable with indices" (let ((eshell-test-value "000 010 020 030 040")) - (should (equal (eshell-test-command-result "echo $'eshell-test-value'[0]") - 0)) - (should (equal (eshell-test-command-result "echo $'eshell-test-value'[0 2]") - '(0 20))))) + (eshell-command-result-equal "echo $'eshell-test-value'[0]" + 0) + (eshell-command-result-equal "echo $'eshell-test-value'[0 2]" + '(0 20)))) (ert-deftest esh-var-test/interp-convert-cmd-string-newline () "Interpolate trailing-newline command result" - (should (equal (eshell-test-command-result "echo ${echo \"foo\n\"}") "foo"))) + (eshell-command-result-equal "echo ${echo \"foo\n\"}" "foo")) (ert-deftest esh-var-test/interp-convert-cmd-multiline () "Interpolate multi-line command result" - (should (equal (eshell-test-command-result "echo ${echo \"foo\nbar\"}") - '("foo" "bar"))) + (eshell-command-result-equal "echo ${echo \"foo\nbar\"}" + '("foo" "bar")) ;; Numeric output should be converted to numbers... - (should (equal (eshell-test-command-result "echo ${echo \"01\n02\n03\"}") - '(1 2 3))) + (eshell-command-result-equal "echo ${echo \"01\n02\n03\"}" + '(1 2 3)) ;; ... but only if every line is numeric. - (should (equal (eshell-test-command-result "echo ${echo \"01\n02\nhi\"}") - '("01" "02" "hi")))) + (eshell-command-result-equal "echo ${echo \"01\n02\nhi\"}" + '("01" "02" "hi"))) (ert-deftest esh-var-test/interp-convert-cmd-number () "Interpolate numeric command result" - (should (equal (eshell-test-command-result "echo ${echo \"1\"}") 1))) + (eshell-command-result-equal "echo ${echo \"1\"}" 1)) (ert-deftest esh-var-test/interp-convert-cmd-split-indices () "Interpolate command result with indices" - (should (equal (eshell-test-command-result "echo ${echo \"000 010 020\"}[0]") - 0)) - (should (equal (eshell-test-command-result - "echo ${echo \"000 010 020\"}[0 2]") - '(0 20)))) + (eshell-command-result-equal "echo ${echo \"000 010 020\"}[0]" + 0) + (eshell-command-result-equal "echo ${echo \"000 010 020\"}[0 2]" + '(0 20))) (ert-deftest esh-var-test/quoted-interp-convert-var-number () "Interpolate numeric variable inside double-quotes" (let ((eshell-test-value 123)) - (should (equal (eshell-test-command-result "type-of \"$eshell-test-value\"") - 'string)))) + (eshell-command-result-equal "type-of \"$eshell-test-value\"" + 'string))) (ert-deftest esh-var-test/quoted-interp-convert-var-split-indices () "Interpolate string variable with indices inside double-quotes" (let ((eshell-test-value "000 010 020 030 040")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0]\"") - "000")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0 2]\"") - "(\"000\" \"020\")")))) + (eshell-command-result-equal "echo \"$eshell-test-value[0]\"" + "000") + (eshell-command-result-equal "echo \"$eshell-test-value[0 2]\"" + "(\"000\" \"020\")"))) (ert-deftest esh-var-test/quoted-interp-convert-quoted-var-number () "Interpolate numeric quoted variable inside double-quotes" (let ((eshell-test-value 123)) - (should (equal (eshell-test-command-result - "type-of \"$'eshell-test-value'\"") - 'string)) - (should (equal (eshell-test-command-result - "type-of \"$\\\"eshell-test-value\\\"\"") - 'string)))) + (eshell-command-result-equal "type-of \"$'eshell-test-value'\"" + 'string) + (eshell-command-result-equal "type-of \"$\\\"eshell-test-value\\\"\"" + 'string))) (ert-deftest esh-var-test/quoted-interp-convert-quoted-var-split-indices () "Interpolate quoted string variable with indices inside double-quotes" (let ((eshell-test-value "000 010 020 030 040")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0]\"") - "000")) - (should (equal (eshell-test-command-result - "echo \"$eshell-test-value[0 2]\"") - "(\"000\" \"020\")")))) + (eshell-command-result-equal "echo \"$eshell-test-value[0]\"" + "000") + (eshell-command-result-equal "echo \"$eshell-test-value[0 2]\"" + "(\"000\" \"020\")"))) (ert-deftest esh-var-test/quoted-interp-convert-cmd-string-newline () "Interpolate trailing-newline command result inside double-quotes" - (should (equal (eshell-test-command-result "echo \"${echo \\\"foo\n\\\"}\"") - "foo")) - (should (equal (eshell-test-command-result "echo \"${echo \\\"foo\n\n\\\"}\"") - "foo"))) + (eshell-command-result-equal "echo \"${echo \\\"foo\n\\\"}\"" + "foo") + (eshell-command-result-equal "echo \"${echo \\\"foo\n\n\\\"}\"" + "foo")) (ert-deftest esh-var-test/quoted-interp-convert-cmd-multiline () "Interpolate multi-line command result inside double-quotes" - (should (equal (eshell-test-command-result - "echo \"${echo \\\"foo\nbar\\\"}\"") - "foo\nbar"))) + (eshell-command-result-equal "echo \"${echo \\\"foo\nbar\\\"}\"" + "foo\nbar")) (ert-deftest esh-var-test/quoted-interp-convert-cmd-number () "Interpolate numeric command result inside double-quotes" - (should (equal (eshell-test-command-result "echo \"${echo \\\"1\\\"}\"") - "1"))) + (eshell-command-result-equal "echo \"${echo \\\"1\\\"}\"" "1")) (ert-deftest esh-var-test/quoted-interp-convert-cmd-split-indices () "Interpolate command result with indices inside double-quotes" - (should (equal (eshell-test-command-result - "echo \"${echo \\\"000 010 020\\\"}[0]\"") - "000"))) + (eshell-command-result-equal "echo \"${echo \\\"000 010 020\\\"}[0]\"" + "000")) ;; Built-in variables (ert-deftest esh-var-test/lines-var () "$LINES should equal (window-body-height nil 'remap)" - (should (equal (eshell-test-command-result "echo $LINES") - (window-body-height nil 'remap)))) + (eshell-command-result-equal "echo $LINES" + (window-body-height nil 'remap))) (ert-deftest esh-var-test/columns-var () "$COLUMNS should equal (window-body-width nil 'remap)" - (should (equal (eshell-test-command-result "echo $COLUMNS") - (window-body-width nil 'remap)))) + (eshell-command-result-equal "echo $COLUMNS" + (window-body-width nil 'remap))) (ert-deftest esh-var-test/inside-emacs-var () "Test presence of \"INSIDE_EMACS\" in subprocesses" diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el index 778087bd755..8f0f993447f 100644 --- a/test/lisp/eshell/eshell-tests-helpers.el +++ b/test/lisp/eshell/eshell-tests-helpers.el @@ -104,6 +104,27 @@ After inserting, call FUNC. If FUNC is nil, instead call (let ((eshell-history-file-name nil)) (eshell-command-result command)))) +(defun eshell-command-result--equal (_command actual expected) + "Compare the ACTUAL result of a COMMAND with its EXPECTED value." + (equal actual expected)) + +(defun eshell-command-result--equal-explainer (command actual expected) + "Explain the result of `eshell-command-result--equal'." + `(nonequal-result + (command ,command) + (result ,actual) + (expected ,expected))) + +(put 'eshell-command-result--equal 'ert-explainer + #'eshell-command-result--equal-explainer) + +(defun eshell-command-result-equal (command result) + "Execute COMMAND non-interactively and compare it to RESULT." + (should (eshell-command-result--equal + command + (eshell-test-command-result command) + result))) + (provide 'eshell-tests-helpers) ;;; eshell-tests-helpers.el ends here diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index c7a9516bea4..1845dba2809 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -83,28 +83,27 @@ (dolist (template '("echo {%s} | *cat" "echo ${%s} | *cat" "*cat $<%s> | *cat")) - (should (equal (eshell-test-command-result - (format template "echo $eshell-in-pipeline-p")) - nil)) - (should (equal (eshell-test-command-result - (format template "echo | echo $eshell-in-pipeline-p")) - "last")) - (should (equal (eshell-test-command-result - (format template "echo $eshell-in-pipeline-p | echo")) - "first")) - (should (equal (eshell-test-command-result - (format template - "echo | echo $eshell-in-pipeline-p | echo")) - "t")))) + (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")) - (should (equal (eshell-test-command-result - (format template "format \"%s\" eshell-in-pipeline-p")) - "nil")))) + (eshell-command-result-equal + (format template "format \"%s\" eshell-in-pipeline-p") + "nil"))) (ert-deftest eshell-test/redirect-buffer () "Check that piping to a buffer works" -- cgit v1.2.3