aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-11-16 02:59:01 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2023-11-22 00:00:05 +0100
commitda8a0584ee322399a16c2cd24709c1418909085c (patch)
tree1d7e4aaf2a50bd383441aec2f7081e0f69704fec
parentRemove unused open-{input,output}-port. (diff)
downloadcalp-da8a0584ee322399a16c2cd24709c1418909085c.tar.gz
calp-da8a0584ee322399a16c2cd24709c1418909085c.tar.xz
Add tests for io utilities.
-rw-r--r--tests/test-module-tree/README.md2
-rw-r--r--tests/unit/util/io.scm36
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/test-module-tree/README.md b/tests/test-module-tree/README.md
index 07cdca5d..4af3b5a9 100644
--- a/tests/test-module-tree/README.md
+++ b/tests/test-module-tree/README.md
@@ -2,3 +2,5 @@ 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.
diff --git a/tests/unit/util/io.scm b/tests/unit/util/io.scm
new file mode 100644
index 00000000..f06fb3bd
--- /dev/null
+++ b/tests/unit/util/io.scm
@@ -0,0 +1,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))