From 06af22b0c153f0c965b27fa674033f5bbaf5b015 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 13 Mar 2021 06:42:54 +0100 Subject: [PATCH] custom diagnostics in example test failure Replace constant "Failed test at line" by a more interesting report of source location and result discrepancy. --- t/examples.t | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/t/examples.t b/t/examples.t index 0b5e778..ae3e7c9 100755 --- a/t/examples.t +++ b/t/examples.t @@ -2,7 +2,12 @@ use 5.014; use warnings; use re '/ms'; + use Test::More; +{ # silence fail diagnostics because of single caller + no warnings 'redefine'; + sub Test::Builder::_ok_debug {} +} my %CMDARGS = ( ping => '-c 1', @@ -46,9 +51,11 @@ while (readline $input) { # run and report unexpected results ok(eval { - qx($cmd) or return; - return $? == 0; - }, $name) or diag($cmd); + my $output = qx($cmd); + $? == 0 or die "error status ", $? >> 8, "\n"; + length $output or die "empty output\n"; + return 1; + }, $name) or diag("Failed command\n$cmd\nfrom $filename line $.: $@"); } done_testing(); -- 2.30.0