From: jakubvrana Date: Wed, 24 Jun 2009 10:02:12 +0000 (+0000) Subject: Coverage uses the same cookie so must live in the same directory X-Git-Tag: v3.0.0~769 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=91156d1a1d671036b363a879a723b1c2871cdb51;p=adminer.git Coverage uses the same cookie so must live in the same directory git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@756 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- diff --git a/adminer/coverage.inc.php b/adminer/coverage.inc.php new file mode 100644 index 00000000..dc0bbf4e --- /dev/null +++ b/adminer/coverage.inc.php @@ -0,0 +1,70 @@ +]+)~', $s, $matches); + foreach ($matches[1] as $val) { + if ($val{0} == "/") { + array_pop($return); + } elseif (substr($val, -1) != "/") { + $return[] = $val; + } + } + return $return; +} + +page_header("Coverage", (extension_loaded("xdebug") ? "" : "Xdebug has to be enabled.")); + +if ($_GET["coverage"] === "0") { + unset($_SESSION["coverage"]); // disable coverage if it is not available + if (extension_loaded("xdebug")) { + $_SESSION["coverage"] = array(); + echo "

Coverage started.

\n"; + } +} elseif (preg_match('~^(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) { + // highlight single file + $filename = $_GET["coverage"]; + $cov = $_SESSION["coverage"][realpath($filename)]; + $file = explode("
", highlight_file($filename, true)); + unset($prev_color); + $s = ""; + for ($l=0; $l <= count($file); $l++) { + $line = $file[$l]; + $color = "#C0FFC0"; // tested + switch ($cov[$l+1]) { + case -1: $color = "#FFC0C0"; break; // untested + case -2: $color = "Silver"; break; // dead code + case null: $color = ""; break; // not executable + } + if (!isset($prev_color)) { + $prev_color = $color; + } + if ($prev_color != $color || !isset($line)) { + echo "" . $s; + $open_tags = xhtml_open_tags($s); + foreach (array_reverse($open_tags) as $tag) { + echo ""; + } + echo "\n"; + $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : ""); + $prev_color = $color; + } + $s .= "$line
\n"; + } +} else { + // display list of files + echo "\n"; + foreach (array_merge(glob("*.php"), glob("include/*.php")) as $filename) { + $cov = $_SESSION["coverage"][realpath($filename)]; + $ratio = 0; + if (isset($cov)) { + $values = array_count_values($cov); + $ratio = round(100 - 100 * $values[-1] / count($cov)); + } + echo "\n"; + } + echo "
$ratio%$filename
\n"; + echo '

Start new coverage

' . "\n"; +} +page_footer("auth"); +exit; diff --git a/adminer/index.php b/adminer/index.php index 23e1e1de..04f28c8d 100644 --- a/adminer/index.php +++ b/adminer/index.php @@ -26,10 +26,6 @@ if (isset($_SESSION["coverage"])) { } xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); register_shutdown_function('save_coverage'); - if ($_GET["start"]) { - // included from ../coverage.php - return; - } } // disable magic quotes to be able to use database escaping function if (get_magic_quotes_gpc()) { @@ -55,6 +51,9 @@ include "./include/functions.inc.php"; include "./include/lang.inc.php"; include "./lang/$LANG.inc.php"; include "./include/design.inc.php"; +if (isset($_GET["coverage"])) { + include "./coverage.inc.php"; +} include "./include/pdo.inc.php"; include "./include/mysql.inc.php"; include "./include/auth.inc.php"; diff --git a/compile.php b/compile.php index 3f2ce468..36624937 100644 --- a/compile.php +++ b/compile.php @@ -171,6 +171,7 @@ if ($_SERVER["argc"] > 1) { $filename = "adminer" . ($_COOKIE["adminer_lang"] ? "-$_COOKIE[adminer_lang]" : "") . ".php"; $file = file_get_contents(dirname(__FILE__) . "/adminer/index.php"); +$file = preg_replace('(' . str_replace(' ', '\\s*', preg_quote(' if (isset($_GET["coverage"])) { include "./coverage.inc.php"; }')) . ')', '', $file); $file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file); $file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file); if ($_COOKIE["adminer_lang"]) { diff --git a/coverage.php b/coverage.php deleted file mode 100644 index 055261f3..00000000 --- a/coverage.php +++ /dev/null @@ -1,80 +0,0 @@ -]+)~', $s, $matches); - foreach ($matches[1] as $val) { - if ($val{0} == "/") { - array_pop($return); - } elseif (substr($val, -1) != "/") { - $return[] = $val; - } - } - return $return; -} - -if (!extension_loaded("xdebug")) { - echo "

Xdebug has to be enabled.

\n"; -} - -if ($_GET["start"]) { - unset($_SESSION["coverage"]); - xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); - $_SESSION["coverage"] = array(); - include "./adminer/index.php"; - header("Location: ."); - exit; -} -if (preg_match('~^(include/)?[-_.a-z0-9]+$~i', $_GET["filename"])) { - // highlight single file - $filename = "adminer/$_GET[filename]"; - $cov = $_SESSION["coverage"][realpath($filename)]; - $file = explode("
", highlight_file($filename, true)); - unset($prev_color); - $s = ""; - for ($l=0; $l <= count($file); $l++) { - $line = $file[$l]; - $color = "#C0FFC0"; // tested - switch ($cov[$l+1]) { - case -1: $color = "#FFC0C0"; break; // untested - case -2: $color = "Silver"; break; // dead code - case null: $color = ""; break; // not executable - } - if (!isset($prev_color)) { - $prev_color = $color; - } - if ($prev_color != $color || !isset($line)) { - echo "" . $s; - $open_tags = xhtml_open_tags($s); - foreach (array_reverse($open_tags) as $tag) { - echo ""; - } - echo "\n"; - $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : ""); - $prev_color = $color; - } - $s .= "$line
\n"; - } -} else { - // display list of files - echo "\n"; - foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php")) as $filename) { - $cov = $_SESSION["coverage"][realpath($filename)]; - $filename = substr($filename, 8); - $ratio = 0; - if (isset($cov)) { - $values = array_count_values($cov); - $ratio = round(100 - 100 * $values[-1] / count($cov)); - } - echo "\n"; - } - echo "
$ratio%$filename
\n"; - echo "

Start new coverage (requires Xdebug)

\n"; -} diff --git a/tests/0-login.html b/tests/0-login.html index aac7c98a..d1fe3c71 100644 --- a/tests/0-login.html +++ b/tests/0-login.html @@ -13,7 +13,7 @@ open - /adminer/coverage.php?start=1 + /adminer/adminer/?coverage=0 diff --git a/tests/logout.html b/tests/logout.html index 1e1480cd..d3358b14 100644 --- a/tests/logout.html +++ b/tests/logout.html @@ -38,7 +38,7 @@ open - /adminer/coverage.php + /adminer/adminer/?coverage=