diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2017-05-30 12:03:54 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2017-06-16 17:08:22 +0200 |
| commit | fa73c1937364872560c509f02b3d7648a5bed006 (patch) | |
| tree | 9b7c54b4c60ff8bab560ff3948fb74de4aed8b25 /tests/syscalls.scm | |
| parent | 8cdbaebcbd34259793cdfb34b03f2f84db82a825 (diff) | |
syscalls: Add 'scandir*'.
* guix/build/syscalls.scm (%struct-dirent-header): New C struct.
(string->pointer/utf-8, pointer->string/utf-8): New procedures.
(opendir*, closedir*, readdir*, scandir*): New procedures.
* tests/syscalls.scm ("scandir*, ENOENT")
("scandir*, ASCII file names", "scandir*, UTF-8 file names")
("scandir*, properties): New tests.
Diffstat (limited to 'tests/syscalls.scm')
| -rw-r--r-- | tests/syscalls.scm | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/syscalls.scm b/tests/syscalls.scm index e20f0600bc6..8c048e61094 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm | |||
| @@ -24,6 +24,8 @@ | |||
| 24 | #:use-module (srfi srfi-1) | 24 | #:use-module (srfi srfi-1) |
| 25 | #:use-module (srfi srfi-26) | 25 | #:use-module (srfi srfi-26) |
| 26 | #:use-module (srfi srfi-64) | 26 | #:use-module (srfi srfi-64) |
| 27 | #:use-module (system foreign) | ||
| 28 | #:use-module ((ice-9 ftw) #:select (scandir)) | ||
| 27 | #:use-module (ice-9 match)) | 29 | #:use-module (ice-9 match)) |
| 28 | 30 | ||
| 29 | ;; Test the (guix build syscalls) module, although there's not much that can | 31 | ;; Test the (guix build syscalls) module, although there's not much that can |
| @@ -184,6 +186,64 @@ | |||
| 184 | (status:exit-val status)))) | 186 | (status:exit-val status)))) |
| 185 | (eq? #t result)))))))) | 187 | (eq? #t result)))))))) |
| 186 | 188 | ||
| 189 | (test-equal "scandir*, ENOENT" | ||
| 190 | ENOENT | ||
| 191 | (catch 'system-error | ||
| 192 | (lambda () | ||
| 193 | (scandir* "/does/not/exist")) | ||
| 194 | (lambda args | ||
| 195 | (system-error-errno args)))) | ||
| 196 | |||
| 197 | (test-equal "scandir*, ASCII file names" | ||
| 198 | (scandir (dirname (search-path %load-path "guix/base32.scm")) | ||
| 199 | (const #t) string<?) | ||
| 200 | (match (scandir* (dirname (search-path %load-path "guix/base32.scm"))) | ||
| 201 | (((names . properties) ...) | ||
| 202 | names))) | ||
| 203 | |||
| 204 | (test-equal "scandir*, UTF-8 file names" | ||
| 205 | '("." ".." "α" "λ") | ||
| 206 | (call-with-temporary-directory | ||
| 207 | (lambda (directory) | ||
| 208 | ;; Wrap 'creat' to make sure that we really pass a UTF-8-encoded file | ||
| 209 | ;; name to the system call. | ||
| 210 | (let ((creat (pointer->procedure int | ||
| 211 | (dynamic-func "creat" (dynamic-link)) | ||
| 212 | (list '* int)))) | ||
| 213 | (creat (string->pointer (string-append directory "/α") | ||
| 214 | "UTF-8") | ||
| 215 | #o644) | ||
| 216 | (creat (string->pointer (string-append directory "/λ") | ||
| 217 | "UTF-8") | ||
| 218 | #o644) | ||
| 219 | (let ((locale (setlocale LC_ALL))) | ||
| 220 | (dynamic-wind | ||
| 221 | (lambda () | ||
| 222 | ;; Make sure that even in a C locale we get the right result. | ||
| 223 | (setlocale LC_ALL "C")) | ||
| 224 | (lambda () | ||
| 225 | (match (scandir* directory) | ||
| 226 | (((names . properties) ...) | ||
| 227 | names))) | ||
| 228 | (lambda () | ||
| 229 | (setlocale LC_ALL locale)))))))) | ||
| 230 | |||
| 231 | (test-assert "scandir*, properties" | ||
| 232 | (let ((directory (dirname (search-path %load-path "guix/base32.scm")))) | ||
| 233 | (every (lambda (entry name) | ||
| 234 | (match entry | ||
| 235 | ((name2 . properties) | ||
| 236 | (and (string=? name2 name) | ||
| 237 | (let* ((full (string-append directory "/" name)) | ||
| 238 | (stat (lstat full)) | ||
| 239 | (inode (assoc-ref properties 'inode)) | ||
| 240 | (type (assoc-ref properties 'type))) | ||
| 241 | (and (= inode (stat:ino stat)) | ||
| 242 | (or (eq? type 'unknown) | ||
| 243 | (eq? type (stat:type stat))))))))) | ||
| 244 | (scandir* directory) | ||
| 245 | (scandir directory (const #t) string<?)))) | ||
| 246 | |||
| 187 | (false-if-exception (delete-file temp-file)) | 247 | (false-if-exception (delete-file temp-file)) |
| 188 | (test-equal "fcntl-flock wait" | 248 | (test-equal "fcntl-flock wait" |
| 189 | 42 ; the child's exit status | 249 | 42 ; the child's exit status |
