~ chicken-core (chicken-5) 2f409e0c238dfbd75eedfd24ecc5190414442807


commit 2f409e0c238dfbd75eedfd24ecc5190414442807
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Thu Sep 2 08:03:39 2021 +0200
Commit:     Mario Domenech Goulart <mario@parenteses.org>
CommitDate: Sun Sep 5 14:09:21 2021 +0200

    Ensure all ports are closed in tests when deleting the file
    
    Under Windows, read-lines-test.scm and posix-tests.scm would
    fail with "permission denied" upon deletion of the output file,
    but that's because there was still an open file handle to it
    (and on Windows you can't delete open files).
    
    In read-lines-test.scm, it is my favorite Scheme footgun:
    call-with-input-file doesn't close its port when the dynamic
    extent is exited via other ways than a regular procedure return.
    
    In posix-tests.scm it was a more mundane error - we opened a
    file using the descriptor-returning POSIX procedure file-open,
    but never closed the descriptor.
    
    Signed-off-by: Mario Domenech Goulart <mario@parenteses.org>

diff --git a/tests/posix-tests.scm b/tests/posix-tests.scm
index 361f55c1..26f495e7 100644
--- a/tests/posix-tests.scm
+++ b/tests/posix-tests.scm
@@ -98,7 +98,7 @@
                          (let ((mode (file-creation-mode)))
                            (set! (file-creation-mode) umask)
                            (delete-file* "posix-tests.out")
-                           (file-open "posix-tests.out" open/creat given ...)
+                           (file-close (file-open "posix-tests.out" open/creat given ...))
                            (assert (equal? (file-permissions "posix-tests.out") expected))
                            (set! (file-creation-mode) mode))))))
   ;; default file mode
diff --git a/tests/read-lines-tests.scm b/tests/read-lines-tests.scm
index 28cdd223..e107c26f 100644
--- a/tests/read-lines-tests.scm
+++ b/tests/read-lines-tests.scm
@@ -46,8 +46,11 @@ EOF
 (test-error
  "with an invalid second argument (max)"
  (call-with-input-file input-test-file
-  (lambda (port)
-    (read-lines port 2.0))))
+   (lambda (port)
+     (dynamic-wind
+	 void
+	 (lambda () (read-lines port 2.0))
+	 (lambda () (close-input-port port))))))
 
 (test-end "read-lines")
 
Trap