Skip to content

Commit e0e587c

Browse files
youkidearitaialexdowad
authored andcommitted
mbstring: Do not stop when mbstring test failed
I way want to confirm different on mbstring PHP 8.1 or newer and PHP 8.0 or older, but when I port to PHP 8.0 from PHP 8.1 or newer phpt files, it stopped die() function when test failed. I want to make a list, so I don't want to stop it. If you execute full test, set $testFailedLimit to -1 in encoding_tests.inc.
1 parent 7b6e31e commit e0e587c

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

ext/mbstring/tests/encoding_tests.inc

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
// Common code for tests which focus on conversion and verification of text
44
// in some specific encoding
55

6+
// Test failed limit. If you want to execute all tests, set to -1.
7+
$testFailedLimit = 1000;
8+
// Test failed counter
9+
$testFailedCounter = 0;
10+
11+
// Count tests failed. If tests failed are more than $testFailedLimit, stop testing.
12+
function testFailedIncrement() {
13+
global $testFailedCounter, $testFailedLimit;
14+
15+
// $testFailedLimit is -1, no limit.
16+
if ($testFailedLimit === -1)
17+
return;
18+
19+
$testFailedCounter++;
20+
if ($testFailedCounter < $testFailedLimit)
21+
return;
22+
23+
die("=== Failed test " . $testFailedLimit . " times exceeded, stop testing ===");
24+
}
25+
626
// Read a file with one character and its equivalent Unicode codepoint on each
727
// line, delimited by tabs
828
function readConversionTable($path, &$from, &$to, $utf32 = false) {
@@ -51,27 +71,33 @@ function dbgPrint($str) {
5171

5272
function identifyValidString($goodString, $encoding) {
5373
$result = mb_check_encoding($goodString, $encoding);
54-
if (!$result)
55-
die("mb_check_encoding failed on good $encoding string: " . dbgPrint($goodString));
74+
if (!$result) {
75+
echo "mb_check_encoding failed on good $encoding string: " . dbgPrint($goodString) . PHP_EOL;
76+
testFailedIncrement();
77+
}
5678
}
5779

5880
function identifyInvalidString($badString, $encoding) {
5981
$result = mb_check_encoding($badString, $encoding);
6082
if ($result)
61-
die("mb_check_encoding passed on bad $encoding string: " . dbgPrint($badString));
83+
echo "mb_check_encoding passed on bad $encoding string: " . dbgPrint($badString) . PHP_EOL;
6284
}
6385

6486
function testConversion($fromString, $toString, $fromEncoding, $toEncoding) {
6587
$result = mb_convert_encoding($fromString, $toEncoding, $fromEncoding);
66-
if ($result !== $toString)
67-
die("mb_convert_encoding not working on $fromEncoding input: " . dbgPrint($fromString) . "\nExpected $toEncoding: " . dbgPrint($toString) . "\nActually got: " . dbgPrint($result));
88+
if ($result !== $toString) {
89+
echo "mb_convert_encoding not working on $fromEncoding input: " . dbgPrint($fromString) . "\nExpected $toEncoding: " . dbgPrint($toString) . "\nActually got: " . dbgPrint($result) . PHP_EOL;
90+
testFailedIncrement();
91+
}
6892
}
6993

7094
function testValidConversion($fromString, $toString, $fromEncoding, $toEncoding) {
7195
$illegalChars = mb_get_info('illegal_chars');
7296
testConversion($fromString, $toString, $fromEncoding, $toEncoding);
73-
if (mb_get_info('illegal_chars') !== $illegalChars)
74-
die("mb_convert_encoding incremented illegal_chars on valid $fromEncoding string: " . dbgPrint($fromString) . " when converting to $toEncoding");
97+
if (mb_get_info('illegal_chars') !== $illegalChars) {
98+
echo "mb_convert_encoding incremented illegal_chars on valid $fromEncoding string: " . dbgPrint($fromString) . " when converting to $toEncoding" . PHP_EOL;
99+
testFailedIncrement();
100+
}
75101
}
76102

77103
function convertValidString($fromString, $toString, $fromEncoding, $toEncoding, $bothWays = true) {
@@ -83,8 +109,10 @@ function convertValidString($fromString, $toString, $fromEncoding, $toEncoding,
83109
function convertInvalidString($fromString, $toString, $fromEncoding, $toEncoding) {
84110
$illegalChars = mb_get_info('illegal_chars');
85111
testConversion($fromString, $toString, $fromEncoding, $toEncoding);
86-
if (mb_get_info('illegal_chars') <= $illegalChars)
87-
die("mb_convert_encoding did not increment illegal_chars on invalid $fromEncoding string: " . dbgPrint($fromString) . " when converting to $toEncoding");
112+
if (mb_get_info('illegal_chars') <= $illegalChars) {
113+
echo "mb_convert_encoding did not increment illegal_chars on invalid $fromEncoding string: " . dbgPrint($fromString) . " when converting to $toEncoding" . PHP_EOL;
114+
testFailedIncrement();
115+
}
88116
}
89117

90118
function testValidString($fromString, $toString, $fromEncoding, $toEncoding, $bothWays = true) {

0 commit comments

Comments
 (0)