1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 22:40:34 +02:00

Untabify some test files.

* test-suite/tests/ports.test: Untabify.
* test-suite/tests/posix.test: Untabify.
* test-suite/tests/r6rs-files.test: Untabify.
This commit is contained in:
Eli Zaretskii 2014-07-03 21:02:23 +03:00
parent 9235f805fa
commit 8c6b62e7d5
3 changed files with 274 additions and 274 deletions

View file

@ -53,12 +53,12 @@
(let loop ((chars '())) (let loop ((chars '()))
(let ((char (read-char port))) (let ((char (read-char port)))
(if (eof-object? char) (if (eof-object? char)
(list->string (reverse! chars)) (list->string (reverse! chars))
(loop (cons char chars)))))) (loop (cons char chars))))))
(define (read-file filename) (define (read-file filename)
(let* ((port (open-input-file filename)) (let* ((port (open-input-file filename))
(string (read-all port))) (string (read-all port)))
(close-port port) (close-port port)
string)) string))
@ -95,7 +95,7 @@
;;; Write out an s-expression, and read it back. ;;; Write out an s-expression, and read it back.
(let ((string '("From fairest creatures we desire increase," (let ((string '("From fairest creatures we desire increase,"
"That thereby beauty's rose might never die,")) "That thereby beauty's rose might never die,"))
(filename (test-file))) (filename (test-file)))
(let ((port (open-output-file filename))) (let ((port (open-output-file filename)))
(write string port) (write string port)
@ -103,7 +103,7 @@
(let ((port (open-input-file filename))) (let ((port (open-input-file filename)))
(let ((in-string (read port))) (let ((in-string (read port)))
(pass-if "file: write and read back list of strings" (pass-if "file: write and read back list of strings"
(equal? string in-string))) (equal? string in-string)))
(close-port port)) (close-port port))
(delete-file filename)) (delete-file filename))
@ -115,7 +115,7 @@
(close-port port)) (close-port port))
(let ((in-string (read-file filename))) (let ((in-string (read-file filename)))
(pass-if "file: write and read back characters" (pass-if "file: write and read back characters"
(equal? string in-string))) (equal? string in-string)))
(delete-file filename)) (delete-file filename))
;;; Buffered input/output port with seeking. ;;; Buffered input/output port with seeking.
@ -124,17 +124,17 @@
(display "J'Accuse" port) (display "J'Accuse" port)
(seek port -1 SEEK_CUR) (seek port -1 SEEK_CUR)
(pass-if "file: r/w 1" (pass-if "file: r/w 1"
(char=? (read-char port) #\e)) (char=? (read-char port) #\e))
(pass-if "file: r/w 2" (pass-if "file: r/w 2"
(eof-object? (read-char port))) (eof-object? (read-char port)))
(seek port -1 SEEK_CUR) (seek port -1 SEEK_CUR)
(write-char #\x port) (write-char #\x port)
(seek port 7 SEEK_SET) (seek port 7 SEEK_SET)
(pass-if "file: r/w 3" (pass-if "file: r/w 3"
(char=? (read-char port) #\x)) (char=? (read-char port) #\x))
(seek port -2 SEEK_END) (seek port -2 SEEK_END)
(pass-if "file: r/w 4" (pass-if "file: r/w 4"
(char=? (read-char port) #\s)) (char=? (read-char port) #\s))
(close-port port) (close-port port)
(delete-file filename)) (delete-file filename))
@ -144,17 +144,17 @@
(display "J'Accuse" port) (display "J'Accuse" port)
(seek port -1 SEEK_CUR) (seek port -1 SEEK_CUR)
(pass-if "file: ub r/w 1" (pass-if "file: ub r/w 1"
(char=? (read-char port) #\e)) (char=? (read-char port) #\e))
(pass-if "file: ub r/w 2" (pass-if "file: ub r/w 2"
(eof-object? (read-char port))) (eof-object? (read-char port)))
(seek port -1 SEEK_CUR) (seek port -1 SEEK_CUR)
(write-char #\x port) (write-char #\x port)
(seek port 7 SEEK_SET) (seek port 7 SEEK_SET)
(pass-if "file: ub r/w 3" (pass-if "file: ub r/w 3"
(char=? (read-char port) #\x)) (char=? (read-char port) #\x))
(seek port -2 SEEK_END) (seek port -2 SEEK_END)
(pass-if "file: ub r/w 4" (pass-if "file: ub r/w 4"
(char=? (read-char port) #\s)) (char=? (read-char port) #\s))
(close-port port) (close-port port)
(delete-file filename)) (delete-file filename))
@ -163,24 +163,24 @@
(port (open-output-file filename))) (port (open-output-file filename)))
(display "J'Accuse" port) (display "J'Accuse" port)
(pass-if "file: out tell" (pass-if "file: out tell"
(= (seek port 0 SEEK_CUR) 8)) (= (seek port 0 SEEK_CUR) 8))
(seek port -1 SEEK_CUR) (seek port -1 SEEK_CUR)
(write-char #\x port) (write-char #\x port)
(close-port port) (close-port port)
(let ((iport (open-input-file filename))) (let ((iport (open-input-file filename)))
(pass-if "file: in tell 0" (pass-if "file: in tell 0"
(= (seek iport 0 SEEK_CUR) 0)) (= (seek iport 0 SEEK_CUR) 0))
(read-char iport) (read-char iport)
(pass-if "file: in tell 1" (pass-if "file: in tell 1"
(= (seek iport 0 SEEK_CUR) 1)) (= (seek iport 0 SEEK_CUR) 1))
(unread-char #\z iport) (unread-char #\z iport)
(pass-if "file: in tell 0 after unread" (pass-if "file: in tell 0 after unread"
(= (seek iport 0 SEEK_CUR) 0)) (= (seek iport 0 SEEK_CUR) 0))
(pass-if "file: unread char still there" (pass-if "file: unread char still there"
(char=? (read-char iport) #\z)) (char=? (read-char iport) #\z))
(seek iport 7 SEEK_SET) (seek iport 7 SEEK_SET)
(pass-if "file: in last char" (pass-if "file: in last char"
(char=? (read-char iport) #\x)) (char=? (read-char iport) #\x))
(close-port iport)) (close-port iport))
(delete-file filename)) (delete-file filename))
@ -188,20 +188,20 @@
(let* ((filename (test-file)) (let* ((filename (test-file))
(port (open-output-file filename))) (port (open-output-file filename)))
(display (string #\nul (integer->char 255) (integer->char 128) (display (string #\nul (integer->char 255) (integer->char 128)
#\nul) port) #\nul) port)
(close-port port) (close-port port)
(let* ((port (open-input-file filename)) (let* ((port (open-input-file filename))
(line (read-line port))) (line (read-line port)))
(pass-if "file: read back NUL 1" (pass-if "file: read back NUL 1"
(char=? (string-ref line 0) #\nul)) (char=? (string-ref line 0) #\nul))
(pass-if "file: read back 255" (pass-if "file: read back 255"
(char=? (string-ref line 1) (integer->char 255))) (char=? (string-ref line 1) (integer->char 255)))
(pass-if "file: read back 128" (pass-if "file: read back 128"
(char=? (string-ref line 2) (integer->char 128))) (char=? (string-ref line 2) (integer->char 128)))
(pass-if "file: read back NUL 2" (pass-if "file: read back NUL 2"
(char=? (string-ref line 3) #\nul)) (char=? (string-ref line 3) #\nul))
(pass-if "file: EOF" (pass-if "file: EOF"
(eof-object? (read-char port))) (eof-object? (read-char port)))
(close-port port)) (close-port port))
(delete-file filename)) (delete-file filename))
@ -211,11 +211,11 @@
(test-string "one line more or less")) (test-string "one line more or less"))
(write-line test-string port) (write-line test-string port)
(let* ((in-port (open-input-file filename)) (let* ((in-port (open-input-file filename))
(line (read-line in-port))) (line (read-line in-port)))
(close-port in-port) (close-port in-port)
(close-port port) (close-port port)
(pass-if "file: line buffering" (pass-if "file: line buffering"
(string=? line test-string))) (string=? line test-string)))
(delete-file filename)) (delete-file filename))
;;; read-line should use the port encoding (not the locale encoding). ;;; read-line should use the port encoding (not the locale encoding).
@ -573,19 +573,19 @@
;;; ungetting characters and strings. ;;; ungetting characters and strings.
(with-input-from-string "walk on the moon\nmoon" (with-input-from-string "walk on the moon\nmoon"
(lambda () (lambda ()
(read-char) (read-char)
(unread-char #\a (current-input-port)) (unread-char #\a (current-input-port))
(pass-if "unread-char" (pass-if "unread-char"
(char=? (read-char) #\a)) (char=? (read-char) #\a))
(read-line) (read-line)
(let ((replacenoid "chicken enchilada")) (let ((replacenoid "chicken enchilada"))
(unread-char #\newline (current-input-port)) (unread-char #\newline (current-input-port))
(unread-string replacenoid (current-input-port)) (unread-string replacenoid (current-input-port))
(pass-if "unread-string" (pass-if "unread-string"
(string=? (read-line) replacenoid))) (string=? (read-line) replacenoid)))
(pass-if "unread residue" (pass-if "unread residue"
(string=? (read-line) "moon")))) (string=? (read-line) "moon"))))
;;; non-blocking mode on a port. create a pipe and set O_NONBLOCK on ;;; non-blocking mode on a port. create a pipe and set O_NONBLOCK on
;;; the reading end. try to read a byte: should get EAGAIN or ;;; the reading end. try to read a byte: should get EAGAIN or
@ -594,13 +594,13 @@
(r (car p))) (r (car p)))
(fcntl r F_SETFL (logior (fcntl r F_GETFL) O_NONBLOCK)) (fcntl r F_SETFL (logior (fcntl r F_GETFL) O_NONBLOCK))
(pass-if "non-blocking-I/O" (pass-if "non-blocking-I/O"
(catch 'system-error (catch 'system-error
(lambda () (read-char r) #f) (lambda () (read-char r) #f)
(lambda (key . args) (lambda (key . args)
(and (eq? key 'system-error) (and (eq? key 'system-error)
(let ((errno (car (list-ref args 3)))) (let ((errno (car (list-ref args 3))))
(or (= errno EAGAIN) (or (= errno EAGAIN)
(= errno EWOULDBLOCK)))))))) (= errno EWOULDBLOCK))))))))
;;;; Pipe (popen) ports. ;;;; Pipe (popen) ports.
@ -610,7 +610,7 @@
(in-string (read-all pipe))) (in-string (read-all pipe)))
(close-pipe pipe) (close-pipe pipe)
(pass-if "pipe: read" (pass-if "pipe: read"
(equal? in-string "Howdy there, partner!\n"))) (equal? in-string "Howdy there, partner!\n")))
;;; Run a command, send some output to it, and see if it worked. ;;; Run a command, send some output to it, and see if it worked.
(let* ((filename (test-file)) (let* ((filename (test-file))
@ -620,7 +620,7 @@
(close-pipe pipe) (close-pipe pipe)
(let ((in-string (read-file filename))) (let ((in-string (read-file filename)))
(pass-if "pipe: write" (pass-if "pipe: write"
(equal? in-string "Mommy, why does everybody have a bomb?\n"))) (equal? in-string "Mommy, why does everybody have a bomb?\n")))
(delete-file filename)) (delete-file filename))
(pass-if-equal "pipe, fdopen, and _IOLBF" (pass-if-equal "pipe, fdopen, and _IOLBF"
@ -657,70 +657,70 @@
;; Write text to a string port. ;; Write text to a string port.
(let* ((string "Howdy there, partner!") (let* ((string "Howdy there, partner!")
(in-string (call-with-output-string (in-string (call-with-output-string
(lambda (port) (lambda (port)
(display string port) (display string port)
(newline port))))) (newline port)))))
(pass-if "display text" (pass-if "display text"
(equal? in-string (string-append string "\n")))) (equal? in-string (string-append string "\n"))))
;; Write an s-expression to a string port. ;; Write an s-expression to a string port.
(let* ((sexpr '("more utterly random text" 1729 #(a vector) 3.1415926)) (let* ((sexpr '("more utterly random text" 1729 #(a vector) 3.1415926))
(in-sexpr (in-sexpr
(call-with-input-string (call-with-output-string (call-with-input-string (call-with-output-string
(lambda (port) (lambda (port)
(write sexpr port))) (write sexpr port)))
read))) read)))
(pass-if "write/read sexpr" (pass-if "write/read sexpr"
(equal? in-sexpr sexpr))) (equal? in-sexpr sexpr)))
;; seeking and unreading from an input string. ;; seeking and unreading from an input string.
(let ((text "that text didn't look random to me")) (let ((text "that text didn't look random to me"))
(call-with-input-string text (call-with-input-string text
(lambda (p) (lambda (p)
(pass-if "input tell 0" (pass-if "input tell 0"
(= (seek p 0 SEEK_CUR) 0)) (= (seek p 0 SEEK_CUR) 0))
(read-char p) (read-char p)
(pass-if "input tell 1" (pass-if "input tell 1"
(= (seek p 0 SEEK_CUR) 1)) (= (seek p 0 SEEK_CUR) 1))
(unread-char #\x p) (unread-char #\x p)
(pass-if "input tell back to 0" (pass-if "input tell back to 0"
(= (seek p 0 SEEK_CUR) 0)) (= (seek p 0 SEEK_CUR) 0))
(pass-if "input ungetted char" (pass-if "input ungetted char"
(char=? (read-char p) #\x)) (char=? (read-char p) #\x))
(seek p 0 SEEK_END) (seek p 0 SEEK_END)
(pass-if "input seek to end" (pass-if "input seek to end"
(= (seek p 0 SEEK_CUR) (= (seek p 0 SEEK_CUR)
(string-length text))) (string-length text)))
(unread-char #\x p) (unread-char #\x p)
(pass-if "input seek to beginning" (pass-if "input seek to beginning"
(= (seek p 0 SEEK_SET) 0)) (= (seek p 0 SEEK_SET) 0))
(pass-if "input reread first char" (pass-if "input reread first char"
(char=? (read-char p) (char=? (read-char p)
(string-ref text 0)))))) (string-ref text 0))))))
;; seeking an output string. ;; seeking an output string.
(let* ((text (string-copy "123456789")) (let* ((text (string-copy "123456789"))
(len (string-length text)) (len (string-length text))
(result (call-with-output-string (result (call-with-output-string
(lambda (p) (lambda (p)
(pass-if "output tell 0" (pass-if "output tell 0"
(= (seek p 0 SEEK_CUR) 0)) (= (seek p 0 SEEK_CUR) 0))
(display text p) (display text p)
(pass-if "output tell end" (pass-if "output tell end"
(= (seek p 0 SEEK_CUR) len)) (= (seek p 0 SEEK_CUR) len))
(pass-if "output seek to beginning" (pass-if "output seek to beginning"
(= (seek p 0 SEEK_SET) 0)) (= (seek p 0 SEEK_SET) 0))
(write-char #\a p) (write-char #\a p)
(seek p -1 SEEK_END) (seek p -1 SEEK_END)
(pass-if "output seek to last char" (pass-if "output seek to last char"
(= (seek p 0 SEEK_CUR) (= (seek p 0 SEEK_CUR)
(- len 1))) (- len 1)))
(write-char #\b p))))) (write-char #\b p)))))
(string-set! text 0 #\a) (string-set! text 0 #\a)
(string-set! text (- len 1) #\b) (string-set! text (- len 1) #\b)
(pass-if "output check" (pass-if "output check"
(string=? text result))) (string=? text result)))
(pass-if "encoding failure leads to exception" (pass-if "encoding failure leads to exception"
;; Prior to 2.0.6, this would trigger a deadlock in `scm_mkstrport'. ;; Prior to 2.0.6, this would trigger a deadlock in `scm_mkstrport'.
@ -1003,10 +1003,10 @@
(close-port out-port)) (close-port out-port))
(list (open-input-file port-loop-temp) (list (open-input-file port-loop-temp)
(open-input-pipe (string-append "cat " port-loop-temp)) (open-input-pipe (string-append "cat " port-loop-temp))
(call-with-input-string text (lambda (x) x)) (call-with-input-string text (lambda (x) x))
;; We don't test soft ports at the moment. ;; We don't test soft ports at the moment.
)) ))
(define port-list-names '("file" "pipe" "string")) (define port-list-names '("file" "pipe" "string"))
@ -1014,55 +1014,55 @@
(define (test-line-counter text second-line final-column) (define (test-line-counter text second-line final-column)
(with-test-prefix "line counter" (with-test-prefix "line counter"
(let ((ports (input-port-list text))) (let ((ports (input-port-list text)))
(for-each (for-each
(lambda (port port-name) (lambda (port port-name)
(with-test-prefix port-name (with-test-prefix port-name
(pass-if "at beginning of input" (pass-if "at beginning of input"
(= (port-line port) 0)) (= (port-line port) 0))
(pass-if "read first character" (pass-if "read first character"
(eqv? (read-char port) #\x)) (eqv? (read-char port) #\x))
(pass-if "after reading one character" (pass-if "after reading one character"
(= (port-line port) 0)) (= (port-line port) 0))
(pass-if "read first newline" (pass-if "read first newline"
(eqv? (read-char port) #\newline)) (eqv? (read-char port) #\newline))
(pass-if "after reading first newline char" (pass-if "after reading first newline char"
(= (port-line port) 1)) (= (port-line port) 1))
(pass-if "second line read correctly" (pass-if "second line read correctly"
(equal? (read-line port) second-line)) (equal? (read-line port) second-line))
(pass-if "read-line increments line number" (pass-if "read-line increments line number"
(= (port-line port) 2)) (= (port-line port) 2))
(pass-if "read-line returns EOF" (pass-if "read-line returns EOF"
(let loop ((i 0)) (let loop ((i 0))
(cond (cond
((eof-object? (read-line port)) #t) ((eof-object? (read-line port)) #t)
((> i 20) #f) ((> i 20) #f)
(else (loop (+ i 1)))))) (else (loop (+ i 1))))))
(pass-if "line count is 5 at EOF" (pass-if "line count is 5 at EOF"
(= (port-line port) 5)) (= (port-line port) 5))
(pass-if "column is correct at EOF" (pass-if "column is correct at EOF"
(= (port-column port) final-column)))) (= (port-column port) final-column))))
ports port-list-names) ports port-list-names)
(for-each close-port ports) (for-each close-port ports)
(delete-file port-loop-temp)))) (delete-file port-loop-temp))))
(with-test-prefix "newline" (with-test-prefix "newline"
(test-line-counter (test-line-counter
(string-append "x\n" (string-append "x\n"
"He who receives an idea from me, receives instruction\n" "He who receives an idea from me, receives instruction\n"
"himself without lessening mine; as he who lights his\n" "himself without lessening mine; as he who lights his\n"
"taper at mine, receives light without darkening me.\n" "taper at mine, receives light without darkening me.\n"
" --- Thomas Jefferson\n") " --- Thomas Jefferson\n")
"He who receives an idea from me, receives instruction" "He who receives an idea from me, receives instruction"
0)) 0))
(with-test-prefix "no newline" (with-test-prefix "no newline"
(test-line-counter (test-line-counter
(string-append "x\n" (string-append "x\n"
"He who receives an idea from me, receives instruction\n" "He who receives an idea from me, receives instruction\n"
"himself without lessening mine; as he who lights his\n" "himself without lessening mine; as he who lights his\n"
"taper at mine, receives light without darkening me.\n" "taper at mine, receives light without darkening me.\n"
" --- Thomas Jefferson\n" " --- Thomas Jefferson\n"
"no newline here") "no newline here")
"He who receives an idea from me, receives instruction" "He who receives an idea from me, receives instruction"
15))) 15)))
@ -1072,28 +1072,28 @@
(with-test-prefix "port-line and port-column for output ports" (with-test-prefix "port-line and port-column for output ports"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(pass-if "at beginning of input" (pass-if "at beginning of input"
(and (= (port-line port) 0) (and (= (port-line port) 0)
(= (port-column port) 0))) (= (port-column port) 0)))
(write-char #\x port) (write-char #\x port)
(pass-if "after writing one character" (pass-if "after writing one character"
(and (= (port-line port) 0) (and (= (port-line port) 0)
(= (port-column port) 1))) (= (port-column port) 1)))
(write-char #\newline port) (write-char #\newline port)
(pass-if "after writing first newline char" (pass-if "after writing first newline char"
(and (= (port-line port) 1) (and (= (port-line port) 1)
(= (port-column port) 0))) (= (port-column port) 0)))
(display text port) (display text port)
(pass-if "line count is 5 at end" (pass-if "line count is 5 at end"
(= (port-line port) 5)) (= (port-line port) 5))
(pass-if "column is correct at end" (pass-if "column is correct at end"
(= (port-column port) final-column))))) (= (port-column port) final-column)))))
(test-output-line-counter (test-output-line-counter
(string-append "He who receives an idea from me, receives instruction\n" (string-append "He who receives an idea from me, receives instruction\n"
"himself without lessening mine; as he who lights his\n" "himself without lessening mine; as he who lights his\n"
"taper at mine, receives light without darkening me.\n" "taper at mine, receives light without darkening me.\n"
" --- Thomas Jefferson\n" " --- Thomas Jefferson\n"
"no newline here") "no newline here")
15) 15)
(with-test-prefix "port-column" (with-test-prefix "port-column"
@ -1102,115 +1102,115 @@
(pass-if "x" (pass-if "x"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "x" port) (display "x" port)
(= 1 (port-column port)))) (= 1 (port-column port))))
(pass-if "\\a" (pass-if "\\a"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "\a" port) (display "\a" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\a" (pass-if "x\\a"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "x\a" port) (display "x\a" port)
(= 1 (port-column port)))) (= 1 (port-column port))))
(pass-if "\\x08 backspace" (pass-if "\\x08 backspace"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "\x08" port) (display "\x08" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\x08 backspace" (pass-if "x\\x08 backspace"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "x\x08" port) (display "x\x08" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "\\n" (pass-if "\\n"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "\n" port) (display "\n" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\n" (pass-if "x\\n"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "x\n" port) (display "x\n" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "\\r" (pass-if "\\r"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "\r" port) (display "\r" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\r" (pass-if "x\\r"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "x\r" port) (display "x\r" port)
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "\\t" (pass-if "\\t"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "\t" port) (display "\t" port)
(= 8 (port-column port)))) (= 8 (port-column port))))
(pass-if "x\\t" (pass-if "x\\t"
(let ((port (open-output-string))) (let ((port (open-output-string)))
(display "x\t" port) (display "x\t" port)
(= 8 (port-column port))))) (= 8 (port-column port)))))
(with-test-prefix "input" (with-test-prefix "input"
(pass-if "x" (pass-if "x"
(let ((port (open-input-string "x"))) (let ((port (open-input-string "x")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 1 (port-column port)))) (= 1 (port-column port))))
(pass-if "\\a" (pass-if "\\a"
(let ((port (open-input-string "\a"))) (let ((port (open-input-string "\a")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\a" (pass-if "x\\a"
(let ((port (open-input-string "x\a"))) (let ((port (open-input-string "x\a")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 1 (port-column port)))) (= 1 (port-column port))))
(pass-if "\\x08 backspace" (pass-if "\\x08 backspace"
(let ((port (open-input-string "\x08"))) (let ((port (open-input-string "\x08")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\x08 backspace" (pass-if "x\\x08 backspace"
(let ((port (open-input-string "x\x08"))) (let ((port (open-input-string "x\x08")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "\\n" (pass-if "\\n"
(let ((port (open-input-string "\n"))) (let ((port (open-input-string "\n")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\n" (pass-if "x\\n"
(let ((port (open-input-string "x\n"))) (let ((port (open-input-string "x\n")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "\\r" (pass-if "\\r"
(let ((port (open-input-string "\r"))) (let ((port (open-input-string "\r")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "x\\r" (pass-if "x\\r"
(let ((port (open-input-string "x\r"))) (let ((port (open-input-string "x\r")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 0 (port-column port)))) (= 0 (port-column port))))
(pass-if "\\t" (pass-if "\\t"
(let ((port (open-input-string "\t"))) (let ((port (open-input-string "\t")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 8 (port-column port)))) (= 8 (port-column port))))
(pass-if "x\\t" (pass-if "x\\t"
(let ((port (open-input-string "x\t"))) (let ((port (open-input-string "x\t")))
(while (not (eof-object? (read-char port)))) (while (not (eof-object? (read-char port))))
(= 8 (port-column port)))))) (= 8 (port-column port))))))
(with-test-prefix "port-line" (with-test-prefix "port-line"
@ -1219,7 +1219,7 @@
;; systems ;; systems
(pass-if "set most-positive-fixnum/2" (pass-if "set most-positive-fixnum/2"
(let ((n (quotient most-positive-fixnum 2)) (let ((n (quotient most-positive-fixnum 2))
(port (open-output-string))) (port (open-output-string)))
(set-port-line! port n) (set-port-line! port n)
(eqv? n (port-line port))))) (eqv? n (port-line port)))))
@ -1260,7 +1260,7 @@
(gc) (gc)
;; but they're still in the port table, so this sees them ;; but they're still in the port table, so this sees them
(port-for-each (lambda (port) (port-for-each (lambda (port)
(set! lst (cons port lst)))) (set! lst (cons port lst))))
;; this forces completion of the sweeping ;; this forces completion of the sweeping
(gc) (gc) (gc) (gc) (gc) (gc)
;; and (if the bug is present) the cells accumulated in LST are now ;; and (if the bug is present) the cells accumulated in LST are now
@ -1270,10 +1270,10 @@
(with-test-prefix (with-test-prefix
"fdes->port" "fdes->port"
(pass-if "fdes->ports finds port" (pass-if "fdes->ports finds port"
(let* ((port (open-file (test-file) "w")) (let* ((port (open-file (test-file) "w"))
(res (not (not (memq port (fdes->ports (port->fdes port))))))) (res (not (not (memq port (fdes->ports (port->fdes port)))))))
(close-port port) (close-port port)
res))) res)))
;;; ;;;
;;; seek ;;; seek
@ -1285,36 +1285,36 @@
(pass-if "SEEK_CUR" (pass-if "SEEK_CUR"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "abcde" port))) (display "abcde" port)))
(let ((port (open-file (test-file) "r"))) (let ((port (open-file (test-file) "r")))
(read-char port) (read-char port)
(seek port 2 SEEK_CUR) (seek port 2 SEEK_CUR)
(let ((res (eqv? #\d (read-char port)))) (let ((res (eqv? #\d (read-char port))))
(close-port port) (close-port port)
res))) res)))
(pass-if "SEEK_SET" (pass-if "SEEK_SET"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "abcde" port))) (display "abcde" port)))
(let ((port (open-file (test-file) "r"))) (let ((port (open-file (test-file) "r")))
(read-char port) (read-char port)
(seek port 3 SEEK_SET) (seek port 3 SEEK_SET)
(let ((res (eqv? #\d (read-char port)))) (let ((res (eqv? #\d (read-char port))))
(close-port port) (close-port port)
res))) res)))
(pass-if "SEEK_END" (pass-if "SEEK_END"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "abcde" port))) (display "abcde" port)))
(let ((port (open-file (test-file) "r"))) (let ((port (open-file (test-file) "r")))
(read-char port) (read-char port)
(seek port -2 SEEK_END) (seek port -2 SEEK_END)
(let ((res (eqv? #\d (read-char port)))) (let ((res (eqv? #\d (read-char port))))
(close-port port) (close-port port)
res))))) res)))))
;;; ;;;
;;; truncate-file ;;; truncate-file
@ -1332,63 +1332,63 @@
(pass-if-exception "flonum length" exception:wrong-type-arg (pass-if-exception "flonum length" exception:wrong-type-arg
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(truncate-file (test-file) 1.0)) (truncate-file (test-file) 1.0))
(pass-if "shorten" (pass-if "shorten"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(truncate-file (test-file) 1) (truncate-file (test-file) 1)
(eqv? 1 (stat:size (stat (test-file))))) (eqv? 1 (stat:size (stat (test-file)))))
(pass-if-exception "shorten to current pos" exception:miscellaneous-error (pass-if-exception "shorten to current pos" exception:miscellaneous-error
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(truncate-file (test-file)))) (truncate-file (test-file))))
(with-test-prefix "file descriptor" (with-test-prefix "file descriptor"
(pass-if "shorten" (pass-if "shorten"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(let ((fd (open-fdes (test-file) O_RDWR))) (let ((fd (open-fdes (test-file) O_RDWR)))
(truncate-file fd 1) (truncate-file fd 1)
(close-fdes fd)) (close-fdes fd))
(eqv? 1 (stat:size (stat (test-file))))) (eqv? 1 (stat:size (stat (test-file)))))
(pass-if "shorten to current pos" (pass-if "shorten to current pos"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(let ((fd (open-fdes (test-file) O_RDWR))) (let ((fd (open-fdes (test-file) O_RDWR)))
(seek fd 1 SEEK_SET) (seek fd 1 SEEK_SET)
(truncate-file fd) (truncate-file fd)
(close-fdes fd)) (close-fdes fd))
(eqv? 1 (stat:size (stat (test-file)))))) (eqv? 1 (stat:size (stat (test-file))))))
(with-test-prefix "file port" (with-test-prefix "file port"
(pass-if "shorten" (pass-if "shorten"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(let ((port (open-file (test-file) "r+"))) (let ((port (open-file (test-file) "r+")))
(truncate-file port 1) (truncate-file port 1)
(close-port port)) (close-port port))
(eqv? 1 (stat:size (stat (test-file))))) (eqv? 1 (stat:size (stat (test-file)))))
(pass-if "shorten to current pos" (pass-if "shorten to current pos"
(call-with-output-file (test-file) (call-with-output-file (test-file)
(lambda (port) (lambda (port)
(display "hello" port))) (display "hello" port)))
(let ((port (open-file (test-file) "r+"))) (let ((port (open-file (test-file) "r+")))
(read-char port) (read-char port)
(truncate-file port) (truncate-file port)
(close-port port)) (close-port port))
(eqv? 1 (stat:size (stat (test-file))))))) (eqv? 1 (stat:size (stat (test-file)))))))
@ -1402,11 +1402,11 @@
(read-delimited! "\n" c port 'concat) (read-delimited! "\n" c port 'concat)
(pass-if "read-delimited! reads a first line" (pass-if "read-delimited! reads a first line"
(string=? c "defdef\n!!!!!!!!!!!!!")) (string=? c "defdef\n!!!!!!!!!!!!!"))
(read-delimited! "\n" c port 'concat 3) (read-delimited! "\n" c port 'concat 3)
(pass-if "read-delimited! reads a first line" (pass-if "read-delimited! reads a first line"
(string=? c "defghighi\n!!!!!!!!!!")))))) (string=? c "defghighi\n!!!!!!!!!!"))))))
;;;; char-ready? ;;;; char-ready?
@ -1415,7 +1415,7 @@
"howdy" "howdy"
(lambda (port) (lambda (port)
(pass-if "char-ready? returns true on string port" (pass-if "char-ready? returns true on string port"
(char-ready? port)))) (char-ready? port))))
;;; This segfaults on some versions of Guile. We really should run ;;; This segfaults on some versions of Guile. We really should run
;;; the tests in a subprocess... ;;; the tests in a subprocess...
@ -1427,7 +1427,7 @@
port port
(lambda () (lambda ()
(pass-if "char-ready? returns true on string port as default port" (pass-if "char-ready? returns true on string port as default port"
(char-ready?)))))) (char-ready?))))))
;;;; pending-eof behavior ;;;; pending-eof behavior
@ -1518,15 +1518,15 @@
(with-test-prefix "closing current-input-port" (with-test-prefix "closing current-input-port"
(for-each (lambda (procedure name) (for-each (lambda (procedure name)
(with-input-from-port (with-input-from-port
(call-with-input-string "foo" (lambda (p) p)) (call-with-input-string "foo" (lambda (p) p))
(lambda () (lambda ()
(close-port (current-input-port)) (close-port (current-input-port))
(pass-if-exception name (pass-if-exception name
exception:wrong-type-arg exception:wrong-type-arg
(procedure))))) (procedure)))))
(list read read-char read-line) (list read read-char read-line)
'("read" "read-char" "read-line"))) '("read" "read-char" "read-line")))

View file

@ -70,9 +70,9 @@
(pass-if "filename string modified" (pass-if "filename string modified"
(let* ((template "T-XXXXXX") (let* ((template "T-XXXXXX")
(str (string-copy template)) (str (string-copy template))
(port (mkstemp! str)) (port (mkstemp! str))
(result (not (string=? str template)))) (result (not (string=? str template))))
(close-port port) (close-port port)
(delete-file str) (delete-file str)
result))) result)))

View file

@ -25,7 +25,7 @@
(with-test-prefix "delete-file" (with-test-prefix "delete-file"
(pass-if "delete-file deletes file" (pass-if "delete-file deletes file"
(let* ((port (mkstemp! "T-XXXXXX")) (let* ((port (mkstemp! "T-XXXXXX"))
(filename (port-filename port))) (filename (port-filename port)))
(close-port port) (close-port port)
(delete-file filename) (delete-file filename)
(not (file-exists? filename)))) (not (file-exists? filename))))
@ -34,9 +34,9 @@
(let ((success #f)) (let ((success #f))
(call/cc (call/cc
(lambda (continuation) (lambda (continuation)
(with-exception-handler (with-exception-handler
(lambda (condition) (lambda (condition)
(set! success (i/o-filename-error? condition)) (set! success (i/o-filename-error? condition))
(continuation)) (continuation))
(lambda () (delete-file ""))))) (lambda () (delete-file "")))))
success))) success)))