From 2177f3f6c54d34e257db1efc53cee3beba6b7af6 Mon Sep 17 00:00:00 2001 From: Michael Gran Date: Mon, 24 Mar 2025 21:43:28 -0700 Subject: [PATCH] filesys.test: fixes for copy-file test on MinGW In the copy-file test, is uses call-with-input-file and get-string-all to retrieve file contents. Since the file is not opened in binary mode, CRLF line ending may be added when writing and then reading the string back from the filesystem. * test-suite/tests/filesys.test (normalize-newlines): new helper function ("copy file: copy-file dest content"): pass even if CRLF line endings are added ("copy file: read only dest"): handle posibility of geteuid not being defined --- test-suite/tests/filesys.test | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test-suite/tests/filesys.test b/test-suite/tests/filesys.test index 7afa87569..f32a023a0 100644 --- a/test-suite/tests/filesys.test +++ b/test-suite/tests/filesys.test @@ -46,6 +46,18 @@ (chmod file (logior (stat:mode (stat file)) #o200))) (delete-file file))) +(define (normalize-newlines s) + "Returns a copy of the input string, replacing any #\return #\newline +pairs with #\newline." + (let loop ((i 0) (result '())) + (if (< i (string-length s)) + (if (and (< (+ i 1) (string-length s)) + (char=? (string-ref s i) #\return) + (char=? (string-ref s (+ i 1)) #\newline)) + (loop (+ i 2) (cons #\newline result)) + (loop (+ i 1) (cons (string-ref s i) result))) + (list->string (reverse result))))) + ;;; ;;; copy-file ;;; @@ -69,8 +81,14 @@ (with-test-prefix "successful copy" (copy-file src dest) (pass-if-equal "copy-file dest content" msg - (call-with-input-file dest get-string-all))) - (unless (zero? (geteuid)) + ;; Since call-with-input-file is always text mode, it may have + ;; \r\n on MinGW. + (normalize-newlines + (call-with-input-file dest get-string-all)))) + ;; Checking for a geteuid of zero is testing of the user + ;; is root, making the chmod to read-only meaningless. geteuid is + ;; not defined in MinGW. + (unless (and (defined? 'geteuid) (zero? (geteuid))) (with-test-prefix "read only dest" (chmod dest #o444) (with-exception-handler