From eebd90d9411707bf17225ef62e998a5c3ab09f63 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 14 Dec 2024 19:17:29 -0500 Subject: [PATCH] ext/gettext/tests: fix libintl return values under musl Musl has two quirks that are leading to failed internationalization tests. First is that the return value of bindtextdomain(..., NULL) will always be false, rather than an "implementation-defined default directory," because musl does not have an implementation-defined default directory. One test needs a special case for this. Second is that the musl implementation of bind_textdomain_codeset() always returns NULL. The POSIX-correctness of this is debatable, but it is roughly equivalent to correct, because musl only support UTF-8, so the NULL value indicating that the codeset is unchanged from the locale's codeset (UTF-8) is accurate. PHP's bind_textdomain_codeset() function however treats NULL as failure, unconditionally: * https://github.com/php/doc-en/issues/4311 * https://github.com/php/php-src/issues/17163 This unfortunately causes false to be returned consistently on musl -- even when nothing unexpected has happened -- and naturally this is affecting several tests. For now we change two tests to accept "false" in addition to "UTF-8" so that they may pass on musl. If PHP's bind_textdomain_codeset() is updated to differentiate between NULL and NULL-with-errno-set, these tests can also be updated once again to reject the NULL-with-errno result. This partially addresses GH #13696 --- ext/gettext/tests/bug53251.phpt | 28 +++++++++++++------ ...ettext_bind_textdomain_codeset-retval.phpt | 12 ++++++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ext/gettext/tests/bug53251.phpt b/ext/gettext/tests/bug53251.phpt index 6f37642925d37..75f8f08b74ccb 100644 --- a/ext/gettext/tests/bug53251.phpt +++ b/ext/gettext/tests/bug53251.phpt @@ -8,18 +8,28 @@ if (getenv('SKIP_REPEAT')) die('skip gettext leaks global state across requests' ?> --FILE-- --EXPECT-- bool(true) -bool(true) -bool(false) -string(5) "UTF-8" -string(5) "UTF-8" diff --git a/ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt b/ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt index cd07db1a94227..413a0951be218 100644 --- a/ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt +++ b/ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt @@ -15,14 +15,22 @@ gettext } catch (ValueError $e) { echo $e->getMessage() . PHP_EOL; } - var_dump(bind_textdomain_codeset('messages', "UTF-8")); + + // bind_textdomain_codeset() always returns false on musl + // because musl only supports UTF-8. For more information: + // + // * https://github.com/php/doc-en/issues/4311, + // * https://github.com/php/php-src/issues/17163 + // + $result = bind_textdomain_codeset('messages', "UTF-8"); + var_dump($result === false or $result === "UTF-8"); echo "Done\n"; ?> --EXPECT-- bind_textdomain_codeset(): Argument #1 ($domain) must not be empty bind_textdomain_codeset(): Argument #1 ($domain) must not be empty -string(5) "UTF-8" +bool(true) Done --CREDITS-- Florian Holzhauer fh-pt@fholzhauer.de