capturing output in memory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

capturing output in memory

Mark Volkmann
For the purpose of writing unit tests for code that writes to a stream  
I want to use something other than a FileStream that will allow me to  
write to it just like FileStream, but will just hold the data in  
memory. When I'm finished writing, I want to retrieve everything I've  
written as a single String. Is there a class that does that?

---
Mark Volkmann




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: capturing output in memory

Randal L. Schwartz
>>>>> "Mark" == Mark Volkmann <[hidden email]> writes:

Mark> For the purpose of writing unit tests for code that writes to a stream I
Mark> want to use something other than a FileStream that will allow me to
Mark> write to it just like FileStream, but will just hold the data in
Mark> memory. When I'm finished writing, I want to retrieve everything I've
Mark> written as a single String. Is there a class that does that?

myStream = WriteStream new.
" use myStream as if it were a FileStream "
myString := myStream contents.

That's the nice part about the various protocol families.  It mostly just
works.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: capturing output in memory

Randal L. Schwartz
>>>>> "Randal" == Randal L Schwartz <[hidden email]> writes:

Randal> myStream = WriteStream new.

Sorry.  (WriteStream on: '')

Randal> " use myStream as if it were a FileStream "
Randal> myString := myStream contents.

Randal> That's the nice part about the various protocol families.  It mostly just
Randal> works.

Randal> --
Randal> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Randal> <[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Randal> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
Randal> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners