1
;;;; filesys.test --- test file system functions -*- scheme -*-
3
;;;; Copyright (C) 2004, 2006 Free Software Foundation, Inc.
5
;;;; This library is free software; you can redistribute it and/or
6
;;;; modify it under the terms of the GNU Lesser General Public
7
;;;; License as published by the Free Software Foundation; either
8
;;;; version 2.1 of the License, or (at your option) any later version.
10
;;;; This library is distributed in the hope that it will be useful,
11
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
;;;; Lesser General Public License for more details.
15
;;;; You should have received a copy of the GNU Lesser General Public
16
;;;; License along with this library; if not, write to the Free Software
17
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
(define-module (test-suite test-filesys)
20
#:use-module (test-suite lib)
21
#:use-module (test-suite guile-test))
24
(data-file-name "filesys-test.tmp"))
25
(define (test-symlink)
26
(data-file-name "filesys-test-link.tmp"))
33
(with-test-prefix "copy-file"
35
;; return next prospective file descriptor number
41
;; in guile 1.6.4 and earlier, copy-file didn't close the input fd when
42
;; the output could not be opened
43
(pass-if "fd leak when dest unwritable"
44
(let ((old-next (next-fd)))
45
(false-if-exception (copy-file "/dev/null" "no/such/dir/foo"))
46
(= old-next (next-fd)))))
52
(with-test-prefix "lstat"
54
(pass-if "normal file"
55
(call-with-output-file (test-file)
57
(display "hello" port)))
58
(eqv? 5 (stat:size (lstat (test-file)))))
60
(call-with-output-file (test-file)
62
(display "hello" port)))
63
(false-if-exception (delete-file (test-symlink)))
64
(if (not (false-if-exception
65
(begin (symlink (test-file) (test-symlink)) #t)))
66
(display "cannot create symlink, lstat test skipped\n")
68
;; not much to test, except that it works
69
(->bool (lstat (test-symlink))))))
72
;;; opendir and friends
75
(with-test-prefix "opendir"
77
(with-test-prefix "root directory"
78
(let ((d (opendir "/")))
80
(string? (readdir d)))
81
(pass-if "all entries are strings"
83
(let ((f (readdir d)))
96
(with-test-prefix "stat"
98
(with-test-prefix "filename"
101
(call-with-output-file (test-file)
103
(display "hello" port)))
104
(eqv? 5 (stat:size (stat (test-file))))))
106
(with-test-prefix "file descriptor"
109
(call-with-output-file (test-file)
111
(display "hello" port)))
112
(let* ((fd (open-fdes (test-file) O_RDONLY))
115
(eqv? 5 (stat:size st)))))
117
(with-test-prefix "port"
120
(call-with-output-file (test-file)
122
(display "hello" port)))
123
(let* ((port (open-file (test-file) "r+"))
126
(eqv? 5 (stat:size st))))))
128
(delete-file (test-file))
129
(delete-file (test-symlink))