|
10 | 10 | require_once __DIR__ . '/basic.inc';
|
11 | 11 | require_once __DIR__ . '/tools.php';
|
12 | 12 |
|
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. |
15 | 17 | */
|
16 |
| -function disable_skipif_caching() |
| 18 | +function disable_skipif_caching_if_necessary() |
17 | 19 | {
|
18 | 20 | if (PHP_VERSION_ID < 80100) {
|
19 | 21 | return;
|
20 | 22 | }
|
21 | 23 |
|
| 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 | + |
22 | 40 | echo "nocache\n";
|
23 | 41 | }
|
24 | 42 |
|
@@ -432,10 +450,6 @@ function skip_if_not_clean($databaseName = DATABASE_NAME, $collectionName = COLL
|
432 | 450 | } catch (RuntimeException $e) {
|
433 | 451 | exit("skip Could not drop '$databaseName.$collectionName': " . $e->getMessage());
|
434 | 452 | }
|
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(); |
439 | 453 | }
|
440 | 454 |
|
441 | 455 | function skip_if_no_getmore_failpoint()
|
|
0 commit comments