Subject: bug#58265: 29.0.50; [PATCH] $HOME adjustment for 'ert-remote-temporary-file-directory' is wrong

From: Jim Porter <[email-masked]>
Date: Sun, 2 Oct 2022 18:32:32 -0700

I tried to use 'ert-remote-temporary-file-directory' in a test for an 
external package, but it ended up breaking some existing tests simply by 
requiring both tramp and ert-x. These tests indirectly used 'cd' (by way 
of 'compilation-start'), which triggered the failure.

Steps to reproduce:

   $ mkdir -p ~/src
   $ emacs -Q --batch -l tramp -l ert-x --eval '(cd "~/src/")'

Result:

   Error: error ("No such directory: ~/src/")
     mapbacktrace(#f(compiled-function (evald func args flags) 
#<bytecode 0xc43976fdbae86a5>))
     debug-early-backtrace()
     debug-early(error (error "No such directory: ~/src/"))
     error("No such directory: %s" "~/src/")
     cd("~/src")
     eval((cd "~/src") t)
     command-line-1(("-l" "tramp" "-l" "ert-x" "--eval" "(cd \"~/src/\")"))
     command-line()
     normal-top-level()
   No such directory: ~/src/

Looking at ert-x.el, I think this is because 
'ert-remote-temporary-file-directory' does some fixup on $HOME, but it 
was too aggressive. See attached.

From 5ef9bce106dbc78c0e29b3c0e1baf0ee47859ece Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Sun, 2 Oct 2022 18:19:56 -0700
Subject: [PATCH] ; Fix logic of $HOME adjustment for
 'ert-remote-temporary-file-directory'

* lisp/emacs-lisp/ert-x.el (ert-remote-temporary-file-directory): Only
adjust $HOME when it doesn't exist.
---
 lisp/emacs-lisp/ert-x.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el
index bfd796586d..a891f068a7 100644
--- a/lisp/emacs-lisp/ert-x.el
+++ b/lisp/emacs-lisp/ert-x.el
@@ -568,7 +568,7 @@ ert-remote-temporary-file-directory
          `("\\`mock\\'" nil ,(system-name)))
         ;; Emacs's Makefile sets $HOME to a nonexistent value.  Needed
         ;; in batch mode only, therefore.
-        (unless (and (null noninteractive) (file-directory-p "~/"))
+        (when (and noninteractive (not (file-directory-p "~/")))
           (setenv "HOME" temporary-file-directory))
         (format "/mock::%s" temporary-file-directory))))
     "Temporary directory for remote file tests.")
-- 
2.25.1