Re: [Boston.pm] test::something that captures/hide expected stderr
David Cantrell <[email protected]> Mon, 7 Mar 2022 19:15:45 +0000
| Newsgroups | gmane.comp.lang.perl.perl-mongers.boston |
|---|---|
| Message-ID | <[email protected]> |
On 07/03/2022 19:03, email-2Ro/Dj86MvDSUeElwK9/[email protected] wrote: > Another issue I'm running into is that I'm doing a lot of negative testing. > I'm testing a module I wrote and making sure it errors out when given > bad data. > According to Test::More, the way to do that is: > > ok !eval {myfun("bad", "data"); 1}, 'test bad data'; > > The annoying thing is that myfunc() prints out a bunch of error messages > which show up on my terminal when I run mytest.pl script. > So, I run mytest.pl, see a bunch of errors, and it's not immediately clear > those messages are expected. The best tool for this is Capture::Tiny. You can capture STDOUT and STDERR into variables and then check that they are as expected. See for example https://metacpan.org/release/DCANTRELL/CPAN-FindDependencies-3.10/source/t/cpandeps-diff-script.t -- David Cantrell