Suppress Test::More Output For Use In Nagios

by Thomas Beutel

I needed a quick way to check for XML well-formedness in a Perl Nagios script and I found that Test::XML has a test called is_well_formed_xml($xml) that does the job nicely. The only problem was that as part of the Test::More framework, Test::XML outputs test results (as it should). In my case though, I just wanted to perform the test. So I was able to suppress the output like so:


Here is a larger code fragment if you are interested:

use Getopt::Euclid;
use Test::XML;
use Test::More;


my $warning = $ARGV{'-w'};
my $critical = $ARGV{'-c'};

my $xml = `curl --silent ''`;

my $well_formed = is_well_formed_xml($xml);

if (!$well_formed) {
print "CRITICAL - XML not well formed\n";

# ... checking XML content for OK and WARNING states not shown here

I’m sure there are other quick ways to check for well-formedness but this is working well for me.