diff --git a/pathnames.lisp b/pathnames.lisp index d6df43c..c6ec6d4 100644 --- a/pathnames.lisp +++ b/pathnames.lisp @@ -36,34 +36,16 @@ (export '(list-directory pathname-as-directory)) -(defun component-present-p (value) - "Helper function for DIRECTORY-PATHNAME-P which checks whether VALUE -is neither NIL nor the keyword :UNSPECIFIC." - (and value (not (eql value :unspecific)))) - (defun directory-pathname-p (pathspec) "Returns NIL if PATHSPEC \(a pathname designator) does not designate a directory, PATHSPEC otherwise. It is irrelevant whether file or directory designated by PATHSPEC does actually exist." - (and - (not (component-present-p (pathname-name pathspec))) - (not (component-present-p (pathname-type pathspec))) - pathspec)) + (uiop:directory-pathname-p pathspec)) (defun pathname-as-directory (pathspec) "Converts the non-wild pathname designator PATHSPEC to directory form." - (let ((pathname (pathname pathspec))) - (when (wild-pathname-p pathname) - (error "Can't reliably convert wild pathnames.")) - (cond ((not (directory-pathname-p pathspec)) - (make-pathname :directory (append (or (pathname-directory pathname) - (list :relative)) - (list (file-namestring pathname))) - :name nil - :type nil - :defaults pathname)) - (t pathname)))) + (uiop:ensure-directory-pathname pathspec)) (defun directory-wildcard (dirname) "Returns a wild pathname designator that designates all files within @@ -82,7 +64,8 @@ directory form - see PATHNAME-AS-DIRECTORY." (when (wild-pathname-p dirname) (error "Can only list concrete directory names.")) (let ((wildcard (directory-wildcard dirname))) - (directory wildcard))) + (directory wildcard))) + (defun list-directory-recursive (dirname &optional flatten-p) "Returns a list of pathnames corresponding to the truenames all files within the directory and in any subdirectories. If diff --git a/stumpwm-tests.asd b/stumpwm-tests.asd index af698b9..5da9f0d 100644 --- a/stumpwm-tests.asd +++ b/stumpwm-tests.asd @@ -5,6 +5,7 @@ "fiasco") :pathname "tests/" :components ((:file "package") - (:file "kmap")) + (:file "kmap") + (:file "pathnames")) :perform (test-op (o c) (uiop/package:symbol-call "FIASCO" "RUN-TESTS" 'stumpwm-tests))) diff --git a/tests/pathnames.lisp b/tests/pathnames.lisp new file mode 100644 index 0000000..20ec6ad --- /dev/null +++ b/tests/pathnames.lisp @@ -0,0 +1,8 @@ +(in-package #:stumpwm-tests) + +(deftest test-directory-pathname-p () + (is (stumpwm::directory-pathname-p "/"))) + +(deftest test-ensure-directory-pathname () + (is (equal (pathname-as-directory "/") #P"/")) + (is (equal (pathname-as-directory "/test.lisp") #P"/test.lisp/")))