aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-11-02 17:56:06 +0100
committerMichael Albinus2020-11-02 17:56:06 +0100
commite654b41c6f9eae424736bc8845d92b9dd97ccd3e (patch)
tree53c7d09c4e5efd8f281888bc13527844a5933136
parent554495006e8d33a06c5df63fd8767c1124e1ed9e (diff)
downloademacs-e654b41c6f9eae424736bc8845d92b9dd97ccd3e.tar.gz
emacs-e654b41c6f9eae424736bc8845d92b9dd97ccd3e.zip
Fix some glitches in recent directory-files-* changes
* doc/lispref/files.texi (Contents of Directories): Fix description of directory-files, directory-empty-p and directory-files-and-attributes. * etc/NEWS: Fix entry for directory-files-and-attributes. Fix typos. * lisp/dired.el (directory-empty-p): Move function from here ... * lisp/files.el (directory-empty-p): ... to here. * lisp/net/ange-ftp.el (ange-ftp-directory-files): Call `nreverse' later. * lisp/net/tramp.el (tramp-handle-directory-files): * lisp/net/tramp-adb.el (tramp-adb-handle-directory-files-and-attributes): Do not call `nreverse'. * src/dired.c (Fdirectory_files) (Fdirectory_files_and_attributes): Fix docstrings. * test/src/dired-tests.el: Removed. Tests moved to test/lisp/dired-tests.el. * test/lisp/dired-tests.el (dired-test-bug27899): Tag it :unstable. (dired-test-directory-files) (dired-test-directory-files-and-attributes): New tests.
-rw-r--r--doc/lispref/files.texi20
-rw-r--r--etc/NEWS15
-rw-r--r--lisp/dired.el14
-rw-r--r--lisp/files.el10
-rw-r--r--lisp/net/ange-ftp.el6
-rw-r--r--lisp/net/tramp-adb.el14
-rw-r--r--lisp/net/tramp-sh.el5
-rw-r--r--lisp/net/tramp-smb.el2
-rw-r--r--lisp/net/tramp.el4
-rw-r--r--src/dired.c14
-rw-r--r--test/lisp/dired-tests.el76
-rw-r--r--test/src/dired-tests.el105
12 files changed, 124 insertions, 161 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index f707fde88a8..d49ac42bb46 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2917,7 +2917,7 @@ or display the names in a buffer using the @code{ls} shell command. In
2917the latter case, it can optionally display information about each file, 2917the latter case, it can optionally display information about each file,
2918depending on the options passed to the @code{ls} command. 2918depending on the options passed to the @code{ls} command.
2919 2919
2920@defun directory-files directory &optional full-name match-regexp nosort 2920@defun directory-files directory &optional full-name match-regexp nosort count
2921This function returns a list of the names of the files in the directory 2921This function returns a list of the names of the files in the directory
2922@var{directory}. By default, the list is in alphabetical order. 2922@var{directory}. By default, the list is in alphabetical order.
2923 2923
@@ -2954,20 +2954,14 @@ An error is signaled if @var{directory} is not the name of a directory
2954that can be read. 2954that can be read.
2955@end defun 2955@end defun
2956 2956
2957@defun directory-empty-p filename 2957@defun directory-empty-p directory
2958This utility function returns t if given @var{filename} is an 2958This utility function returns @code{t} if given @var{directory} is an
2959accessible directory and it does not contain any files, i.e. is an 2959accessible directory and it does not contain any files, i.e., is an
2960empty directory. It will ignore '.' and '..' on systems that returns 2960empty directory. It will ignore @samp{.} and @samp{..} on systems
2961them as files in a directory. 2961that return them as files in a directory.
2962
2963As a special case, this function will also return t if
2964FILENAME is the empty string (""). This quirk is due to Emacs
2965interpreting the empty string (in some cases) as the current
2966directory.
2967 2962
2968Symbolic links to directories count as directories. 2963Symbolic links to directories count as directories.
2969See @var{file-symlink-p} to distinguish symlinks. 2964See @var{file-symlink-p} to distinguish symlinks.
2970
2971@end defun 2965@end defun
2972 2966
2973@cindex recursive traverse of directory tree 2967@cindex recursive traverse of directory tree
@@ -3016,7 +3010,7 @@ is called with one argument (the file or directory) and should return
3016non-@code{nil} if that directory is the one it is looking for. 3010non-@code{nil} if that directory is the one it is looking for.
3017@end defun 3011@end defun
3018 3012
3019@defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format 3013@defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format count
3020This is similar to @code{directory-files} in deciding which files 3014This is similar to @code{directory-files} in deciding which files
3021to report on and how to report their names. However, instead 3015to report on and how to report their names. However, instead
3022of returning a list of file names, it returns for each file a 3016of returning a list of file names, it returns for each file a
diff --git a/etc/NEWS b/etc/NEWS
index 5fbe0755fed..4ddb1924935 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1704,34 +1704,34 @@ argument 'ellipsis', will now indicate truncation using '…' when
1704the selected frame can display it, and using "..." otherwise. 1704the selected frame can display it, and using "..." otherwise.
1705 1705
1706+++ 1706+++
1707*** New command 'make-directory-autoloads'. 1707** New command 'make-directory-autoloads'.
1708This does the same as the old command 'update-directory-autoloads', 1708This does the same as the old command 'update-directory-autoloads',
1709but has different semantics: Instead of passing in the output file via 1709but has different semantics: Instead of passing in the output file via
1710the dynamically bound 'generated-autoload-file' variable, the output 1710the dynamically bound 'generated-autoload-file' variable, the output
1711file is now a explicit parameter. 1711file is now a explicit parameter.
1712 1712
1713+++ 1713+++
1714*** New function 'string-search'. 1714** New function 'string-search'.
1715This function takes two string parameters and returns the position of 1715This function takes two string parameters and returns the position of
1716the first instance of the former string in the latter. 1716the first instance of the former string in the latter.
1717 1717
1718+++ 1718+++
1719*** New function 'string-replace'. 1719** New function 'string-replace'.
1720This function works along the line of 'replace-regexp-in-string', but 1720This function works along the line of 'replace-regexp-in-string', but
1721matching on strings instead of regexps, and does not change the global 1721matching on strings instead of regexps, and does not change the global
1722match state. 1722match state.
1723 1723
1724+++ 1724+++
1725*** New function 'process-lines-ignore-status'. 1725** New function 'process-lines-ignore-status'.
1726This is like 'process-lines', but does not signal an error if the 1726This is like 'process-lines', but does not signal an error if the
1727return status is non-zero. 'process-lines-handling-status' has also 1727return status is non-zero. 'process-lines-handling-status' has also
1728been added, and takes a callback to handle the return status. 1728been added, and takes a callback to handle the return status.
1729 1729
1730--- 1730---
1731*** 'ascii' is now a coding system alias for 'us-ascii'. 1731** 'ascii' is now a coding system alias for 'us-ascii'.
1732 1732
1733+++ 1733+++
1734*** New function 'file-backup-file-names'. 1734** New function 'file-backup-file-names'.
1735This function returns the list of file names of all the backup files 1735This function returns the list of file names of all the backup files
1736of its file argument. 1736of its file argument.
1737 1737
@@ -1744,7 +1744,8 @@ directory and whether it contains no other directories or files.
1744** 'directory-files' now takes an additional COUNT parameter. 1744** 'directory-files' now takes an additional COUNT parameter.
1745The parameter makes 'directory-files' return COUNT first file names 1745The parameter makes 'directory-files' return COUNT first file names
1746from a directory. If MATCH is also given, the function will return 1746from a directory. If MATCH is also given, the function will return
1747first COUNT file names that match the expression. 1747first COUNT file names that match the expression. The same COUNT
1748parameter has been added to 'directory-files-and-attributes'.
1748 1749
1749+++ 1750+++
1750** The 'count-lines' function now takes an optional parameter to 1751** The 'count-lines' function now takes an optional parameter to
diff --git a/lisp/dired.el b/lisp/dired.el
index 5ac2f203347..08b19a02250 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3016,20 +3016,6 @@ dired-buffers."
3016;; Tree Dired 3016;; Tree Dired
3017 3017
3018;;; utility functions 3018;;; utility functions
3019(defun directory-empty-p (filename)
3020 "Return t if FILENAME names an existing directory containing no
3021other files. Return nil if FILENAME does not name a directory, or if
3022there was trouble determining whether DIRECTORYNAME is a directory or empty.
3023
3024As a special case, this function will also return t if FILENAME is the
3025empty string (\"\"). This quirk is due to Emacs interpreting the
3026empty string (in some cases) as the current directory.
3027
3028Symbolic links to directories count as directories.
3029See `file-symlink-p' to distinguish symlinks. "
3030 (and (file-directory-p filename)
3031 (null (directory-files
3032 filename nil directory-files-no-dot-files-regexp t 1))))
3033 3019
3034(defun dired-in-this-tree-p (file dir) 3020(defun dired-in-this-tree-p (file dir)
3035 ;;"Is FILE part of the directory tree starting at DIR?" 3021 ;;"Is FILE part of the directory tree starting at DIR?"
diff --git a/lisp/files.el b/lisp/files.el
index 59bcc3e8a78..e55552a2d9a 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -888,6 +888,16 @@ recursion."
888 (push (concat dir "/" file) files))))) 888 (push (concat dir "/" file) files)))))
889 (nconc result (nreverse files)))) 889 (nconc result (nreverse files))))
890 890
891(defun directory-empty-p (dir)
892 "Return t if DIR names an existing directory containing no other files.
893Return nil if DIR does not name a directory, or if there was
894trouble determining whether DIR is a directory or empty.
895
896Symbolic links to directories count as directories.
897See `file-symlink-p' to distinguish symlinks."
898 (and (file-directory-p dir)
899 (null (directory-files dir nil directory-files-no-dot-files-regexp t 1))))
900
891(defvar module-file-suffix) 901(defvar module-file-suffix)
892 902
893(defun load-file (file) 903(defun load-file (file)
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el
index 7ce90504ba3..15322219eff 100644
--- a/lisp/net/ange-ftp.el
+++ b/lisp/net/ange-ftp.el
@@ -3442,9 +3442,9 @@ system TYPE.")
3442 (if (or (not match) (string-match-p match f)) 3442 (if (or (not match) (string-match-p match f))
3443 (setq files 3443 (setq files
3444 (cons (if full (concat directory f) f) files)))) 3444 (cons (if full (concat directory f) f) files))))
3445 (nreverse files)) 3445 (when (natnump count)
3446 (when (natnump count) 3446 (setq files (last files count)))
3447 (setq files (last files count)))) 3447 (nreverse files)))
3448 (apply 'ange-ftp-real-directory-files directory full match nosort count))) 3448 (apply 'ange-ftp-real-directory-files directory full match nosort count)))
3449 3449
3450(defun ange-ftp-directory-files-and-attributes 3450(defun ange-ftp-directory-files-and-attributes
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index e8dbe1618d0..8ccbe412f2b 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -344,14 +344,14 @@ ARGUMENTS to pass to the OPERATION."
344 (sort result (lambda (x y) (string< (car x) (car y)))))) 344 (sort result (lambda (x y) (string< (car x) (car y))))))
345 345
346 (setq result (delq nil 346 (setq result (delq nil
347 (mapcar (lambda (x) (if (or (not match) 347 (mapcar
348 (string-match-p 348 (lambda (x) (if (or (not match)
349 match (car x))) 349 (string-match-p
350 x)) result))) 350 match (car x)))
351 x))
352 result)))
351 (when (natnump count) 353 (when (natnump count)
352 (setq result (last result count)) 354 (setq result (last result count)))
353 (nreverse result))
354
355 result))))))) 355 result)))))))
356 356
357(defun tramp-adb-get-ls-command (vec) 357(defun tramp-adb-get-ls-command (vec)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 7afd6fac47d..915ce2f6a65 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1701,6 +1701,7 @@ ID-FORMAT valid values are `string' and `integer'."
1701 (tramp-get-remote-gid v 'integer))))))))) 1701 (tramp-get-remote-gid v 'integer)))))))))
1702 1702
1703;; Directory listings. 1703;; Directory listings.
1704
1704(defun tramp-sh-handle-directory-files-and-attributes 1705(defun tramp-sh-handle-directory-files-and-attributes
1705 (directory &optional full match nosort id-format count) 1706 (directory &optional full match nosort id-format count)
1706 "Like `directory-files-and-attributes' for Tramp files." 1707 "Like `directory-files-and-attributes' for Tramp files."
@@ -1744,7 +1745,7 @@ ID-FORMAT valid values are `string' and `integer'."
1744 (tramp-handle-directory-files-and-attributes 1745 (tramp-handle-directory-files-and-attributes
1745 directory full match nosort id-format count))))) 1746 directory full match nosort id-format count)))))
1746 1747
1747;; FIXME Fix function to work with count parameter. 1748;; FIXME: Fix function to work with count parameter.
1748(defun tramp-do-directory-files-and-attributes-with-perl 1749(defun tramp-do-directory-files-and-attributes-with-perl
1749 (vec localname &optional id-format) 1750 (vec localname &optional id-format)
1750 "Implement `directory-files-and-attributes' for Tramp files using a Perl script." 1751 "Implement `directory-files-and-attributes' for Tramp files using a Perl script."
@@ -1760,7 +1761,7 @@ ID-FORMAT valid values are `string' and `integer'."
1760 (when (stringp object) (tramp-error vec 'file-error object)) 1761 (when (stringp object) (tramp-error vec 'file-error object))
1761 object)) 1762 object))
1762 1763
1763;; FIXME Fix function to work with count parameter. 1764;; FIXME: Fix function to work with count parameter.
1764(defun tramp-do-directory-files-and-attributes-with-stat 1765(defun tramp-do-directory-files-and-attributes-with-stat
1765 (vec localname &optional id-format) 1766 (vec localname &optional id-format)
1766 "Implement `directory-files-and-attributes' for Tramp files using stat(1) command." 1767 "Implement `directory-files-and-attributes' for Tramp files using stat(1) command."
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index b3b6a94e9cc..3220e516050 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -704,7 +704,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
704 (mapcar (lambda (x) (when (string-match-p match x) x)) 704 (mapcar (lambda (x) (when (string-match-p match x) x))
705 result)))) 705 result))))
706 706
707 ;; return count number of results 707 ;; Return count number of results.
708 (when (and (natnump count) (> count 0)) 708 (when (and (natnump count) (> count 0))
709 (setq result (nbutlast result (- (length result) count)))) 709 (setq result (nbutlast result (- (length result) count))))
710 710
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 25fa9754881..ce0a2b54ff5 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3135,8 +3135,8 @@ User is always nil."
3135 (unless nosort 3135 (unless nosort
3136 (setq result (sort result #'string<))) 3136 (setq result (sort result #'string<)))
3137 (when (natnump count) 3137 (when (natnump count)
3138 (setq result (last file count)) 3138 (setq result (last result count)))
3139 (nreverse files))))) 3139 result)))
3140 3140
3141(defun tramp-handle-directory-files-and-attributes 3141(defun tramp-handle-directory-files-and-attributes
3142 (directory &optional full match nosort id-format count) 3142 (directory &optional full match nosort id-format count)
diff --git a/src/dired.c b/src/dired.c
index 120934bfe74..039dd68c177 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -169,9 +169,9 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
169{ 169{
170 ptrdiff_t ind = 0, last = MOST_POSITIVE_FIXNUM; 170 ptrdiff_t ind = 0, last = MOST_POSITIVE_FIXNUM;
171 171
172 if (!NILP(return_count)) 172 if (!NILP (return_count))
173 { 173 {
174 CHECK_FIXNAT(return_count); 174 CHECK_FIXNAT (return_count);
175 last = XFIXNAT (return_count); 175 last = XFIXNAT (return_count);
176 } 176 }
177 177
@@ -302,7 +302,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
302 302
303DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 5, 0, 303DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 5, 0,
304 doc: /* Return a list of names of files in DIRECTORY. 304 doc: /* Return a list of names of files in DIRECTORY.
305There are three optional arguments: 305There are four optional arguments:
306If FULL is non-nil, return absolute file names. Otherwise return names 306If FULL is non-nil, return absolute file names. Otherwise return names
307 that are relative to the specified directory. 307 that are relative to the specified directory.
308If MATCH is non-nil, mention only file names whose non-directory part 308If MATCH is non-nil, mention only file names whose non-directory part
@@ -338,7 +338,7 @@ Value is a list of the form:
338where each FILEn-ATTRS is the attributes of FILEn as returned 338where each FILEn-ATTRS is the attributes of FILEn as returned
339by `file-attributes'. 339by `file-attributes'.
340 340
341This function accepts four optional arguments: 341This function accepts five optional arguments:
342If FULL is non-nil, return absolute file names. Otherwise return names 342If FULL is non-nil, return absolute file names. Otherwise return names
343 that are relative to the specified directory. 343 that are relative to the specified directory.
344If MATCH is non-nil, mention only file names whose non-directory part 344If MATCH is non-nil, mention only file names whose non-directory part
@@ -347,10 +347,10 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
347 NOSORT is useful if you plan to sort the result yourself. 347 NOSORT is useful if you plan to sort the result yourself.
348ID-FORMAT specifies the preferred format of attributes uid and gid, see 348ID-FORMAT specifies the preferred format of attributes uid and gid, see
349 `file-attributes' for further documentation. 349 `file-attributes' for further documentation.
350On MS-Windows, performance depends on `w32-get-true-file-attributes',
351which see.
352If COUNT is non-nil and a natural number, the function will return 350If COUNT is non-nil and a natural number, the function will return
353 COUNT number of file names (if so many are present). */) 351 COUNT number of file names (if so many are present).
352On MS-Windows, performance depends on `w32-get-true-file-attributes',
353which see. */)
354 (Lisp_Object directory, Lisp_Object full, Lisp_Object match, 354 (Lisp_Object directory, Lisp_Object full, Lisp_Object match,
355 Lisp_Object nosort, Lisp_Object id_format, Lisp_Object count) 355 Lisp_Object nosort, Lisp_Object id_format, Lisp_Object count)
356{ 356{
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index cec533ddfaa..66f8ed95b89 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -293,6 +293,7 @@
293 293
294(ert-deftest dired-test-bug27899 () 294(ert-deftest dired-test-bug27899 ()
295 "Test for https://debbugs.gnu.org/27899 ." 295 "Test for https://debbugs.gnu.org/27899 ."
296 :tags '(:unstable)
296 (dired (list (expand-file-name "src" source-directory) 297 (dired (list (expand-file-name "src" source-directory)
297 "cygw32.c" "alloc.c" "w32xfns.c" "xdisp.c")) 298 "cygw32.c" "alloc.c" "w32xfns.c" "xdisp.c"))
298 (let ((orig dired-hide-details-mode)) 299 (let ((orig dired-hide-details-mode))
@@ -440,6 +441,81 @@
440 (should (= 6 (length (dired-get-marked-files)))) ; All empty dirs but zeta-empty-dir deleted. 441 (should (= 6 (length (dired-get-marked-files)))) ; All empty dirs but zeta-empty-dir deleted.
441 (advice-remove 'read-answer 'dired-test-bug27940-advice)))) 442 (advice-remove 'read-answer 'dired-test-bug27940-advice))))
442 443
444(ert-deftest dired-test-directory-files ()
445 "Test for `directory-files'."
446 (let ((testdir (expand-file-name
447 "directory-files-test" (temporary-file-directory)))
448 (nod directory-files-no-dot-files-regexp))
449 (unwind-protect
450 (progn
451 (when (file-directory-p testdir)
452 (delete-directory testdir t))
453
454 (make-directory testdir)
455 (when (file-directory-p testdir)
456 ;; directory-empty-p: test non-existent dir
457 (should-not (directory-empty-p "some-imaginary-dir"))
458 (should (= 2 (length (directory-files testdir))))
459 ;; directory-empty-p: test empty dir
460 (should (directory-empty-p testdir))
461 (should-not (directory-files testdir nil nod t 1))
462 (dolist (file '(a b c d))
463 (make-empty-file (expand-file-name (symbol-name file) testdir)))
464 (should (= 6 (length (directory-files testdir))))
465 (should (equal "abcd" (mapconcat 'identity (directory-files
466 testdir nil nod) "")))
467 (should (= 2 (length (directory-files testdir nil "[bc]"))))
468 (should (= 3 (length (directory-files testdir nil nod nil 3))))
469 (dolist (file '(5 4 3 2 1))
470 (make-empty-file
471 (expand-file-name (number-to-string file) testdir)))
472 ;;(should (= 0 (length (directory-files testdir nil "[0-9]" t -1))))
473 (should (= 5 (length (directory-files testdir nil "[0-9]" t))))
474 (should (= 5 (length (directory-files testdir nil "[0-9]" t 50))))
475 (should-not (directory-empty-p testdir)))
476
477 (delete-directory testdir t)))))
478
479(ert-deftest dired-test-directory-files-and-attributes ()
480 "Test for `directory-files-and-attributes'."
481 (let ((testdir (expand-file-name
482 "directory-files-test" (temporary-file-directory)))
483 (nod directory-files-no-dot-files-regexp))
484
485 (unwind-protect
486 (progn
487 (when (file-directory-p testdir)
488 (delete-directory testdir t))
489
490 (make-directory testdir)
491 (when (file-directory-p testdir)
492 (should (= 2 (length (directory-files testdir))))
493 (should-not (directory-files-and-attributes testdir t nod t 1))
494 (dolist (file '(a b c d))
495 (make-directory (expand-file-name (symbol-name file) testdir)))
496 (should (= 6 (length (directory-files-and-attributes testdir))))
497 (dolist (dir (directory-files-and-attributes testdir t nod))
498 (should (file-directory-p (car dir)))
499 (should-not (file-regular-p (car dir))))
500 (should (= 2 (length
501 (directory-files-and-attributes testdir nil "[bc]"))))
502 (should (= 3 (length
503 (directory-files-and-attributes
504 testdir nil nod nil nil 3))))
505 (dolist (file '(5 4 3 2 1))
506 (make-empty-file
507 (expand-file-name (number-to-string file) testdir)))
508 ;; (should (= 0 (length (directory-files-and-attributes testdir nil
509 ;; "[0-9]" t
510 ;; nil -1))))
511 (should (= 5 (length
512 (directory-files-and-attributes
513 testdir nil "[0-9]" t))))
514 (should (= 5 (length
515 (directory-files-and-attributes
516 testdir nil "[0-9]" t nil 50))))))
517 (when (file-directory-p testdir)
518 (delete-directory testdir t)))))
443 519
444(provide 'dired-tests) 520(provide 'dired-tests)
445;; dired-tests.el ends here 521;; dired-tests.el ends here
diff --git a/test/src/dired-tests.el b/test/src/dired-tests.el
deleted file mode 100644
index 3beb51366f7..00000000000
--- a/test/src/dired-tests.el
+++ /dev/null
@@ -1,105 +0,0 @@
1;;; dired-tests.el --- Tests for directory-files in dired.c -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; Author: Arthur Miller <arthur.miller@live.com>
6;; Keywords:
7
8;; This program is free software; you can redistribute it and/or modify
9;; it under the terms of the GNU General Public License as published by
10;; the Free Software Foundation, either version 3 of the License, or
11;; (at your option) any later version.
12
13;; This program is distributed in the hope that it will be useful,
14;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;; GNU General Public License for more details.
17
18;; You should have received a copy of the GNU General Public License
19;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21;;; Commentary:
22
23;; These tests check mostly for correct behaviour with COUNT argument.
24
25;;; Code:
26(require 'ert)
27
28(ert-deftest directory-files-tests ()
29 (let ((testdir (expand-file-name "directory-files-test"
30 (temporary-file-directory)))
31 (nod directory-files-no-dot-files-regexp))
32 (unwind-protect
33 (progn
34 (when (file-directory-p testdir)
35 (delete-directory testdir t))
36
37 (make-directory testdir)
38 (when (file-directory-p testdir)
39 ;; directory-empty-p: test non-existent dir
40 (should-not (directory-empty-p "some-imaginary-dir"))
41 (should (= 2 (length (directory-files testdir))))
42 ;; directory-empty-p: test empty dir
43 (should (directory-empty-p testdir))
44 (should-not (directory-files testdir nil nod t 1))
45 (dolist (file '(a b c d))
46 (make-empty-file (expand-file-name (symbol-name file) testdir)))
47 (should (= 6 (length (directory-files testdir))))
48 (should (equal "abcd" (mapconcat 'identity (directory-files
49 testdir nil nod) "")))
50 (should (= 2 (length (directory-files testdir nil "[bc]"))))
51 (should (= 3 (length (directory-files testdir nil nod nil 3))))
52 (dolist (file '(5 4 3 2 1))
53 (make-empty-file (expand-file-name (number-to-string
54 file) testdir)))
55 ;;(should (= 0 (length (directory-files testdir nil "[0-9]" t -1))))
56 (should (= 5 (length (directory-files testdir nil "[0-9]" t))))
57 (should (= 5 (length (directory-files testdir nil "[0-9]" t 50))))
58 (should-not (directory-empty-p testdir)))
59
60 (delete-directory testdir t)))))
61
62(ert-deftest directory-files-and-attributes-tests ()
63 (let ((testdir (expand-file-name "directory-files-test"
64 (temporary-file-directory)))
65 (nod directory-files-no-dot-files-regexp))
66
67 (unwind-protect
68 (progn
69 (when (file-directory-p testdir)
70 (delete-directory testdir t))
71
72 (make-directory testdir)
73 (when (file-directory-p testdir)
74 (should (= 2 (length (directory-files testdir))))
75 (should-not (directory-files-and-attributes testdir t nod t 1))
76 (dolist (file '(a b c d))
77 (make-directory (expand-file-name (symbol-name file) testdir)))
78 (should (= 6 (length (directory-files-and-attributes testdir))))
79 (dolist (dir (directory-files-and-attributes testdir t nod))
80 (should (file-directory-p (car dir)))
81 (should-not (file-regular-p (car dir))))
82 (should (= 2 (length
83 (directory-files-and-attributes testdir nil
84 "[bc]"))))
85 (should (= 3 (length
86 (directory-files-and-attributes testdir nil nod
87 nil nil 3))))
88 (dolist (file '(5 4 3 2 1))
89 (make-empty-file (expand-file-name (number-to-string file)
90 testdir)))
91 ;; (should (= 0 (length (directory-files-and-attributes testdir nil
92 ;; "[0-9]" t
93 ;; nil -1))))
94 (should (= 5 (length
95 (directory-files-and-attributes testdir nil
96 "[0-9]" t))))
97 (should (= 5 (length
98 (directory-files-and-attributes testdir nil
99 "[0-9]" t
100 nil 50))))))
101 (when (file-directory-p testdir)
102 (delete-directory testdir t)))))
103
104(provide 'dired-tests)
105;;; dired-tests.el ends here