all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Cummings <john@rootabega.net>
To: "50630@debbugs.gnu.org" <50630@debbugs.gnu.org>
Subject: bug#50630: [PATCH] Add tests for insert-directory
Date: Fri, 24 Sep 2021 19:58:25 +0000	[thread overview]
Message-ID: <V5JmW0o5qHaKH206wrmdK_B_QWu_EIkLRqFA-axsnWRueelk8bxLT7d20sE3tCePq_aT_8_H_LVEvj7uavlPAFvCmnum929I-Ewqo7tdF28=@rootabega.net> (raw)
In-Reply-To: <JBqm7KQ2DJUp-dhplOvmXWA9jYAO3_nq6esSKGU1ESYNcZUg0jrRtN-W6J8LQ9umlAyPYR633evnmi_kWgBuIWC0fSwtNeeJ1eZtbUJRK_Q=@rootabega.net>

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

The attached patch adds a regression test for this bug, as well as a
couple other basic functionality tests for insert-directory. This does
not test the other unfixed cases still in ls-lisp.el and tramp-sh.el,
but I thought it prudent to get these tests in before trying to apply
them in other libraries.

Along those lines, I also attempted to skip the test when ls-lisp
would be used during files-tests.el, which I predict might happen when
building on Windows?

I sent in my copyright assignment, but I think it's still being
finalized.

Thank you!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-tests-for-insert-directory.patch --]
[-- Type: text/x-patch; name=0001-Add-tests-for-insert-directory.patch, Size: 6612 bytes --]

From 213243a73871f365c910a6680a894907a497bbee Mon Sep 17 00:00:00 2001
From: John Cummings <john@rootabega.net>
Date: Fri, 24 Sep 2021 15:36:23 -0400
Subject: [PATCH] Add tests for 'insert-directory'

Add tests for 'insert-directory' base functionality and regression tests for
the issue where free space was reported for the current directory instead of
the target of 'list-directory' (Bug#50630).
* test/lisp/files-tests.el: Add 'insert-directory' tests.
* test/lisp/files-resources/insert-directory/: Create directories and files to
use for testing 'insert-directory'.
---
 .../insert-directory/test_dir/bar             |  0
 .../insert-directory/test_dir/foo             |  0
 .../insert-directory/test_dir_other/bar       |  0
 .../insert-directory/test_dir_other/foo       |  0
 test/lisp/files-tests.el                      | 79 +++++++++++++++++++
 5 files changed, 79 insertions(+)
 create mode 100644 test/lisp/files-resources/insert-directory/test_dir/bar
 create mode 100644 test/lisp/files-resources/insert-directory/test_dir/foo
 create mode 100644 test/lisp/files-resources/insert-directory/test_dir_other/bar
 create mode 100644 test/lisp/files-resources/insert-directory/test_dir_other/foo

diff --git a/test/lisp/files-resources/insert-directory/test_dir/bar b/test/lisp/files-resources/insert-directory/test_dir/bar
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/lisp/files-resources/insert-directory/test_dir/foo b/test/lisp/files-resources/insert-directory/test_dir/foo
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/bar b/test/lisp/files-resources/insert-directory/test_dir_other/bar
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/foo b/test/lisp/files-resources/insert-directory/test_dir_other/foo
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index b283a512a4..61c5a13546 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -26,6 +26,7 @@
 (require 'bytecomp) ; `byte-compiler-base-file-name'.
 (require 'dired) ; `dired-uncache'.
 (require 'filenotify) ; `file-notify-add-watch'.
+(require 'map)
 
 ;; Set to t if the local variable was set, `query' if the query was
 ;; triggered.
@@ -1774,6 +1775,84 @@ files-tests-save-buffers-kill-emacs--asks-to-save-buffers
          ;; `save-some-buffers-default-predicate' (i.e. the 2nd element) is ignored.
          (nil save-some-buffers-root ,nb-might-save))))))
 
