1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00
emacs/test/lisp/eshell/esh-ext-tests.el
Jim Porter cee1cbfd54 Improve handling of $PATH in Eshell for remote directories
* lisp/eshell/esh-util.el (eshell-path-env, eshell-parse-colon-path):
Make obsolete.
(eshell-path-env-list): New variable.
(eshell-connection-default-profile): New connection-local profile.
(eshell-get-path): Reimplement using 'eshell-path-env-list'; add
LITERAL-P argument.
(eshell-set-path): New function.

* lisp/eshell/esh-var.el (eshell-variable-aliases-list): Add entry for
$PATH.
(eshell-var-initialize): Add 'eshell-path-env-list' to
'eshell-subcommand-bindings'.

* lisp/eshell/esh-ext.el (eshell-search-path): Use 'file-name-concat'
instead of 'concat'.
(eshell/addpath): Use 'eshell-get-path' and 'eshell-set-path'.

* lisp/net/tramp-integration.el: Only apply Eshell hooks when
'eshell-path-env-list' is unbound.

* test/lisp/eshell/esh-var-tests.el
(esh-var-test/path-var/local-directory)
(esh-var-test/path-var/remote-directory, esh-var-test/path-var/set)
(esh-var-test/path-var/set-locally)
(esh-var-test/path-var-preserve-across-hosts): New tests.

* test/lisp/eshell/esh-ext-tests.el: New file.

* test/lisp/eshell/eshell-tests-helpers.el
(with-temp-eshell): Set 'eshell-last-dir-ring-file-name' to nil.
(eshell-tests-remote-accessible-p, eshell-last-input)
(eshell-last-output): New functions.
(eshell-match-output, eshell-match-output--explainer): Use
'eshell-last-input' and 'eshell-last-output'.

* doc/misc/eshell.texi (Variables): Document $PATH.

* etc/NEWS: Announce this change (bug#57556).
2022-10-17 18:48:52 -07:00

76 lines
3.1 KiB
EmacsLisp

;;; esh-ext-tests.el --- esh-ext 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Tests for Eshell's external command handling.
;;; Code:
(require 'ert)
(require 'esh-mode)
(require 'esh-ext)
(require 'eshell)
(require 'eshell-tests-helpers
(expand-file-name "eshell-tests-helpers"
(file-name-directory (or load-file-name
default-directory))))
;;; Tests:
(ert-deftest esh-ext-test/addpath/end ()
"Test that \"addpath\" adds paths to the end of $PATH."
(with-temp-eshell
(let ((eshell-path-env-list '("/some/path" "/other/path"))
(expected-path (string-join '("/some/path" "/other/path" "/new/path"
"/new/path2")
(path-separator))))
(eshell-match-command-output "addpath /new/path /new/path2"
(concat expected-path "\n"))
(eshell-match-command-output "echo $PATH"
(concat expected-path "\n")))))
(ert-deftest esh-ext-test/addpath/begin ()
"Test that \"addpath -b\" adds paths to the beginning of $PATH."
(with-temp-eshell
(let ((eshell-path-env-list '("/some/path" "/other/path"))
(expected-path (string-join '("/new/path" "/new/path2" "/some/path"
"/other/path")
(path-separator))))
(eshell-match-command-output "addpath -b /new/path /new/path2"
(concat expected-path "\n"))
(eshell-match-command-output "echo $PATH"
(concat expected-path "\n")))))
(ert-deftest esh-ext-test/addpath/set-locally ()
"Test adding to the path temporarily in a subcommand."
(let* ((eshell-path-env-list '("/some/path" "/other/path"))
(original-path (string-join eshell-path-env-list (path-separator)))
(local-path (string-join (append eshell-path-env-list '("/new/path"))
(path-separator))))
(with-temp-eshell
(eshell-match-command-output
"{ addpath /new/path; env }"
(format "PATH=%s\n" (regexp-quote local-path)))
;; After the last command, the previous $PATH value should be restored.
(eshell-match-command-output "echo $PATH"
(concat original-path "\n")))))
;; esh-ext-tests.el ends here