Skip to content

Sanity check extensions by inline their test code#182

Merged
crazywhalecc merged 1 commit intocrazywhalecc:mainfrom
stloyd:ext-test-bis
Sep 13, 2023
Merged

Sanity check extensions by inline their test code#182
crazywhalecc merged 1 commit intocrazywhalecc:mainfrom
stloyd:ext-test-bis

Conversation

@stloyd
Copy link
Contributor

@stloyd stloyd commented Sep 13, 2023

stloyd@MacBook-Pro-2 spc-test % ./spc build gd --build-cli
     _        _   _                 _
 ___| |_ __ _| |_(_) ___      _ __ | |__  _ __
/ __| __/ _` | __| |/ __|____| '_ \| '_ \| '_ \
\__ \ || (_| | |_| | (_|_____| |_) | | | | |_) |
|___/\__\__,_|\__|_|\___|    | .__/|_| |_| .__/   v2.0-rc6
                             |_|         |_|
[11:45:50] [INFO] [EXEC] sysctl -n hw.ncpu
[11:45:50] [INFO] Build target: cli
[11:45:50] [INFO] Enabled extensions: zlib, gd
[11:45:50] [INFO] Required libraries: zlib, libpng
[11:45:50] [WARN] some extensions will be enabled due to dependencies: zlib
[11:45:52] [NOTI] lib [pkg-config] already built
[11:45:52] [NOTI] lib [zlib] already built
[11:45:52] [NOTI] lib [libpng] already built
[11:45:52] [INFO] enabling gd without library libavif
[11:45:52] [INFO] enabling gd without library libwebp
[11:45:52] [INFO] enabling gd without library libjpeg
[11:45:52] [INFO] enabling gd without library freetype
[11:45:52] [INFO] Entering dir: /Users/stloyd/Documents/spc-test/source/php-src
[11:45:52] [INFO] [EXEC] ./buildconf --force
[11:45:58] [INFO] Entering dir: /Users/stloyd/Documents/spc-test/source/php-src
[11:45:58] [INFO] Using configure: --with-zlib --enable-gd
(...)
[11:46:54] [INFO] cleaning up
[11:46:54] [INFO] Entering dir: /Users/stloyd/Documents/spc-test/source/php-src
[11:46:54] [INFO] [EXEC] make clean
[11:46:55] [INFO] building cli
[11:46:55] [INFO] Entering dir: /Users/stloyd/Documents/spc-test/source/php-src
[11:46:55] [INFO] [EXEC] make -j10 EXTRA_CFLAGS='-g -Os' EXTRA_LIBS='/Users/stloyd/Documents/spc-test/buildroot/lib/libpng16.a /Users/stloyd/Documents/spc-test/buildroot/lib/libz.a -lresolv' cli
[11:49:18] [INFO] [EXEC] dsymutil -f sapi/cli/php
[11:49:19] [INFO] [EXEC] strip sapi/cli/php
[11:49:19] [INFO] Deploying cli file
[11:49:19] [INFO] [EXEC] cp '/Users/stloyd/Documents/spc-test/source/php-src/sapi/cli/php' '/Users/stloyd/Documents/spc-test/buildroot/bin/'
[11:49:19] [INFO] running cli sanity check
[11:49:19] [INFO] [EXEC] /Users/stloyd/Documents/spc-test/buildroot/bin/php -r "echo \"hello\";"
[11:49:19] [INFO] [EXEC] /Users/stloyd/Documents/spc-test/buildroot/bin/php -r "assert(function_exists('gzcompress'));"
[11:49:19] [INFO] [EXEC] /Users/stloyd/Documents/spc-test/buildroot/bin/php -r "assert(function_exists('gd_info'));\$info = gd_info();assert(\$info['PNG Support'] ?? false);assert(\$info['GIF Create Support'] ?? false);assert(\$info['GIF Read Support'] ?? false);"
[11:49:19] [INFO] Build complete, used 209.285 s !
[11:49:19] [INFO] Static php binary path: /Users/stloyd/Documents/spc-test/buildroot/bin/php
[11:49:19] [INFO] License path: /Users/stloyd/Documents/spc-test/buildroot/license/

Alternative for #180
Fixes #124

@stloyd
Copy link
Contributor Author

stloyd commented Sep 13, 2023

Tested with dom extension too (with small fix):

[12:50:14] [INFO] running cli sanity check
[12:50:14] [INFO] [EXEC] /Users/stloyd/Documents/spc-test/buildroot/bin/php -r "echo \"hello\";"
[12:50:15] [INFO] [EXEC] /Users/stloyd/Documents/spc-test/buildroot/bin/php -r "assert(function_exists('curl_init'));"
[12:50:16] [INFO] [EXEC] /Users/stloyd/Documents/spc-test/buildroot/bin/php -r "assert(class_exists('\\DOMDocument'));\$doc = new DOMDocument();\$doc->loadHtml('<html><head><meta charset=\"UTF-8\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body id=\"app\">Hello</body></html>');assert(\$doc->getElementById('app')->nodeValue === 'Hello');"
[12:50:16] [INFO] Build complete, used 201.601 s !
[12:50:16] [INFO] Static php binary path: /Users/stloyd/Documents/spc-test/buildroot/bin/php
[12:50:16] [INFO] License path: /Users/stloyd/Documents/spc-test/buildroot/license/

@crazywhalecc crazywhalecc added bug Something isn't working kind/framework Issues related to CLI app framework labels Sep 13, 2023
@crazywhalecc
Copy link
Owner

crazywhalecc commented Sep 13, 2023

Is it a better way to escape? For old PHP version (5.x) escapeshellarg may have known bugs and vulnerablilities, but now I haven't found one. This way we don't need to worry about quotation marks in the test code.

$test = str_replace(
    ['<?php', 'declare(strict_types=1);'],
    '',
    file_get_contents(ROOT_DIR . '/src/globals/tests/' . $ext->getName() . '.php')
);

[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r ' . escapeshellarg(trim($test)));

@stloyd
Copy link
Contributor Author

stloyd commented Sep 13, 2023

#Unfortunately, this escapes too much, we need to escape just: $ & ", while this command escapes much more along with >, (, etc.

@crazywhalecc
Copy link
Owner

I feel that even though it escapes a lot of content and easily causes parameter redundancy, it is indeed safer and can prevent errors caused by misuse of \" when adding new tests in the future.

@stloyd
Copy link
Contributor Author

stloyd commented Sep 13, 2023

TBH. I would prefer writing some kind of additional tool to validate tests in dev, rather than fighting with unescaping the strings, especially since this will be something provided by the library, not from outside.

Here is a comparison: https://3v4l.org/58omP

@crazywhalecc crazywhalecc added need test This PR has not been tested yet, cannot merge now and removed need test This PR has not been tested yet, cannot merge now labels Sep 13, 2023
@crazywhalecc crazywhalecc merged commit be32190 into crazywhalecc:main Sep 13, 2023
@stloyd stloyd deleted the ext-test-bis branch September 13, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kind/framework Issues related to CLI app framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiling with standalone spc binary cannot pass sanity check

2 participants