]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Eshell tests on MS-Windows
authorEli Zaretskii <eliz@gnu.org>
Sun, 9 Jun 2024 07:56:39 +0000 (10:56 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Jun 2024 09:52:45 +0000 (11:52 +0200)
* 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
test/lisp/eshell/em-script-tests.el
test/lisp/eshell/em-unix-tests.el
test/lisp/eshell/esh-proc-tests.el
test/lisp/eshell/esh-util-tests.el
test/lisp/eshell/esh-var-tests.el
test/lisp/eshell/eshell-tests-helpers.el

index 85e30e23cecfd6de7b1d8773eb2864dee5234ca2..1504d89731da5b939b617f55358fee914d8cd6a3 100644 (file)
@@ -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)
index f3adbae9df785055f609f1e11e85436831073f62..94afe775a3b5acb8ecdeaeb869022f942c60e0f9 100644 (file)
 
 (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"
index 2ee42c81333786f903e282a4fb98d8085ccc98d2..7312fb831cd4cf4ba08229e80f28350300dac49e 100644 (file)
                                  "#<buffer \\*compilation\\*>")
     (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."
index 63fb8f46dfaa1bd07781c2d6d47735c55fc1f42c..cf869edbe0c6048dbb2c2d834cd7138e57207065 100644 (file)
   "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)))))))
 
index 71a047b1801e06afbb99036ffd7071488aaa7e49..031de558d1fdde7392f4123d742734153d058534 100644 (file)
 (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))))
 
index 1b46b214e778a01e98065d05ea0e67a0c6046605..8b2f882f37e7e28ae3bcbf6e055b7af976e45c4a 100644 (file)
@@ -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
index bfd829c95e9640e9470973934456ae1b0a7b4266..acbe57a72833c209d69375e3d1c66b00ef9528de 100644 (file)
@@ -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'."