~ chicken-core (master) /tests/test-create-temporary-file.scm


 1(import (chicken file)
 2        (chicken pathname)
 3        (chicken platform)
 4        (chicken process-context))
 5
 6;; Skip this test on Windows altogether, regardless of Windows variant
 7(when (eq? (software-type) 'windows)
 8  (print "Skipping test-create-temporary-file.scm due to problematic unsetenv behaviour on Windows")
 9  (exit 0))
10
11(define (with-environment-variable var val thunk)
12  (let ((old-val (get-environment-variable var)))
13    (set-environment-variable! var val)
14     (thunk)
15     (if old-val
16         (set-environment-variable! var old-val)
17         (unset-environment-variable! var))))
18
19(let ((tmp (create-temporary-file)))
20  (delete-file tmp)
21  (assert (pathname-directory tmp)))
22
23;; Assert that changes to the environment variables used by
24;; create-temporary-file and create-temporary-directory get used (see
25;; https://bugs.call-cc.org/ticket/1830).
26;;
27;; Here the use of "" as value of TMPDIR is because
28;; (pathname-directory (make-pathname "" filename)) => #f
29(with-environment-variable "TMPDIR" ""
30  (lambda ()
31    (let ((tmp (create-temporary-file)))
32      (delete-file tmp)
33      (assert (not (pathname-directory tmp))))))
34
35(with-environment-variable "TMPDIR" ""
36  (lambda ()
37    (let ((tmp (create-temporary-directory)))
38      (delete-directory tmp)
39      (assert (not (pathname-directory tmp))))))
Trap