I would like to write unit-test for a method that outputs to standard output. I already changed the code, so it prints an instance of the past File by default, not stdout . The only thing I am missing is some instance of File in memory that I could pass. Does something like this exist? Any recommendation? I would like this to work:
import std.stdio; void greet(File f = stdout) { f.writeln("hello!"); } unittest { greet(inmemory); assert(inmemory.content == "hello!\n") } void main() { greet(); }
Any other approach for unit testing code that prints to stdout ?
source share