CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
'print' Output When Running Test::More Tests

 



zoetus
New User

Jul 8, 2014, 7:36 AM

Post #1 of 4 (513 views)
'print' Output When Running Test::More Tests Can't Post

Hello!

For some reason, if I try to insert any 'print' calls anywhere in code that's being called in a test, I don't see any output. I understand I can use 'diag' in the unit test itself, but what if I want to inspect some value nested deep in the call hierarchy?


Zhris
Enthusiast

Jul 8, 2014, 3:10 PM

Post #2 of 4 (492 views)
Re: [zoetus] 'print' Output When Running Test::More Tests [In reply to] Can't Post

Hi,

This will perhaps help: http://stackoverflow.com/questions/1538260/how-can-i-unit-test-perl-functions-that-print-to-the-screen

Regards,

Chris


(This post was edited by Zhris on Jul 8, 2014, 3:12 PM)


zoetus
New User

Jul 8, 2014, 3:19 PM

Post #3 of 4 (475 views)
Re: [Zhris] 'print' Output When Running Test::More Tests [In reply to] Can't Post

I guess that would work, but it seems a bit silly that we have to write all this extra code just to get 'print' to behave as it normally should. I don't really care about capturing print output or inspecting it; I just want to be able insert print calls for quick debugging and actually see them in the terminal window.

Does anyone know why Test::More is actually doing this?


Zhris
Enthusiast

Jul 8, 2014, 4:15 PM

Post #4 of 4 (448 views)
Re: [zoetus] 'print' Output When Running Test::More Tests [In reply to] Can't Post

From the documentation (update: this doesn't actually explain how Test::More prevents output, I can't figure out from the source code how it does):

Quote
Test::Builder (which powers Test::More) duplicates STDOUT and STDERR. So any changes to them, including changing their output disciplines, will not be seem [sic] by Test::More.


And for your question:

Quote
Does anyone know why Test::More is actually doing this


Test prints would be muddied / intermingled within your own prints (not just your debug ones), which in most cases would be undesirable. Also, The purpose of a test is not to check output or debug your code, your code should be assumed working. I personally write a test and a usage, the usage being a quick rough script which usually uses the module etc for its intended purpose. Or if I don't have time to write a usage, I'll debug directly with my production script.

I suggest that you do not print debug statements to STDOUT. I would make use of a logging module such as Log::Log4perl and ensure calls to $log->debug( ) are directed to an appropriate handle.

Regards,

Chris


(This post was edited by Zhris on Jul 8, 2014, 5:36 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives