From 615c6667d12c7972fb08288e1ffaecea8abb16a8 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Mon, 25 Apr 2011 07:31:54 -0400 Subject: [PATCH] make unit test results look good And make passed tests accessible --- unit_tests.php | 25 +++++++++++---- unit_tests/template.html | 77 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 80 insertions(+), 22 deletions(-) diff --git a/unit_tests.php b/unit_tests.php index 62f7d6b..ee62e20 100644 --- a/unit_tests.php +++ b/unit_tests.php @@ -23,15 +23,13 @@ require_once('code/wfpl/messages.php'); # call this to declare that a unit test has passed function unit_test_passed($msg) { - if(isset($GLOBALS['unit_tests_verbose']) && $GLOBALS['unit_tests_verbose'] > 1) { - message("PASSED: $msg"); - } + $GLOBALS['unit_tests_passed_msgs'][] = $msg; $GLOBALS['unit_tests_passed'] += 1; } # call this to declare that a unit test has failed function unit_test_failed($msg) { - message("FAILED: $msg"); + $GLOBALS['unit_tests_failed_msgs'][] = $msg; $GLOBALS['unit_tests_failed'] += 1; } @@ -79,17 +77,32 @@ function file_run_unit_tests($filename) { # tests in that file. It should print a message() about each test that failed, # and return the number of tests that failed. function run_unit_tests($directory, $basenames) { + $files = array(); $GLOBALS['unit_tests_passed'] = 0; $GLOBALS['unit_tests_failed'] = 0; $basenames = explode(' ', $basenames); foreach($basenames as $basename) { + $GLOBALS['unit_tests_passed_msgs'] = array(); + $GLOBALS['unit_tests_failed_msgs'] = array(); + $already_passed = $GLOBALS['unit_tests_passed']; + $already_failed = $GLOBALS['unit_tests_failed']; $filename = "$directory/$basename.php"; - message("running tests in $filename"); file_run_unit_tests($filename); + $files[] = array( + 'file' => $filename, + 'fails' => columnize($GLOBALS['unit_tests_failed_msgs']), + 'passes' => columnize($GLOBALS['unit_tests_passed_msgs']), + 'count_passed' => $GLOBALS['unit_tests_passed'] - $already_passed, + 'count_failed' => $GLOBALS['unit_tests_failed'] - $already_failed + ); } $passed = $GLOBALS['unit_tests_passed']; $failed = $GLOBALS['unit_tests_failed']; - message("tests finished with $passed test" . enc_s($passed) . " passed and $GLOBALS[unit_tests_failed] test" . enc_s($failed) . " failed"); + tem_set('unit_tests', array( + 'files' => $files, + 'total_passed' => $passed, + 'total_failed' => $failed + )); } # Call this to unit test wfpl. By default it tests everything, or you can pass diff --git a/unit_tests/template.html b/unit_tests/template.html index 9a61084..1ba97c7 100644 --- a/unit_tests/template.html +++ b/unit_tests/template.html @@ -2,22 +2,45 @@ - wfpl unit test results - - + wfpl unit test results + + + @@ -26,5 +49,27 @@
~data htmlbrnbsp~
+ + + +
+
running tests in ~file html~
+ +
FAIL: ~data htmlbrnbsp~
+ + +
~count_failed once_else {~All ~}~~count_passed html~ test~count_passed s~ passed
+
+ +
PASS: ~data htmlbrnbsp~
+ +
+ +
+ +
Total Passed: ~total_passed html~, Total Failed: ~total_failed html~
+ + + -- 1.7.10.4