+;;insert-directory output tests
+(let* ((data-dir "insert-directory")
+       (test-dir (file-name-as-directory
+                  (ert-resource-file
+                   (concat data-dir "/test_dir"))))
+       (test-dir-other (file-name-as-directory
+                        (ert-resource-file
+                         (concat data-dir "/test_dir_other"))))
+       (test-files `(,test-dir "foo" "bar")) ;expected files to be found
+       ;Free space test data for `insert-directory'.
+       ;Meaning: (path free-space-bytes-to-stub expected-free-space-string)
+       (free-data `((,test-dir 10 "available 10 B")
+                    (,test-dir-other 100 "available 100 B")
+                    (:default 999 "available 999 B")))
+       ;;Try to verify that insert-directory will come from files.el,
+       ;;not ls-lisp.el. Windows builds will probably use ls-lisp.el
+       ;;by default, which will invalidate some tests.
+       (insert-directory-program-used (or (not (featurep 'ls-lisp))
+                                          ls-lisp-use-insert-directory-program)))
+
+
+  (defun files-tests--look-up-free-data (path)
+    "Look up free space test data, with a default for unspecified paths."
+    (let ((path (file-name-as-directory path)))
+      (cdr (or (assoc path free-data)
+               (assoc :default free-data)))))
+
+  (defun files-tests--make-file-system-info-stub (&optional static-path)
+    "Return a stub for `file-system-info' using dynamic or static test data.
+If that data should be static, pass STATIC-PATH to choose which
+path's data to use."
+    (lambda (path)
+      (let* ((path (cond (static-path)
+                         ;; file-system-info knows how to handle ".", so we
+                         ;; do the same thing
+                         ((equal "." path) default-directory)
+                         (path)))
+             (return-size
+              (car (files-tests--look-up-free-data path))))
+        (list return-size return-size return-size))))
+
+  (defun files-tests--insert-directory-output (dir &optional verbose)
+    "Run `insert-directory' and return its output."
+    (with-current-buffer-window "files-tests--insert-directory" nil nil
+      (insert-directory dir "-l" nil t)
+      (buffer-substring-no-properties (point-min) (point-max))))
+
+  (ert-deftest files-tests-insert-directory-shows-files ()
+    "Verify `insert-directory' reports the files in the directory."
+    (let* ((test-dir (car test-files))
+           (files (cdr test-files))
+           (output (files-tests--insert-directory-output test-dir)))
+      (dolist (file files)
+        (should (string-match-p file output)))))
+
+  (defun files-tests--insert-directory-shows-given-free (dir &optional info-func)
+    "Run `insert-directory' and verify it reports the correct available space.
+Stub `file-system-info' to ensure the available space is consistent,
+either with the given stub function or a default one using test data."
+    (cl-letf (((symbol-function 'file-system-info)
+               (or info-func
+                   (files-tests--make-file-system-info-stub))))
+      (should (string-match-p (cadr
+                               (files-tests--look-up-free-data dir))
+                              (files-tests--insert-directory-output dir t)))))
+
+  (ert-deftest files-tests-insert-directory-shows-free ()
+    "Test that verbose `insert-directory' shows the correct available space."
+    (files-tests--insert-directory-shows-given-free
+     test-dir
+     (files-tests--make-file-system-info-stub test-dir)))
+
+  (ert-deftest files-tests-bug-50630 ()
+    "Verify verbose `insert-directory' shows free space of the target directory.
+The current directory at call time should not affect the result (Bug#50630)."
+    (skip-unless insert-directory-program-used)
+    (let ((default-directory test-dir-other))
+      (files-tests--insert-directory-shows-given-free test-dir))))
 
 (provide 'files-tests)
 ;;; files-tests.el ends here
-- 
2.25.1


  parent reply	other threads:[~2021-09-24 19:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16 23:00 bug#50630: 28.0.50; list-directory shows free space for current directory, not the specified one John Cummings
2021-09-17  7:07 ` Eli Zaretskii
2021-09-17 10:24   ` John Cummings
2021-09-17 10:36     ` Eli Zaretskii
2021-09-17 17:38   ` bug#50630: [External] : " Drew Adams
2021-09-17 18:04     ` Eli Zaretskii
2021-09-17 20:32       ` John Cummings
2021-09-18  5:56         ` Eli Zaretskii
2021-09-18 10:04           ` John Cummings
2021-09-21 10:57 ` bug#50630: Confirmation of instances in ls-lisp.el and tramp-sh.el John Cummings
2021-09-24 19:58 ` John Cummings [this message]
2021-09-25  1:47   ` bug#50630: [PATCH] Add tests for insert-directory Lars Ingebrigtsen
2021-09-25 10:45     ` John Cummings
2021-09-25 11:38       ` Michael Albinus
2021-09-25 12:13         ` John Cummings
2021-09-25  6:10   ` Eli Zaretskii
2021-09-25 11:38     ` John Cummings
2021-09-25 12:30       ` John Cummings
2021-09-25 13:06       ` Eli Zaretskii
2021-09-25 14:29         ` John Cummings
2021-09-25 14:55           ` Eli Zaretskii
2021-09-25 17:15             ` John Cummings
2021-09-25 17:26               ` Eli Zaretskii
2021-09-25 17:37                 ` John Cummings
2021-09-25 17:44                   ` Eli Zaretskii
2021-09-25 18:01                     ` John Cummings
2021-09-25 18:44                       ` Eli Zaretskii
2021-09-25 19:00                         ` John Cummings
2021-09-25 19:07                           ` Eli Zaretskii
2021-09-25 19:58                             ` John Cummings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='V5JmW0o5qHaKH206wrmdK_B_QWu_EIkLRqFA-axsnWRueelk8bxLT7d20sE3tCePq_aT_8_H_LVEvj7uavlPAFvCmnum929I-Ewqo7tdF28=@rootabega.net' \
    --to=john@rootabega.net \
    --cc=50630@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.