Skip to content

Commit ece7f60

Browse files
committed
wip PHPC-2064: Change strategy for disabling SKIPIF caching
This complements php/php-src#8076
1 parent 6fab43c commit ece7f60

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

tests/utils/basic-skipif.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ register_shutdown_function(function() {
2525
exit(sprintf('skip %s: %s', errno_as_string($lastError['type']), $lastError['message']));
2626
}
2727
});
28+
29+
disable_skipif_caching_if_necessary();

tests/utils/skipif.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,33 @@
1010
require_once __DIR__ . '/basic.inc';
1111
require_once __DIR__ . '/tools.php';
1212

13-
/**
14-
* Disables SKIPIF caching (PHP 8.1+).
13+
/* Disable SKIPIF caching on PHP 8.1+ if the current script calls any functions
14+
* that cannot be cached. SkipCache (from run-tests.php) requires that "nocache"
15+
* be printed before all other SKIPIF output, so this function should be called
16+
* from basic-skipif.inc before test-level skip code.
1517
*/
16-
function disable_skipif_caching()
18+
function disable_skipif_caching_if_necessary()
1719
{
1820
if (PHP_VERSION_ID < 80100) {
1921
return;
2022
}
2123

24+
$skipif = file_get_contents($_SERVER['PATH_TRANSLATED']);
25+
26+
if (strpos($skipif, 'skip_if_not_clean') === false) {
27+
return;
28+
}
29+
30+
/* Earlier versions of PHP 8.1.x discard SKIPIF output after consuming a
31+
* leading "nocache" tag, which could prevent a test from being skipped. To
32+
* avoid that, only print "nocache" as the final output. In the event the
33+
* test does skip, this trailing "nocache" tag will be ignored, but that is
34+
* preferable to ignoring the skip entirely. */
35+
if (PHP_VERSION_ID < 80103) {
36+
register_shutdown_function(function() { echo "nocache\n"; });
37+
return;
38+
}
39+
2240
echo "nocache\n";
2341
}
2442

@@ -432,10 +450,6 @@ function skip_if_not_clean($databaseName = DATABASE_NAME, $collectionName = COLL
432450
} catch (RuntimeException $e) {
433451
exit("skip Could not drop '$databaseName.$collectionName': " . $e->getMessage());
434452
}
435-
436-
/* Since this function modifies the state of the database, we need it to run
437-
* each time before a test. */
438-
disable_skipif_caching();
439453
}
440454

441455
function skip_if_no_getmore_failpoint()

0 commit comments

Comments
 (0)