From 49e92c1e66f9243c4bd41319006678fadcd268f2 Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Thu, 12 Oct 2023 16:06:14 +0000 Subject: [PATCH] Fix the failures and full reports * Make them look roughly like the progress report, with pass/fail status up front and failure reason on a separate line. * Greatly simplify the print-result-info generic. * Use the same indentation mechanism as the progress report. --- reports.dylan | 87 +++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 55 deletions(-) diff --git a/reports.dylan b/reports.dylan index 124faea..773b3dc 100644 --- a/reports.dylan +++ b/reports.dylan @@ -68,47 +68,36 @@ define function count-results-of-type end function; define method print-result-info - (result :: , stream :: , #key indent = "", test) - => () - let result-status = result.result-status; - let show-result? = if (test) test(result) else #t end; - if (show-result?) - format(stream, "\n%s%s %s", - indent, result.result-name, status-name(result-status)); - if (result-status == $passed - & instance?(result, )) - format(stream, " in %s seconds with %s bytes allocated.", - result-time(result), result-bytes(result) | "?"); - end if - end; -end method print-result-info; - -define method print-result-info - (result :: , stream :: , #key indent = "", test) - => () - next-method(); - let show-result? = if (test) test(result) else #t end; - let reason = result.result-reason; - if (show-result? & reason) - format(stream, "%s", reason); + (result :: , stream :: , #key test) => () + if (~test | test(result)) + let reason = result.result-reason; + let status = result.result-status; + format(stream, "%s%s: %s%s\n", + *indent*, + status.status-name.as-uppercase, + result.result-name, + if (status == $passed & instance?(result, )) + format-to-string(" in %ss and %s", + result.result-time, + format-bytes(result.result-bytes)) + else + "" + end); + if (reason) + format(stream, "%s%s%s\n", *indent*, $indent-step, reason); + end; end; - let subindent = concatenate(indent, " "); - for (subresult in result-subresults(result)) - print-result-info(subresult, stream, indent: subindent, test: test) - end -end method print-result-info; +end method; -// This 'after' method prints the reason for the result's failure define method print-result-info - (result :: , stream :: , #key indent = "", test) => () - ignore(indent); + (result :: , stream :: , #key test) => () next-method(); - let show-result? = if (test) test(result) else #t end; - let reason = result.result-reason; - if (show-result? & reason) - format(stream, "%s", reason); + dynamic-bind (*indent* = next-indent()) + for (subresult in result-subresults(result)) + print-result-info(subresult, stream, test: test) + end; end; -end method print-result-info; +end method; define function stats-summary (v :: limited(, of: )) @@ -132,15 +121,9 @@ define function stats-summary end function; define method print-result-info - (result :: , stream :: , #key indent = "", test) => () + (result :: , stream :: , #key test) => () if (~test | test(result)) - let result-status = result.result-status; - format(stream, "\n%s%s %s", - indent, result.result-name, status-name(result-status)); - if (result-status == $passed) - format(stream, " in %s seconds with %s bytes allocated.", - result-time(result), result-bytes(result) | "?"); - end if; + next-method(); let iteration-results = choose(rcurry(instance?, ), result-subresults(result)); @@ -155,16 +138,16 @@ define method print-result-info let (min-value :: , max-value :: , mean-value :: , median-value :: ) = stats-summary(iteration-times); - format(stream, "\n%s %d iterations, per iteration min %s seconds, mean %s seconds," - " median %s seconds, max %s seconds", - indent, iteration-times.size, + format(stream, "%s%s%d iterations, per iteration min %ss, mean %ss," + " median %ss, max %ss\n", + *indent*, $indent-step, iteration-times.size, float-time-to-string(min-value), float-time-to-string(mean-value), float-time-to-string(median-value), float-time-to-string(max-value)); end unless; end if; -end method print-result-info; +end method; /// Report functions @@ -232,13 +215,7 @@ end method; define method print-failures-report (result :: , stream :: ) => () if (result.result-status ~= $passed) - print-result-info(result, stream, - test: method (result) - select (result.result-status) - $passed, $skipped, $expected-failure => #f; - otherwise => #t; - end - end); + print-result-info(result, stream, test: compose(\~, result-passing?)); format(stream, "\n"); end; print-summary-report(result, stream);