Skip to content

Commit 4db0060

Browse files
committed
unify test parsing in run-tests.php
1 parent 12bc84e commit 4db0060

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

run-tests.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,7 +3817,7 @@ class TestFile
38173817
{
38183818
private string $fileName;
38193819

3820-
private array $sections = ['TEST' => ''];
3820+
private array $sections = [];
38213821

38223822
private const ALLOWED_SECTIONS = [
38233823
'EXPECT', 'EXPECTF', 'EXPECTREGEX', 'EXPECTREGEX_EXTERNAL', 'EXPECT_EXTERNAL', 'EXPECTF_EXTERNAL', 'EXPECTHEADERS',
@@ -3826,7 +3826,7 @@ class TestFile
38263826
'CAPTURE_STDIO', 'STDIN', 'CGI', 'PHPDBG',
38273827
'INI', 'ENV', 'EXTENSIONS',
38283828
'SKIPIF', 'XFAIL', 'XLEAK', 'CLEAN',
3829-
'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE',
3829+
'TEST', 'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE',
38303830
];
38313831

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

3920-
if (!feof($fp)) {
3921-
$line = fgets($fp);
3922-
3923-
if ($line === false) {
3924-
throw new BorkageException("cannot read test");
3925-
}
3926-
} else {
3927-
throw new BorkageException("empty test [{$this->fileName}]");
3928-
}
3929-
if (strncmp('--TEST--', $line, 8)) {
3930-
throw new BorkageException("tests must start with --TEST-- [{$this->fileName}]");
3920+
if (feof($fp)) {
3921+
throw new BorkageException("empty test");
39313922
}
39323923

3933-
$section = 'TEST';
3934-
$secfile = false;
3935-
$secdone = false;
3924+
$section = false;
39363925

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

3929+
if ($section === false) {
3930+
if ($line === false) {
3931+
throw new BorkageException("cannot read test");
3932+
}
3933+
3934+
if (rtrim($line, "\n\r") !== '--TEST--') {
3935+
throw new BorkageException("test must start with --TEST--");
3936+
}
3937+
}
3938+
39403939
if ($line === false) {
39413940
break;
39423941
}
39433942

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

3948-
if (isset($this->sections[$section]) && $this->sections[$section]) {
3947+
if (isset($this->sections[$section])) {
39493948
throw new BorkageException("duplicated $section section");
39503949
}
39513950

39523951
// check for unknown sections
39533952
if (!in_array($section, self::ALLOWED_SECTIONS)) {
3954-
throw new BorkageException('Unknown section "' . $section . '"');
3953+
throw new BorkageException('unknown section "' . $section . '"');
39553954
}
39563955

39573956
$this->sections[$section] = '';

0 commit comments

Comments
 (0)