function parse_contents($name, $tests) { $lines = explode("\n", $tests); $current = 0; $pass = 0; $fail = 0; foreach ($lines as $lineno => $line) { if ($line == '') { continue; } else { if (preg_match('/^(\\d+)\\.\\.(\\d+)$/', $line, $matches)) { $from = $matches[1]; $to = $matches[2]; $count = $to - $from + 1; } else { if (preg_match('/^ok (\\d+)/', $line, $matches)) { $current++; $pass++; $test = $matches[1]; if ($test != $current) { notate("bad test! {$name} test {$test} (expected {$current})!"); } } else { if (preg_match('/^not ok (\\d+)/', $line, $matches)) { $current++; $fail++; $test = $matches[1]; if ($test != $current) { notate("bad test! {$name} test {$test} (expected {$current})!"); } } else { if (!preg_match('/^\\#/', $line)) { notate("unknown output format {$line} ({$name}:{$lineno})"); } } } } } } return "{$pass}/{$fail}/{$count}"; }
$test = ob_get_contents(); ob_end_clean(); $out = parse_contents($fn, $test); preg_match('/^(\\d+)\\/(\\d+)\\/(\\d+)$/', $out, $matches); $opass = $matches[1]; $ofail = $matches[2]; $oall = $matches[3]; $pass += $opass > $oall ? $oall : $opass; $fail += $ofail; $all += $oall; $name = "{$fn} ({$oall} subtests)"; if (!is($opass, $oall, $name)) { array_push($failed, $fn); } } notate("finished testing files"); is($pass, $all, "All {$all} subtests pass"); $allpass = is(count($failed), 0, 'Test failures is empty'); echo "\n"; if (!$allpass) { notate("Failed test files:"); foreach ($failed as $failure) { notate(" {$failure}"); } } list($endms, $ends) = explode(' ', microtime()); $slen = (int) $ends - (int) $starts; $mslen = (double) $endms - (double) $startms; $dur = $slen + $mslen; notate("Tests ran in {$dur}s.");