Skip to content

Unify run-tests.php test parsing #10535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/standard/tests/array/bug24198.phpt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--TEST--n
--TEST--
Bug #24198 (array_merge_recursive() invalid recursion detection)
--FILE--
<?php
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/bug24220.phpt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--TEST--n
--TEST--
Bug #24220 (range() numeric string handling)
--FILE--
<?php
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/file/windows_mb_path/bug64506.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--Bug #64506
PHP can not read or write file correctly if file name have special char like š
--TEST--
Bug #64506 - PHP can not read or write file correctly if file name have special char like š
--SKIPIF--
<?php
include __DIR__ . DIRECTORY_SEPARATOR . "util.inc";
Expand Down
37 changes: 18 additions & 19 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3817,7 +3817,7 @@ class TestFile
{
private string $fileName;

private array $sections = ['TEST' => ''];
private array $sections = [];

private const ALLOWED_SECTIONS = [
'EXPECT', 'EXPECTF', 'EXPECTREGEX', 'EXPECTREGEX_EXTERNAL', 'EXPECT_EXTERNAL', 'EXPECTF_EXTERNAL', 'EXPECTHEADERS',
Expand All @@ -3826,7 +3826,7 @@ class TestFile
'CAPTURE_STDIO', 'STDIN', 'CGI', 'PHPDBG',
'INI', 'ENV', 'EXTENSIONS',
'SKIPIF', 'XFAIL', 'XLEAK', 'CLEAN',
'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE',
'TEST', 'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE',
];

/**
Expand Down Expand Up @@ -3917,41 +3917,40 @@ private function readFile(): void
{
$fp = fopen($this->fileName, "rb") or error("Cannot open test file: {$this->fileName}");

if (!feof($fp)) {
$line = fgets($fp);

if ($line === false) {
throw new BorkageException("cannot read test");
}
} else {
throw new BorkageException("empty test [{$this->fileName}]");
}
if (strncmp('--TEST--', $line, 8)) {
throw new BorkageException("tests must start with --TEST-- [{$this->fileName}]");
if (feof($fp)) {
throw new BorkageException("empty test");
}

$section = 'TEST';
$secfile = false;
$secdone = false;
$section = false;

while (!feof($fp)) {
$line = fgets($fp);

if ($section === false) {
if ($line === false) {
throw new BorkageException("cannot read test");
}

if (rtrim($line, "\n\r") !== '--TEST--') {
throw new BorkageException("test must start with --TEST--");
}
}

if ($line === false) {
break;
}

// Match the beginning of a section.
if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {
$section = (string) $r[1];
$section = $r[1];

if (isset($this->sections[$section]) && $this->sections[$section]) {
if (isset($this->sections[$section])) {
throw new BorkageException("duplicated $section section");
}

// check for unknown sections
if (!in_array($section, self::ALLOWED_SECTIONS)) {
throw new BorkageException('Unknown section "' . $section . '"');
throw new BorkageException('unknown section "' . $section . '"');
}

$this->sections[$section] = '';
Expand Down