dimanche 22 novembre 2015

chicken scheme - how do i temporarily capture data sent to standard output

I have a procedure that calls (display "foo")

I want to write a unit test for it, to confirm that it's sending the correct data there but display sends its input to Standard Output:

scheme (define (display x #!optional (port ##sys#standard-output)) (##sys#check-output-port port #t 'display) (##sys#print x #f port) )

Question: In other languages I might redefine standard output as something that just writes to a variable, and then set it back after the test. Is that the correct thing to do in chicken ? If so, how? If not, then what is the correct thing to do?

Note: passing something else in to display as a third parameter isn't an option because i'd have to alter the method I'm unit testing to do so.

Aucun commentaire:

Enregistrer un commentaire