Subject: Re: bug#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers

From: Vladimir Sedach <[email-masked]>
Date: Sat, 08 Jul 2023 10:18:40 -0600

Eli Zaretskii <[email-masked]> writes:

> Thanks, I installed this, with slight changes, on the master branch,
> and I'm therefore closing this bug.

Thank you. There is also the unit tests patch in the original email
(attached here as well) that should be applied.

--
Vladimir Sedach

>From ce4b041bd71cd7ee1b025cc14ae962f8d98d9478 Mon Sep 17 00:00:00 2001
From: Vladimir Sedach <[email-masked]>
Date: Mon, 26 Jun 2023 22:30:25 -0600
Subject: [PATCH 1/2] ; * test/lisp/shell-tests.el: added tests for
 shell-dirtrack-mode

---
 test/lisp/shell-tests.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/test/lisp/shell-tests.el b/test/lisp/shell-tests.el
index db9124e2435..ddddfdb2e0f 100644
--- a/test/lisp/shell-tests.el
+++ b/test/lisp/shell-tests.el
@@ -64,4 +64,35 @@ shell-tests-split-string
     (should (equal (split-string-shell-command "ls /tmp/foo\\ bar")
                    '("ls" "/tmp/foo bar")))))
 
+(ert-deftest shell-dirtrack-on-by-default ()
+  (with-temp-buffer
+    (shell-mode)
+    (should shell-dirtrack-mode)))
+
+(ert-deftest shell-dirtrack-should-not-be-on-in-unrelated-modes ()
+  (with-temp-buffer
+    (should (not shell-dirtrack-mode))))
+
+(ert-deftest shell-dirtrack-sets-list-buffers-directory ()
+  (let ((start-dir default-directory))
+    (with-temp-buffer
+      (should-not list-buffers-directory)
+      (shell-mode)
+      (shell-cd "..")
+      (should list-buffers-directory)
+      (should (not (equal start-dir list-buffers-directory)))
+      (should (string-prefix-p list-buffers-directory start-dir)))))
+
+(ert-deftest shell-directory-tracker-cd ()
+  (let ((start-dir default-directory))
+    (with-temp-buffer
+      (should-not list-buffers-directory)
+      (shell-mode)
+      (cl-letf (((symbol-function 'shell-unquote-argument)
+                 (lambda (x) x)))
+        (shell-directory-tracker "cd .."))
+      (should list-buffers-directory)
+      (should (not (equal start-dir list-buffers-directory)))
+      (should (string-prefix-p list-buffers-directory start-dir)))))
+
 ;;; shell-tests.el ends here
-- 
2.20.1