Skip to content

Commit eebd90d

Browse files
committed
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: * php/doc-en#4311 * #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
1 parent 83b700e commit eebd90d

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

ext/gettext/tests/bug53251.phpt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ if (getenv('SKIP_REPEAT')) die('skip gettext leaks global state across requests'
88
?>
99
--FILE--
1010
<?php
11-
var_dump(is_string(bindtextdomain('foo', null)));
11+
$results[] = is_string(bindtextdomain('foo', null));
1212
$dir = bindtextdomain('foo', '.');
13-
var_dump(bindtextdomain('foo', null) === $dir);
13+
$results[] = bindtextdomain('foo', null) === $dir;
14+
$results[] = bind_textdomain_codeset('foo', null);
15+
$results[] = bind_textdomain_codeset('foo', 'UTF-8');
16+
$results[] = bind_textdomain_codeset('foo', null);
1417

15-
var_dump(bind_textdomain_codeset('foo', null));
16-
var_dump(bind_textdomain_codeset('foo', 'UTF-8'));
17-
var_dump(bind_textdomain_codeset('foo', null));
18+
$expected = [true, true, false, "UTF-8", "UTF-8"];
1819

20+
// musl's bindtextdomain() has no default directory to return when
21+
// "foo" is unbound, so in the first call, you will get false instead
22+
// of a string.
23+
//
24+
// bind_textdomain_codeset() always returns false on musl
25+
// because musl only supports UTF-8. For more information:
26+
//
27+
// * https://github.com/php/doc-en/issues/4311,
28+
// * https://github.com/php/php-src/issues/17163
29+
//
30+
$expected_musl = [false, true, false, false, false];
31+
32+
var_dump($results === $expected or $results === $expected_musl);
1933
?>
2034
--EXPECT--
2135
bool(true)
22-
bool(true)
23-
bool(false)
24-
string(5) "UTF-8"
25-
string(5) "UTF-8"

ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ gettext
1515
} catch (ValueError $e) {
1616
echo $e->getMessage() . PHP_EOL;
1717
}
18-
var_dump(bind_textdomain_codeset('messages', "UTF-8"));
18+
19+
// bind_textdomain_codeset() always returns false on musl
20+
// because musl only supports UTF-8. For more information:
21+
//
22+
// * https://github.com/php/doc-en/issues/4311,
23+
// * https://github.com/php/php-src/issues/17163
24+
//
25+
$result = bind_textdomain_codeset('messages', "UTF-8");
26+
var_dump($result === false or $result === "UTF-8");
1927

2028
echo "Done\n";
2129
?>
2230
--EXPECT--
2331
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
2432
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
25-
string(5) "UTF-8"
33+
bool(true)
2634
Done
2735
--CREDITS--
2836
Florian Holzhauer fh-pt@fholzhauer.de

0 commit comments

Comments
 (0)