summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-12-01 23:27:09 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-12-01 23:27:19 +0100
commit1914d946d62de4ab7bab1434bcea09087d61bb5a (patch)
tree2c535caf9dc3d7094f4548b5b482e01bcb8fb33b /test
parented7591c9055d4c90d2f59ffbd90aff45da2dc102 (diff)
downloademacs-1914d946d62de4ab7bab1434bcea09087d61bb5a.tar.gz
Change how Dired displays available space
* doc/emacs/dired.texi (Misc Dired Features): Document it (bug#23812). * lisp/dired.el (dired-free-space): New user option. (dired-insert-directory): Use it from here. (dired--insert-disk-space): New function that uses the user option. * lisp/files.el (insert-directory): Don't transform "total" here. * lisp/ls-lisp.el (ls-lisp--insert-directory): Or here. Instead just leave the "total <num>" bit alone, and let Dired transform it. * test/lisp/files-tests.el (files-tests): Move "available" tests to dired-tests. * test/lisp/dired-tests.el (data-dir): Moved here.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/dired-resources/insert-directory/test_dir/bar (renamed from test/lisp/files-resources/insert-directory/test_dir/bar)0
-rw-r--r--test/lisp/dired-resources/insert-directory/test_dir/foo (renamed from test/lisp/files-resources/insert-directory/test_dir/foo)0
-rw-r--r--test/lisp/dired-resources/insert-directory/test_dir_other/bar (renamed from test/lisp/files-resources/insert-directory/test_dir_other/bar)0
-rw-r--r--test/lisp/dired-resources/insert-directory/test_dir_other/foo (renamed from test/lisp/files-resources/insert-directory/test_dir_other/foo)0
-rw-r--r--test/lisp/dired-tests.el74
-rw-r--r--test/lisp/files-tests.el74
6 files changed, 74 insertions, 74 deletions
diff --git a/test/lisp/files-resources/insert-directory/test_dir/bar b/test/lisp/dired-resources/insert-directory/test_dir/bar
index e69de29bb2d..e69de29bb2d 100644
--- a/test/lisp/files-resources/insert-directory/test_dir/bar
+++ b/test/lisp/dired-resources/insert-directory/test_dir/bar
diff --git a/test/lisp/files-resources/insert-directory/test_dir/foo b/test/lisp/dired-resources/insert-directory/test_dir/foo
index e69de29bb2d..e69de29bb2d 100644
--- a/test/lisp/files-resources/insert-directory/test_dir/foo
+++ b/test/lisp/dired-resources/insert-directory/test_dir/foo
diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/bar b/test/lisp/dired-resources/insert-directory/test_dir_other/bar
index e69de29bb2d..e69de29bb2d 100644
--- a/test/lisp/files-resources/insert-directory/test_dir_other/bar
+++ b/test/lisp/dired-resources/insert-directory/test_dir_other/bar
diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/foo b/test/lisp/dired-resources/insert-directory/test_dir_other/foo
index e69de29bb2d..e69de29bb2d 100644
--- a/test/lisp/files-resources/insert-directory/test_dir_other/foo
+++ b/test/lisp/dired-resources/insert-directory/test_dir_other/foo
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index ad1bca923d9..43791118f14 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -511,5 +511,79 @@
(when (file-directory-p testdir)
(delete-directory testdir t)))))
+;; `dired-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
+ (let ((dired-free-space 'separate))
+ (dired-insert-directory dir "-l" nil 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 'dired-tests)
;;; dired-tests.el ends here
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index d3d58aad5f2..462048802f0 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1822,79 +1822,5 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil."
(should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" "")))
(should (equal (file-name-split "foo/bar/") '("foo" "bar" ""))))
-;; `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