~ chicken-core (master) 99b1223ee4164252c17c8e93711f3e67a0b8adfd


commit 99b1223ee4164252c17c8e93711f3e67a0b8adfd
Author:     Mario Domenech Goulart <mario@parenteses.org>
AuthorDate: Sun Nov 30 15:16:11 2025 +0100
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Tue Dec 2 10:42:44 2025 +0100

    Re-add tests/test-create-temporary-file.scm
    
    test-create-temporary-file.scm was removed in 860f8d764457b8
    (presumably because it on the way to test C6 on Windows).
    
    Re-add the tests, but explicitly disable them on all Windows variants.
    The disablement is now done in the Scheme code, as runtests.bat
    doesn't exist in C6.
    
    Signed-off-by: felix <felix@call-with-current-continuation.org>

diff --git a/distribution/manifest b/distribution/manifest
index dc5b7b2b..785b5d1f 100644
--- a/distribution/manifest
+++ b/distribution/manifest
@@ -216,6 +216,7 @@ tests/specialization-test-1.scm
 tests/specialization-test-2.scm
 tests/specialization-test-2.types
 tests/specialization.expected
+tests/test-create-temporary-file.scm
 tests/test-irregex.scm
 tests/re-tests.txt
 tests/lolevel-tests.scm
diff --git a/tests/runtests.sh b/tests/runtests.sh
index 7753ae1f..8b4b93ea 100755
--- a/tests/runtests.sh
+++ b/tests/runtests.sh
@@ -439,6 +439,9 @@ $interpret -s file-access-tests.scm
 echo "======================================== find-files tests ..."
 $interpret -bnq test-find-files.scm
 
+echo "======================================== create-temporary-file tests ..."
+$interpret -bnq test-create-temporary-file.scm
+
 echo "======================================== record-renaming tests ..."
 $interpret -bnq record-rename-test.scm
 
diff --git a/tests/test-create-temporary-file.scm b/tests/test-create-temporary-file.scm
new file mode 100644
index 00000000..d60394b3
--- /dev/null
+++ b/tests/test-create-temporary-file.scm
@@ -0,0 +1,39 @@
+(import (chicken file)
+        (chicken pathname)
+        (chicken platform)
+        (chicken process-context))
+
+;; Skip this test on Windows altogether, regardless of Windows variant
+(when (eq? (software-type) 'windows)
+  (print "Skipping test-create-temporary-file.scm due to problematic unsetenv behaviour on Windows")
+  (exit 0))
+
+(define (with-environment-variable var val thunk)
+  (let ((old-val (get-environment-variable var)))
+    (set-environment-variable! var val)
+     (thunk)
+     (if old-val
+         (set-environment-variable! var old-val)
+         (unset-environment-variable! var))))
+
+(let ((tmp (create-temporary-file)))
+  (delete-file tmp)
+  (assert (pathname-directory tmp)))
+
+;; Assert that changes to the environment variables used by
+;; create-temporary-file and create-temporary-directory get used (see
+;; https://bugs.call-cc.org/ticket/1830).
+;;
+;; Here the use of "" as value of TMPDIR is because
+;; (pathname-directory (make-pathname "" filename)) => #f
+(with-environment-variable "TMPDIR" ""
+  (lambda ()
+    (let ((tmp (create-temporary-file)))
+      (delete-file tmp)
+      (assert (not (pathname-directory tmp))))))
+
+(with-environment-variable "TMPDIR" ""
+  (lambda ()
+    (let ((tmp (create-temporary-directory)))
+      (delete-directory tmp)
+      (assert (not (pathname-directory tmp))))))
Trap