From da8a0584ee322399a16c2cd24709c1418909085c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 16 Nov 2023 02:59:01 +0100 Subject: Add tests for io utilities. --- tests/unit/util/io.scm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/unit/util/io.scm (limited to 'tests/unit/util/io.scm') 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)) -- cgit v1.2.3