# 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;
}
# 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
<html>
<head>
- <title>wfpl unit test results</title>
- <meta name="robots" content="none">
- <style type="text/css">
- .row_even, .row_odd {
- font: 14px monospace;
- margin-top: -1px;
- border: 1px dotted black;
- padding: 5px;
- }
- .row_even {
- background-color: #ccf;
- }
- .row_odd {
- background-color: #cfc;
- }
- </style>
+ <title>wfpl unit test results</title>
+ <meta name="robots" content="none">
+ <style type="text/css">
+ .row_even, .row_odd, .error_even, .error_odd, .pass_even, .pass_odd {
+ font: 14px monospace;
+ margin-top: -1px;
+ border: 1px dotted black;
+ padding: 5px;
+ }
+ .row_even {
+ background-color: #ddf;
+ }
+ .row_odd {
+ background-color: #def;
+ }
+ .error_even {
+ font-family: monospace;
+ background-color: #fcc;
+ }
+ .error_odd {
+ font-family: monospace;
+ background-color: #fdb;
+ }
+ .pass_even {
+ font-family: monospace;
+ background-color: #cfc;
+ }
+ .pass_odd {
+ font-family: monospace;
+ background-color: #bfd;
+ }
+</style>
+<script>
+ function showpass(thus) {
+ var me = $(thus);
+ me.parent().next().show();
+ me.hide();
+ }
+</script>
</head>
<body>
<!--~wfpl_messages {~-->
<div class="row_~row evenodd~">~data htmlbrnbsp~</div>
<!--~}~-->
+
+ <!--~unit_tests {~-->
+ <!--~files {~-->
+ <div class="row_~row evenodd~">
+ <div class="file">running tests in <code>~file html~</code></div>
+ <!--~fails {~-->
+ <div class="error_~err evenodd~">FAIL: ~data htmlbrnbsp~</div>
+ <!--~}~-->
+ <!--~count_passed once_if {~-->
+ <div><a href="javascript:void(0)" onclick="showpass(this)">~count_failed once_else {~All ~}~~count_passed html~ test~count_passed s~ passed</a></div>
+ <div style="display: none">
+ <!--~passes {~-->
+ <div class="pass_~pass evenodd~">PASS: ~data htmlbrnbsp~</div>
+ <!--~}~-->
+ </div>
+ <!--~}~-->
+ </div>
+ <!--~}~-->
+ <div class="totals">Total Passed: ~total_passed html~, Total Failed: ~total_failed html~</div>
+ <!--~}~-->
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
</body>
</html>