geoff 2004/10/25 18:24:52
Modified: perl-framework/Apache-Test/lib/Apache TestConfigPHP.pm Log: major overhaul from chris shiflett get skip() working, among other things Revision Changes Path 1.6 +99 -91 httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfigPHP.pm Index: TestConfigPHP.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfigPHP.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TestConfigPHP.pm 25 Oct 2004 17:19:11 -0000 1.5 +++ TestConfigPHP.pm 26 Oct 2004 01:24:52 -0000 1.6 @@ -183,109 +183,73 @@ __DATA__ <?php -# Based on work from Andy Lester: -# http://use.perl.org/~petdance/journal/14227 - -$test = 0; -$num_failures = 0; -$no_plan = false; - +# based on initial work from Andy Lester +# +# extensive rework by Chris Shiflett + +$_no_plan = false; +$_num_failures = 0; +$_num_skips = 0; +$_test = 0; + register_shutdown_function('_test_end'); - -function ok($condition, $name = '') + +function diag($lines) { - global $test; - global $num_failures; - $test++; - - # FIXME: There may be a better way to do this. - $caller = debug_backtrace(); - if (basename($caller['0']['file']) == 'more.php') - { - $file = $caller['1']['file']; - $line = $caller['1']['line']; - } - else - { - $file = $caller['0']['file']; - $line = $caller['0']['line']; - } - - if (!$condition) - { - echo "not ok $test"; - $num_failures++; - } - else - { - echo "ok $test"; - } - - if (!empty($name)) + if (is_string($lines)) { - echo " - $name"; + $lines = explode("\n", $lines); } - - echo "\n"; - - if (!$condition) + + foreach ($lines as $str) { - echo "# Failed test ($file at line $line)\n"; + echo "# $str\n"; } - - return $condition; -} - -function pass($name = '') -{ - return ok(true, $name); } - + function fail($name = '') { return ok(false, $name); } - -function skip($msg, $num) -{ - for ($i = 0; $i < $num; $i++) - { - pass("# SKIP $msg"); - } -} - + function is($actual, $expected, $name = '') { $ok = ($expected == $actual); ok($ok, $name); + if (!$ok) { diag(" got: '$actual'"); diag(" expected: '$expected'"); } + return $ok; } - + function isnt($actual, $dontwant, $name = '') { $ok = ($actual != $dontwant); ok($ok, $name); + if (!$ok) { diag("Didn't want '$actual'"); } + return $ok; } - + function isa_ok($object, $class, $name = null) { if (isset($object)) { $actual = get_class($object); + if (!isset($name)) { $name = "Object is of type $class"; } + return is(get_class($object), strtolower($class), $name); } else @@ -293,7 +257,7 @@ return fail('object is undefined'); } } - + function like($string, $regex, $name='') { $ok = ok(preg_match($regex, $string), $name); @@ -304,51 +268,95 @@ diag(" doesn't match '$regex'"); } + return $ok; } - -function diag($lines) + +function no_plan() { - if (is_string($lines)) + global $_no_plan; + $_no_plan = true; +} + +function ok($condition, $name = '') +{ + global $_test; + global $_num_failures; + global $_num_skips; + $_test++; + $caller = debug_backtrace(); + + if ($_num_skips) { - # Use explode() when there is a literal match. - $lines = explode("\n", $lines); + $_num_skips--; + return true; } - - foreach ($lines as $str) + + if (basename($caller['0']['file']) == 'more.php') { - echo "# $str\n"; + $file = $caller['1']['file']; + $line = $caller['1']['line']; + } + else + { + $file = $caller['0']['file']; + $line = $caller['0']['line']; + } + + $file = str_replace($_SERVER['SERVER_ROOT'], 't', $file); + + if (!$condition) + { + echo "not ok $_test"; + $_num_failures++; + } + else + { + echo "ok $_test"; + } + + if (!empty($name)) + { + echo " - $name"; } + + echo "\n"; + + if (!$condition) + { + echo "# Failed test ($file at line $line)\n"; + } + + return $condition; } - + +function pass($name = '') +{ + return ok(true, $name); +} + function plan($num_tests) { echo "1..$num_tests\n"; } - -function no_plan() + +function skip($msg, $num) { - global $no_plan; - $no_plan = true; + global $_num_skips; + + for ($i = 0; $i < $num; $i++) + { + pass("# SKIP $msg"); + } + + $_num_skips = $num; } - + function _test_end() { - if ($no_plan) - { - echo "1..$test\n"; - } - - $ver = phpversion(); - if (version_compare(phpversion(), '4.2.2' ) > 0) - { - global $num_failures; - # FIXME: This reeks of Perl - exit($num_failures > 254 ? 254 : $num_failures); - } - else + if ($_no_plan) { - # Don't return anything + echo "1..$_test\n"; } } ?>