$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() {
$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));
}
}
# 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();