* bug#50630: [PATCH] Add tests for 'insert-directory'
[not found] <aBs7q8Blh7yNi2iWuTB37DzPY569oKDfxI4vlDTa5boeqeEYqw3sma_9-EERi7_PeldJUFkji73sSkHocv__8WBAZr6mr81aLfj5UxU45Fs=@rootabega.net>
@ 2021-11-11 1:43 ` John Cummings
2021-11-11 3:38 ` Lars Ingebrigtsen
0 siblings, 1 reply; 2+ messages in thread
From: John Cummings @ 2021-11-11 1:43 UTC (permalink / raw)
To: 50630@debbugs.gnu.org
[-- Attachment #1: Type: text/plain, Size: 360 bytes --]
My copyright assignment is complete. Here is the patch to add tests,
signed from the same master key I used to sign the agreement:
D148 50A5 E6B1 45AE CD83 7983 16B9 CFB2 30B1 275C
This was generated against the emacs-28 branch. There will be a merge
conflict when merged to master, but these tests can just be added as
the last tests in files-tests.el
[-- 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: 5953 bytes --]
From 639ddbcc3f82304f7d5ca96441626bc451d8e92d Mon Sep 17 00:00:00 2001
From: John Cummings <john@rootabega.net>
Date: Wed, 10 Nov 2021 17:51:40 -0500
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 | 72 +++++++++++++++++++
5 files changed, 72 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 9547ac2b69..ab9e3bdc4c 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1807,6 +1807,78 @@ 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"))))
+
+
+ (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)."
+ (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
[-- Attachment #3: 0001-Add-tests-for-insert-directory.patch.asc --]
[-- Type: text/plain, Size: 833 bytes --]
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEwTELQV1b85Q944JhtPO94M0H0gEFAmGMchIACgkQtPO94M0H
0gHdzxAA1EhkTnt4ms2zj7iyuYljbPxOyYOyTCVp1h+XNFyv0XvQQNW0P6XwQtbM
+md18+ASzFvnundH/cx8Pdy9tJ/8t7l77CrWdIlX8lkct9EIjLQf7vqbYY1Zogje
A/JHGR2yGTD+ZA48hQW3GvhibVddX4+5Jnir+0VxN7xoSbOT4WlOxsZmfa5SQC75
6s12vqz7oD1oLbbp/XoDsWTcBSD9A2i8yId8eJOFpnOGhrZVB94yaDvSneWMt68s
AMp3mcJ7r4vEP1UGBZhRFXgreQ8VoZYCe08CW7fclS16xKKnt5eK/HVi5IPS42jh
UAKWSZDazJSi1M+b7C8Sxty2KHQwbP8spvZ6Vl1bkUMjz1L4jl5DJlIsghFZTCfM
taCHc0sM8wB+ay/iMbsCt8c6xXatxR1dpj/z3gZFNzApLMv8l5/anJKB4lgmVajk
/9bT5pfpFAWPRK5EqZMv3+I1j//7h3b7QZOzrsE70I5reQuz+1wo+QgxpcteTCww
yNhLfzWPxpsTYRpZ88A1qDqqJJNhjiv8ulPzKTFjc+8kTPq5o5mN6dpH8kHEHOiO
mhg4MHQKSmXq2qrP3W5nR+Muizdq0HQjt+AbT+akryJfX03pY8tUicEcMCV/98oa
lGDNzNnn8sfHwvkdb6ql48kp+PHCGHvjs6MoegITZX7n97YuCY4=
=UU1M
-----END PGP SIGNATURE-----
^ permalink raw reply related [flat|nested] 2+ messages in thread
* bug#50630: [PATCH] Add tests for 'insert-directory'
2021-11-11 1:43 ` bug#50630: [PATCH] Add tests for 'insert-directory' John Cummings
@ 2021-11-11 3:38 ` Lars Ingebrigtsen
0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-11 3:38 UTC (permalink / raw)
To: John Cummings; +Cc: 50630@debbugs.gnu.org
John Cummings <john@rootabega.net> writes:
> My copyright assignment is complete. Here is the patch to add tests,
> signed from the same master key I used to sign the agreement:
> D148 50A5 E6B1 45AE CD83 7983 16B9 CFB2 30B1 275C
Thanks; applied to Emacs 29.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-11 3:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <aBs7q8Blh7yNi2iWuTB37DzPY569oKDfxI4vlDTa5boeqeEYqw3sma_9-EERi7_PeldJUFkji73sSkHocv__8WBAZr6mr81aLfj5UxU45Fs=@rootabega.net>
2021-11-11 1:43 ` bug#50630: [PATCH] Add tests for 'insert-directory' John Cummings
2021-11-11 3:38 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).