;;;; directory-utils-test.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 (import test) (import (test-utils gloss)) (import (chicken format)) (test-begin "Directory Utils") (import (directory-utils dotted)) (import (directory-utils checks)) (import (directory-utils stack)) (import (directory-utils operations)) (import (chicken condition)) ;;; (test-assert (dirname? "/abc")) (test-assert (dirname? "/")) (test-assert (dirname? "abc/cbs")) (test-assert (dirname? "abc/")) (test-assert "just filename not dirname" (not (dirname? "abc"))) (test-assert (not (dirname? ""))) (test-assert (pathname? "abc/cbs.foo")) (test-assert (pathname? "abc/cbs")) (test-assert (pathname? ".abc")) (test-assert (not (pathname? ""))) (test-assert (not (filename? "abc/cbs.foo"))) (test-assert (filename? "cbs.foo")) (test-assert (not (filename? ""))) (test-assert (dot-pathname? "/abc/.hide/hidden")) (test-assert (dot-pathname? "/abc/cbs/../.foo")) (test-assert (dot-pathname? "/abc/cbs/../.foo/bar")) (test-assert (not (dot-pathname? "abc/cbs.foo"))) ;WTF? yeah, exclude "system" directories (test-assert (not (dot-pathname? "/abc/cbs/./foo"))) (test-assert (not (dot-pathname? "/abc/cbs/../foo"))) (test-assert (dot-pathname? "/abc/cbs/./foo" '())) (test-assert (dot-pathname? "/abc/cbs/../foo" '())) (test-assert (dot-filename? ".hide")) (test-assert (not (dot-filename? "/abc/.hide/hidden"))) (test-assert (not (dot-filename? "."))) (test-assert (not (dot-filename? ".."))) (test '("abc/cbs.foo") (remove-dotfiles '(".hide" "abc/cbs.foo"))) ;macOS ;Error: (file-exists?) system error while trying to access file: "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin/chicken" (test-assert "(which-command-pathname \"mkdir\")" (cond-expand (macosx (handle-exceptions exp (begin (gloss "failure (.security. probably)") #t) (which-command-pathname "mkdir")) ) (else (which-command-pathname "mkdir") ) )) (test-assert "(not (which-command-pathname \"93274030#$%)#)$()\"))" (cond-expand (macosx (handle-exceptions exp (begin (gloss "failure (.security. probably)") #t) (not (which-command-pathname "93274030#$%)#)$()"))) ) (else (not (which-command-pathname "93274030#$%)#)$()")) ) )) ;run.scm + *-test.scm + *-test upto that point, depends on knowing test run ;order. not a great test. (define-constant SCM-DIRECTORY-COUNT (+ 1 1 1)) (cond-expand (compiling (define-constant TESTS-DIRECTORY-COUNT (+ SCM-DIRECTORY-COUNT 1 1))) (else (define-constant TESTS-DIRECTORY-COUNT (+ SCM-DIRECTORY-COUNT 1))) ) (test "directory-foldl tests" TESTS-DIRECTORY-COUNT (directory-foldl "." (lambda (ct fn) (add1 ct)) 0)) (test "directory-tree-unfold tests" TESTS-DIRECTORY-COUNT (length (directory-tree-unfold))) ;; (test-assert (push-directory "..")) ;tests .egg .scm (define-constant EGG-DIRECTORY-COUNT 3) (import (only (srfi 1) xcons)) (let ((fns (directory-foldl "." xcons '() #t))) ;(glossf "Files: ~A" fns) ;debug (test-assert "directory-foldl tests/.." (<= EGG-DIRECTORY-COUNT (length fns))) ) ;NOTE at this point the same (test-assert (pop-toplevel-directory)) ;test-not-error (test-assert (pop-directory)) ;test-not-error ;;; (test-end "Directory Utils") (test-exit)