JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
unit_test_func requires that type matches
[wfpl.git] / unit_tests.php
index d092962..62f7d6b 100644 (file)
@@ -35,6 +35,19 @@ function unit_test_failed($msg) {
        $GLOBALS['unit_tests_failed'] += 1;
 }
 
+function backslashinate($str) {
+       return '"' . addcslashes($str, "\0..\37\"\\\177..\377") . '"';
+}
+
+function backslashinate_each($a) {
+       foreach($a as &$v) {
+               $v = backslashinate($v);
+       }
+
+       return $a;
+}
+       
+
 # use this function to unit-test a function
 # real prototype: ($name, $args..., $correct)
 function unit_test_func() {
@@ -42,11 +55,11 @@ function unit_test_func() {
        $function = array_shift($args);
        $correct = array_pop($args);
        $result = call_user_func_array($function, $args);
-       $message = "$function(" . join(', ', $args) . ") returned $result";
-       if($result == $correct) {
+       $message = "$function(" . join(', ', backslashinate_each($args)) . ") returned " . backslashinate($result);
+       if($result === $correct) {
                unit_test_passed($message);
        } else {
-               unit_test_failed($message . " instead of $correct");
+               unit_test_failed($message . " instead of " . backslashinate($correct));
        }
 }
 
@@ -82,7 +95,7 @@ function run_unit_tests($directory, $basenames) {
 # Call this to unit test wfpl. By default it tests everything, or you can pass
 # a space-separated list of the basenames of the files in code/wfpl/unit_tests/
 # that you'd like to run.
-function unit_test_wfpl($basenames = 'format db misc') {
+function unit_test_wfpl($basenames = 'format db misc encode') {
        tem_load('code/wfpl/unit_tests/template.html');
        run_unit_tests('code/wfpl/unit_tests', $basenames);
        display_messages();