~ chicken-core (chicken-5) /tests/test-create-temporary-file.scm
Trap1(import (chicken file)
2 (chicken pathname)
3 (chicken process-context))
4
5(define (with-environment-variable var val thunk)
6 (let ((old-val (get-environment-variable var)))
7 (set-environment-variable! var val)
8 (thunk)
9 (if old-val
10 (set-environment-variable! var old-val)
11 (unset-environment-variable! var))))
12
13(let ((tmp (create-temporary-file)))
14 (delete-file tmp)
15 (assert (pathname-directory tmp)))
16
17;; Assert that changes to the environment variables used by
18;; create-temporary-file and create-temporary-directory get used (see
19;; https://bugs.call-cc.org/ticket/1830).
20;;
21;; Here the use of "" as value of TMPDIR is because
22;; (pathname-directory (make-pathname "" filename)) => #f
23(with-environment-variable "TMPDIR" ""
24 (lambda ()
25 (let ((tmp (create-temporary-file)))
26 (delete-file tmp)
27 (assert (not (pathname-directory tmp))))))
28
29(with-environment-variable "TMPDIR" ""
30 (lambda ()
31 (let ((tmp (create-temporary-directory)))
32 (delete-directory tmp)
33 (assert (not (pathname-directory tmp))))))