File: filesys.lisp

package info (click to toggle)
cmucl 21a-4
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 50,060 kB
  • sloc: lisp: 375,822; ansic: 30,304; asm: 2,977; sh: 1,372; makefile: 355; csh: 31
file content (60 lines) | stat: -rw-r--r-- 1,735 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;;; Tests for the functions in filesys.lisp.

(defpackage :filesys-tests
  (:use :cl :lisp-unit))

(in-package "FILESYS-TESTS")

;; These tests for unix-namestring come from the cmucl-help mailing
;; list, Sep 26, 2014 by Jared C. Davis

(define-test unix-namestring.1.exists
  ;; Make sure the desired directories exist.
  (assert-equal #P"/tmp/foo/bar/hello.txt"
		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
  (dolist (path '("/tmp/hello.txt"
		  "/tmp/foo/"
		  "/tmp/foo/hello.txt"
		  "/tmp/foo/bar/hello.txt"
		  "/tmp/foo/bar/bye.txt"
		  "/tmp/foo/bar/"
		  "/tmp/foo/bar/baz"
		  "/tmp/foo/bye.txt"
		  "/tmp/bye.txt"))
    (assert-equal path
		  (ext:unix-namestring path nil)
		  path)))

(define-test unix-namestring.1.non-existent
  ;; Make sure the desired directories exist.
  (assert-equal #P"/tmp/foo/bar/hello.txt"
		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
  ;; These paths contain directories that don't exist.
  (dolist (path '("/tmp/oops/"
		  "/tmp/oops/hello.txt"
		  "/tmp/foo/oops/hello.txt"
		  "/tmp/foo/bar/oops/hello.txt"
		  "/tmp/foo/oops/"
		  ))
    (assert-equal path
		  (ext:unix-namestring path nil)
		  path)))

(define-test unix-namestring.2
  ;; Make sure the desired directories exist.
  (assert-equal #P"/tmp/foo/bar/hello.txt"
		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
  (unwind-protect
       (progn
	 ;; Create a symlink loop
	 ;; ln -s /tmp/foo/bar/symlink /tmp/foo/
	 (unix:unix-unlink "/tmp/foo/bar/symlink")
	 (assert-equal t
		       (unix:unix-symlink "/tmp/foo/" "/tmp/foo/bar/symlink"))
	 (assert-equal "/tmp/foo/bar/symlink"
		       (ext:unix-namestring "/tmp/foo/bar/symlink" nil)))
    (unix:unix-unlink "/tmp/foo/bar/symlink")))