Merge branch 'R_2_0'
authorMichael Wallner <mike@php.net>
Fri, 11 Jul 2014 12:19:16 +0000 (14:19 +0200)
committerMichael Wallner <mike@php.net>
Fri, 11 Jul 2014 12:19:16 +0000 (14:19 +0200)
.gitignore
check_package-xml.php [new file with mode: 0755]
phpunit.php [deleted file]

index 8ffc91c46f3546d790f7ea759d43af7b705dba99..64b23b6c9850843b25b88288a97f0833805da510 100644 (file)
@@ -36,3 +36,4 @@ tests/*.log
 tests/*.out
 tests/*.php
 tests/*.sh
+lcov_data
diff --git a/check_package-xml.php b/check_package-xml.php
new file mode 100755 (executable)
index 0000000..4000054
--- /dev/null
@@ -0,0 +1,92 @@
+#!/usr/bin/env php
+<?php
+
+ini_set("log_errors", false);
+ini_set("display_errors", true);
+
+if ($argc > 1) {
+       if ($argv[1] === "-") {
+               $file = "php://stdin";
+       } else {
+               $file = $argv[1];
+       }
+} elseif (stdin_is_readable()) {
+       $file = "php://stdin";
+} else {
+       $file = "./package.xml";
+}
+
+if (($xml = simplexml_load_file($file))) {
+       $xml_files = xmllist($xml->contents[0]);
+       $dirs = ["."];
+       while ($dir = array_shift($dirs)) {
+               foreach (dirlist($dir) as $file) {
+                       if (is_gitignored($file)) {
+                               continue;
+                       }
+                       if (!is_dir($file)) {
+                               if (!in_array($file, $xml_files)) {
+                                       echo "Missing file $file\n";
+                               }
+                       } else {
+                               $base = basename($file);
+                               if ($base{0} !== ".") {
+                                       array_push($dirs, $file);
+                               }
+                       }
+               }
+       }
+}
+
+###
+
+function error($fmt) {
+       trigger_error(call_user_func_array("sprintf", func_get_args()));
+}
+
+function stdin_is_readable() {
+       $r = [STDIN]; $w = $e = [];
+       return stream_select($r, $w, $e, 0);
+}
+
+function is_gitignored($file) {
+       static $gitignore;
+       
+       if (!isset($gitignore)) {
+               if (is_readable(".gitignore")) {
+                       $gitignore = explode("\n", `find | git check-ignore --stdin`);
+               } else {
+                       $gitignore = false;
+               }
+       }
+       if ($gitignore) {
+               return in_array($file, $gitignore);
+       }
+       return false;
+}
+
+function xmllist(SimpleXmlElement $dir, $p = ".", &$a = null) {
+       settype($a, "array");
+       $p = trim($p, "/") . "/" . trim($dir["name"], "/") . "/";
+       foreach ($dir as $file) {
+               switch ($file->getName()) {
+                       case "dir":
+                               xmllist($file, $p, $a);
+                               break;
+                       case "file":
+                               $a[] = sprintf("%s/%s", trim($p, "/"), trim($file["name"]));
+                               break;
+                       default:
+                               error("Unknown content type: %s", $file->getName());
+                               break;
+               }
+       }
+       return $a;
+}
+
+function dirlist($dir, $p = null) {
+       $p = implode("/", array_filter([trim($p, "/"), trim($dir, "/")]));
+       foreach (scandir($p) as $file) {
+               yield $p."/".$file;
+       }
+}
diff --git a/phpunit.php b/phpunit.php
deleted file mode 100644 (file)
index 8a61937..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<?php
-require_once "PHPUnit/Autoload.php";
-$c = new PHPUnit_TextUI_Command;
-$c->run(array_merge($argv, array(__DIR__."/phpunit/")));