Skip to content

Commit a15623e

Browse files
Use suitable characters in log filenames.
This is a patch from Per Bothner, which he describes like this: The default "simple runner" creates a log file whose name is the append of the suite-name (from the initial test-begin) and ".log". But the 'suite-name' is a string that can contain characters not suitable for a filename. This patch "sanitizes" the filename, converting questionable characters to #\_.
1 parent 207c968 commit a15623e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

testing.scm

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,30 @@
318318
(display "%%%% Starting test ")
319319
(display suite-name)
320320
(if test-log-to-file
321-
(let* ((log-file-name
322-
(if (string? test-log-to-file) test-log-to-file
323-
(string-append suite-name ".log")))
321+
(let* ((log-name (if (string? test-log-to-file) test-log-to-file
322+
(string-append suite-name ".log")))
323+
;; Replace "bad" characters in log file name with #\_
324+
(fix-invalid-char
325+
(lambda (ch)
326+
(if (or (char-alphabetic? ch)
327+
(char-numeric? ch)
328+
(char=? ch #\Space)
329+
(char=? ch #\-)
330+
(char=? ch #\+)
331+
(char=? ch #\_)
332+
(char=? ch #\.)
333+
(char=? ch #\,))
334+
ch
335+
#\_)))
336+
(log-file-name
337+
(cond-expand (r7rs
338+
(string-map fix-invalid-char log-name))
339+
(else
340+
(let ((t (string-copy log-name))
341+
(tlen (string-length log-name)))
342+
(do ((i 0 (+ i 1))) ((>= i tlen) t)
343+
(string-set! t i (fix-invalid-char
344+
(string-ref t i))))))))
324345
(log-file
325346
(cond-expand (mzscheme
326347
(open-output-file log-file-name 'truncate/replace))

0 commit comments

Comments
 (0)