From d29a79aa895a33f316d352c67e09efaaebec6255 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 9 Jun 2024 10:56:39 +0300 Subject: [PATCH] Fix Eshell tests on MS-Windows * lisp/eshell/esh-util.el (eshell-get-path): Don't add "." if it is already there. * test/lisp/eshell/esh-var-tests.el (esh-var-test/path-var/preserve-across-hosts): Skip on MS-Windows. (esh-var-test/path-var/set, esh-var-test/path-var/set-locally): Quote the PATH value, for MS-Windows. * test/lisp/eshell/esh-util-tests.el (esh-util-test/path/get): No need to add ".": it is already done by 'eshell-get-path'. * test/lisp/eshell/esh-proc-tests.el (esh-proc-test/kill-pipeline): Accept empty string as valid output. (esh-proc-test/sigpipe-exits-process): Skip on MS-Windows: no SIGPIPE. (esh-proc-test/emacs-command): Quote correctly for MS-Windows. * test/lisp/eshell/em-unix-tests.el (em-unix-test/compile/interactive): Fix test on MS-Windows. * test/lisp/eshell/em-script-tests.el (em-script-test/batch-file): Skip on MS-Windows. * test/lisp/eshell/eshell-tests-helpers.el (eshell-command-result--equal): Compare strings (file names) case-insensitively on MS-Windows. (cherry picked from commit f869f1ffc2ef0e126e633553e6b4c38bee90f7f8) --- lisp/eshell/esh-util.el | 3 ++- test/lisp/eshell/em-script-tests.el | 1 + test/lisp/eshell/em-unix-tests.el | 7 ++++++- test/lisp/eshell/esh-proc-tests.el | 23 +++++++++++++++++------ test/lisp/eshell/esh-util-tests.el | 5 +---- test/lisp/eshell/esh-var-tests.el | 6 ++++-- test/lisp/eshell/eshell-tests-helpers.el | 7 ++++++- 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 85e30e23cec..1504d89731d 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -417,7 +417,8 @@ as the $PATH was actually specified." (butlast (exec-path)))))) (when (and (not literal-p) (not remote) - (eshell-under-windows-p)) + (eshell-under-windows-p) + (not (member "." path))) (push "." path)) (if (and remote (not literal-p)) (mapcar (lambda (x) (concat remote x)) path) diff --git a/test/lisp/eshell/em-script-tests.el b/test/lisp/eshell/em-script-tests.el index f3adbae9df7..94afe775a3b 100644 --- a/test/lisp/eshell/em-script-tests.el +++ b/test/lisp/eshell/em-script-tests.el @@ -115,6 +115,7 @@ (ert-deftest em-script-test/batch-file () "Test running an Eshell script file as a batch script." + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (ert-with-temp-file temp-file :text (format "#!/usr/bin/env -S %s --batch -f eshell-batch-file\necho hi" diff --git a/test/lisp/eshell/em-unix-tests.el b/test/lisp/eshell/em-unix-tests.el index 2ee42c81333..7312fb831cd 100644 --- a/test/lisp/eshell/em-unix-tests.el +++ b/test/lisp/eshell/em-unix-tests.el @@ -43,7 +43,12 @@ "#") (with-current-buffer "*compilation*" (forward-line 3) - (should (looking-at "echo hello"))))) + (should (looking-at + ;; MS-Windows/DOS quote by unconditionally enclosing in + ;; double quotes. + (if (memq system-type '(windows-nt ms-dos)) + "\"echo\" \"hello\"" + "echo hello")))))) (ert-deftest em-unix-test/compile/noninteractive () "Check that `eshell/compile' writes to stdout noninteractively." diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el index 63fb8f46dfa..cf869edbe0c 100644 --- a/test/lisp/eshell/esh-proc-tests.el +++ b/test/lisp/eshell/esh-proc-tests.el @@ -136,7 +136,8 @@ "Test that a SIGPIPE is properly sent to a process if a pipe closes" (skip-unless (and (executable-find "sh") (executable-find "echo") - (executable-find "sleep"))) + (executable-find "sleep") + (not (eq system-type 'windows-nt)))) (let ((starting-process-list (process-list))) (with-temp-eshell (eshell-match-command-output @@ -197,10 +198,20 @@ pipeline." (defsubst esh-proc-test/emacs-command (command) "Evaluate COMMAND in a new Emacs batch instance." - (mapconcat #'shell-quote-argument - `(,(expand-file-name invocation-name invocation-directory) - "-Q" "--batch" "--eval" ,(prin1-to-string command)) - " ")) + (if (eq system-type 'windows-nt) + ;; The MS-Windows implementation of shell-quote-argument is too + ;; much for arguments that already have quotes, so we quote "by + ;; hand" here. + (concat (shell-quote-argument + (expand-file-name invocation-name invocation-directory)) + " -Q --batch --eval " + "\"" + (string-replace "\"" "\\\"" (prin1-to-string command)) + "\"") + (mapconcat #'shell-quote-argument + `(,(expand-file-name invocation-name invocation-directory) + "-Q" "--batch" "--eval" ,(prin1-to-string command)) + " "))) (defvar esh-proc-test/emacs-echo (esh-proc-test/emacs-command '(princ "hello\n")) @@ -286,7 +297,7 @@ prompt. See bug#54136." (eshell-wait-for-subprocess t) (should (string-match-p ;; "interrupt\n" is for MS-Windows. - (rx (or "interrupt\n" "killed\n" "killed: 9\n")) + (rx (or "interrupt\n" "killed\n" "killed: 9\n" "")) (buffer-substring-no-properties output-start (eshell-end-of-output))))))) diff --git a/test/lisp/eshell/esh-util-tests.el b/test/lisp/eshell/esh-util-tests.el index 71a047b1801..031de558d1f 100644 --- a/test/lisp/eshell/esh-util-tests.el +++ b/test/lisp/eshell/esh-util-tests.el @@ -165,10 +165,7 @@ (ert-deftest esh-util-test/path/get () "Test that getting the Eshell path returns the expected results." (let ((expected-path (butlast (exec-path)))) - (should (equal (eshell-get-path) - (if (eshell-under-windows-p) - (cons "." expected-path) - expected-path))) + (should (equal (eshell-get-path) expected-path)) (should (equal (eshell-get-path 'literal) expected-path)))) diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index 1b46b214e77..8b2f882f37e 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el @@ -855,7 +855,8 @@ the value of the $PAGER env var." (let* ((path-to-set-list '("/some/path" "/other/path")) (path-to-set (string-join path-to-set-list (path-separator)))) (with-temp-eshell - (eshell-match-command-output (concat "set PATH " path-to-set) + ;; Quote PATH value, because on Windows path-separator is ';'. + (eshell-match-command-output (concat "set PATH \"" path-to-set "\"") (concat path-to-set "\n")) (eshell-match-command-output "echo $PATH" (concat path-to-set "\n")) (should (equal (eshell-get-path t) path-to-set-list))))) @@ -865,7 +866,7 @@ the value of the $PAGER env var." (let* ((path-to-set-list '("/some/path" "/other/path")) (path-to-set (string-join path-to-set-list (path-separator)))) (with-temp-eshell - (eshell-match-command-output (concat "set PATH " path-to-set) + (eshell-match-command-output (concat "set PATH \"" path-to-set "\"") (concat path-to-set "\n")) (eshell-match-command-output "PATH=/local/path env" "PATH=/local/path\n") @@ -875,6 +876,7 @@ the value of the $PAGER env var." (ert-deftest esh-var-test/path-var/preserve-across-hosts () "Test that $PATH can be set independently on multiple hosts." + (skip-unless (not (eq system-type 'windows-nt))) (let ((local-directory default-directory) local-path remote-path) (with-temp-eshell diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el index bfd829c95e9..acbe57a7283 100644 --- a/test/lisp/eshell/eshell-tests-helpers.el +++ b/test/lisp/eshell/eshell-tests-helpers.el @@ -179,7 +179,12 @@ inserting the command." (defun eshell-command-result--equal (_command actual expected) "Compare the ACTUAL result of a COMMAND with its EXPECTED value." - (equal actual expected)) + (or (equal actual expected) + ;; Compare case-isensitively on case-insensitive filesystems. + (and (memq system-type '(windows-nt ms-dos)) + (stringp actual) + (stringp expected) + (string-equal-ignore-case actual expected)))) (defun eshell-command-result--equal-explainer (command actual expected) "Explain the result of `eshell-command-result--equal'." -- 2.39.2