consider following io:
val io = (for{ userchoice <- getchar } yield if (userchoice == 'y') putstr("yes") else putstr("no")).flatmap(identity)
i trying test this:
val input: inputstream = new bytearrayinputstream(array('n', 'n')) // not sure why need 2 of them... system.setin(input) val output = new bytearrayoutputstream() system.setout(new java.io.printstream(output)) io.unsafeperformio() system.setin(new fileinputstream(filedescriptor.in)) system.setout(new printstream(new fileoutputstream(filedescriptor.out))) output.tostring ==== "no"
i using specs2 within sbt test. first time run test, passes. second time fails console has reached end of input
, sbt in weird state , need kill it.
i suppose there might kind of interaction sbt don't understand exactly. there better way test io?
for kind of interactions think worth developing "mini-language" using free monads , have 2 interpreters, 1 testing using id
monad , 1 production using io
monad.
Comments
Post a Comment