diff options
| author | John Cummings | 2021-11-11 04:37:46 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-11-11 04:37:46 +0100 |
| commit | 9b80fe55f9725a039a2f367ffccea164c6ca9cf9 (patch) | |
| tree | b244728e9cf31ff14d98ab4b3fef2ac9a1b5e6e7 | |
| parent | 6c405b7a4915bd3604d6591ff9156cf1cf77fecb (diff) | |
| download | emacs-9b80fe55f9725a039a2f367ffccea164c6ca9cf9.tar.gz emacs-9b80fe55f9725a039a2f367ffccea164c6ca9cf9.zip | |
Add tests for 'insert-directory'
* 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'.
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).
5 files changed, 74 insertions, 0 deletions
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 00000000000..e69de29bb2d --- /dev/null +++ b/test/lisp/files-resources/insert-directory/test_dir/bar | |||
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 00000000000..e69de29bb2d --- /dev/null +++ b/test/lisp/files-resources/insert-directory/test_dir/foo | |||
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 00000000000..e69de29bb2d --- /dev/null +++ b/test/lisp/files-resources/insert-directory/test_dir_other/bar | |||
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 00000000000..e69de29bb2d --- /dev/null +++ b/test/lisp/files-resources/insert-directory/test_dir_other/foo | |||
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 1e20317739a..d66ed62e286 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el | |||
| @@ -1807,5 +1807,79 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." | |||
| 1807 | (should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" ""))) | 1807 | (should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" ""))) |
| 1808 | (should (equal (file-name-split "foo/bar/") '("foo" "bar" "")))) | 1808 | (should (equal (file-name-split "foo/bar/") '("foo" "bar" "")))) |
| 1809 | 1809 | ||
| 1810 | ;; `insert-directory' output tests. | ||
| 1811 | (let* ((data-dir "insert-directory") | ||
| 1812 | (test-dir (file-name-as-directory | ||
| 1813 | (ert-resource-file | ||
| 1814 | (concat data-dir "/test_dir")))) | ||
| 1815 | (test-dir-other (file-name-as-directory | ||
| 1816 | (ert-resource-file | ||
| 1817 | (concat data-dir "/test_dir_other")))) | ||
| 1818 | (test-files `(,test-dir "foo" "bar")) ;expected files to be found | ||
| 1819 | ;; Free space test data for `insert-directory'. | ||
| 1820 | ;; Meaning: (path free-space-bytes-to-stub expected-free-space-string) | ||
| 1821 | (free-data `((,test-dir 10 "available 10 B") | ||
| 1822 | (,test-dir-other 100 "available 100 B") | ||
| 1823 | (:default 999 "available 999 B")))) | ||
| 1824 | |||
| 1825 | |||
| 1826 | (defun files-tests--look-up-free-data (path) | ||
| 1827 | "Look up free space test data, with a default for unspecified paths." | ||
| 1828 | (let ((path (file-name-as-directory path))) | ||
| 1829 | (cdr (or (assoc path free-data) | ||
| 1830 | (assoc :default free-data))))) | ||
| 1831 | |||
| 1832 | (defun files-tests--make-file-system-info-stub (&optional static-path) | ||
| 1833 | "Return a stub for `file-system-info' using dynamic or static test data. | ||
| 1834 | If that data should be static, pass STATIC-PATH to choose which | ||
| 1835 | path's data to use." | ||
| 1836 | (lambda (path) | ||
| 1837 | (let* ((path (cond (static-path) | ||
| 1838 | ;; file-system-info knows how to handle ".", so we | ||
| 1839 | ;; do the same thing | ||
| 1840 | ((equal "." path) default-directory) | ||
| 1841 | (path))) | ||
| 1842 | (return-size | ||
| 1843 | (car (files-tests--look-up-free-data path)))) | ||
| 1844 | (list return-size return-size return-size)))) | ||
| 1845 | |||
| 1846 | (defun files-tests--insert-directory-output (dir &optional verbose) | ||
| 1847 | "Run `insert-directory' and return its output." | ||
| 1848 | (with-current-buffer-window "files-tests--insert-directory" nil nil | ||
| 1849 | (insert-directory dir "-l" nil t) | ||
| 1850 | (buffer-substring-no-properties (point-min) (point-max)))) | ||
| 1851 | |||
| 1852 | (ert-deftest files-tests-insert-directory-shows-files () | ||
| 1853 | "Verify `insert-directory' reports the files in the directory." | ||
| 1854 | (let* ((test-dir (car test-files)) | ||
| 1855 | (files (cdr test-files)) | ||
| 1856 | (output (files-tests--insert-directory-output test-dir))) | ||
| 1857 | (dolist (file files) | ||
| 1858 | (should (string-match-p file output))))) | ||
| 1859 | |||
| 1860 | (defun files-tests--insert-directory-shows-given-free (dir &optional | ||
| 1861 | info-func) | ||
| 1862 | "Run `insert-directory' and verify it reports the correct available space. | ||
| 1863 | Stub `file-system-info' to ensure the available space is consistent, | ||
| 1864 | either with the given stub function or a default one using test data." | ||
| 1865 | (cl-letf (((symbol-function 'file-system-info) | ||
| 1866 | (or info-func | ||
| 1867 | (files-tests--make-file-system-info-stub)))) | ||
| 1868 | (should (string-match-p (cadr | ||
| 1869 | (files-tests--look-up-free-data dir)) | ||
| 1870 | (files-tests--insert-directory-output dir t))))) | ||
| 1871 | |||
| 1872 | (ert-deftest files-tests-insert-directory-shows-free () | ||
| 1873 | "Test that verbose `insert-directory' shows the correct available space." | ||
| 1874 | (files-tests--insert-directory-shows-given-free | ||
| 1875 | test-dir | ||
| 1876 | (files-tests--make-file-system-info-stub test-dir))) | ||
| 1877 | |||
| 1878 | (ert-deftest files-tests-bug-50630 () | ||
| 1879 | "Verify verbose `insert-directory' shows free space of the target directory. | ||
| 1880 | The current directory at call time should not affect the result (Bug#50630)." | ||
| 1881 | (let ((default-directory test-dir-other)) | ||
| 1882 | (files-tests--insert-directory-shows-given-free test-dir)))) | ||
| 1883 | |||
| 1810 | (provide 'files-tests) | 1884 | (provide 'files-tests) |
| 1811 | ;;; files-tests.el ends here | 1885 | ;;; files-tests.el ends here |