aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/util/io.scm
blob: f06fb3bd6a0789d576d3581afd49f00079157b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(define-module (test io)
  :use-module (srfi srfi-64)
  :use-module (srfi srfi-64 test-error)
  :use-module (srfi srfi-88)
  :use-module (hnh util io))

(test-equal "read-lines"
  '("Test module tree"
    "================"
    ""
    "This directory contains test data, primarily for the module-introspection."
    ""
    "Changing any of these files requires a full re-run of all tests.")
  (call-with-input-file "tests/test-module-tree/README.md"
    read-lines))

;;; TODO how do you even unit test these?
;;; TODO with-atomic-output-to-file
;;; TODO call-with-tmpfile

;;; This is technically implementation dependant, since the
;;; string definition of a newline is unspecified by RnRs.
(test-group "displayln"
  (test-equal "Hello\n"
    (with-output-to-string
      (lambda () (displayln "Hello"))))
  (test-equal "World\n"
    (call-with-output-string
      (lambda (p) (displayln "World" p)))))

(test-group "->port"
  (test-assert (port? (->port (current-input-port))))
  (test-assert (port? (->port "Hello, World")))
  (test-error 'misc-error (->port 1)))

'((hnh util io))