From a8b8fd74454904c7710ba5d77a8ec473151079e4 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 12 Sep 2023 19:35:36 +0200 Subject: [PATCH] Replace file based extension tests with inline ones --- config/ext.json | 49 +++++++++++++++++++-- src/SPC/builder/Extension.php | 8 ++++ src/SPC/builder/traits/UnixBuilderTrait.php | 6 ++- src/globals/tests/bcmath.php | 5 --- src/globals/tests/bz2.php | 8 ---- src/globals/tests/calendar.php | 6 --- src/globals/tests/curl.php | 5 --- src/globals/tests/dom.php | 8 ---- src/globals/tests/filter.php | 5 --- src/globals/tests/gd.php | 9 ---- src/globals/tests/intl.php | 5 --- src/globals/tests/redis.php | 5 --- src/globals/tests/zip.php | 5 --- src/globals/tests/zlib.php | 5 --- 14 files changed, 58 insertions(+), 71 deletions(-) delete mode 100644 src/globals/tests/bcmath.php delete mode 100644 src/globals/tests/bz2.php delete mode 100644 src/globals/tests/calendar.php delete mode 100644 src/globals/tests/curl.php delete mode 100644 src/globals/tests/dom.php delete mode 100644 src/globals/tests/filter.php delete mode 100644 src/globals/tests/gd.php delete mode 100644 src/globals/tests/intl.php delete mode 100644 src/globals/tests/redis.php delete mode 100644 src/globals/tests/zip.php delete mode 100644 src/globals/tests/zlib.php diff --git a/config/ext.json b/config/ext.json index d5234e4ed..de5c122f0 100644 --- a/config/ext.json +++ b/config/ext.json @@ -4,17 +4,30 @@ "source": "apcu" }, "bcmath": { - "type": "builtin" + "type": "builtin", + "test": [ + "assert(function_exists('bcscale'));" + ] }, "bz2": { "type": "builtin", "arg-type": "with-prefix", "lib-depends": [ "bzip2" + ], + "test": [ + "$str = 'This is bz2 extension test';", + "assert(function_exists('bzdecompress'));", + "assert(function_exists('bzcompress'));", + "assert(bzdecompress(bzcompress($str, 9)) === $str);" ] }, "calendar": { - "type": "builtin" + "type": "builtin", + "test": [ + "assert(function_exists('cal_info'));", + "assert(is_array(cal_info(0)));" + ] }, "ctype": { "type": "builtin" @@ -24,6 +37,9 @@ "arg-type": "with", "lib-depends": [ "curl" + ], + "test": [ + "assert(function_exists('curl_init'));" ] }, "dba": { @@ -37,6 +53,12 @@ "lib-depends": [ "libxml2", "zlib" + ], + "test": [ + "assert(class_exists('\\DOMDocument'));", + "$doc = new DOMDocument();", + "$doc->loadHtml('Hello');", + "assert($doc->getElementById('app')->nodeValue === 'Hello');" ] }, "event": { @@ -67,7 +89,10 @@ "type": "builtin" }, "filter": { - "type": "builtin" + "type": "builtin", + "test": [ + "assert(function_exists('filter_var'));" + ] }, "ftp": { "type": "builtin", @@ -91,6 +116,12 @@ "libwebp", "libjpeg", "freetype" + ], + "test": [ + "assert(function_exists('gd_info'));", + "assert(gd_info()['PNG Support'] ?? false);", + "assert(gd_info()['GIF Create Support'] ?? false);", + "assert(gd_info()['GIF Read Support'] ?? false);" ] }, "gettext": { @@ -149,6 +180,9 @@ "cpp-extension": true, "lib-depends": [ "icu" + ], + "test": [ + "assert(class_exists(NumberFormatter::class));" ] }, "ldap": { @@ -309,6 +343,9 @@ "arg-type": "custom", "ext-suggests": [ "session" + ], + "test": [ + "assert(class_exists('\\Redis'));" ] }, "session": { @@ -484,6 +521,9 @@ "arg-type-windows": "enable", "lib-depends": [ "libzip" + ], + "test": [ + "assert(class_exists('\\ZipArchive'));" ] }, "zlib": { @@ -492,6 +532,9 @@ "arg-type-windows": "enable", "lib-depends": [ "zlib" + ], + "test": [ + "assert(function_exists('gzcompress'));" ] }, "zstd": { diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index d9edc6b52..78a01c365 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -124,6 +124,14 @@ public function getDistName(): string return $this->name; } + /** + * @return string[] + */ + public function getTests(): array + { + return Config::getExt($this->name, 'test', []); + } + public function getWindowsConfigureArg(): string { return ''; diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index 8dafe20a3..fa500d676 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -72,8 +72,10 @@ public function sanityCheck(int $build_target): void if ($ret !== 0) { throw new RuntimeException('extension ' . $ext->getName() . ' failed compile check'); } - if (file_exists(ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php')) { - [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php ' . ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php'); + + $tests = $ext->getTests(); + if ($tests !== []) { + [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "' . implode('', $tests) . '"'); if ($ret !== 0) { throw new RuntimeException('extension ' . $ext->getName() . ' failed sanity check'); } diff --git a/src/globals/tests/bcmath.php b/src/globals/tests/bcmath.php deleted file mode 100644 index 0190aa78b..000000000 --- a/src/globals/tests/bcmath.php +++ /dev/null @@ -1,5 +0,0 @@ -loadHtml("Hello"); -assert($doc->getElementById('app')->nodeValue === 'Hello'); diff --git a/src/globals/tests/filter.php b/src/globals/tests/filter.php deleted file mode 100644 index 6857bca02..000000000 --- a/src/globals/tests/filter.php +++ /dev/null @@ -1,5 +0,0 @@ -