Lesson #2 from the real world
Working with streams is hard.
In particular, they are not as composable as I initially thought.
A small peculiarity is closing streams: I had a stream sink in stdout
and kept getting an error.
It turns out that closing a stream in the library cascaded.
Hence, it also closed the stdout
stream.
Naturally, my testing library kept writing to stdout
which, in turn, yielded a write after close error.
It turns out the solution was to apply good testing habits: A test should not write to stdout
.
Instead, a simple sink was written, and the stream was directed to it.
That allowed the increased benefit of measuring the stream and adding assertions to have the stream is expected to behave.
Sometimes problems can be solved by progressing over them. Weird.
Please remember always to have compassion for other programmers and becurious about lessons.An obvious point for one programmer might be an epiphany for another.
Over and out Mads