I write some test cases for a function foo.
Some test cases fail, and to debug and find the problem, I wish to print some debug messages inside function foo.
My attempts are:
- Print to stdout, later I learned that
Test::Moredoes not want me to modify stdout. - Print to stderr, my messages are not shown when I execute
make test
I learned about diag note and explain, I did diag('test') inside foo however the message is not printed. Examples of them show that they are to be used inside test case function.
I really want to print a message in my foo when I run test case for it!
So what is the most correct way to achieve this?
Thanks for everyone’s attention.
I figured this out finally..
In my function
In my test:
And I did not see ‘hahahaha’ output when I ran
perl Makefile.PL; make testI read perldoc of Test::More and noticed that the example usages of diag/note are from the test file, not from the tested function,and that confused me little bit: I thought diag/note could ONLY be used in test case, not in the tested function.
Then why did not ‘hahahah’ print out at first place?
The reason is that… I did not
use Test::More;in the package offoo. After put the line in there, I could see ‘hahahah’ in output.I did not receive warning about
diag not found.