From cfe0c290788ed5e0b52c80a37e2bd6a74ae9bfaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 2 Feb 2023 22:40:08 +0100 Subject: [PATCH 1/2] unify test parsing in run-tests.php --- run-tests.php | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/run-tests.php b/run-tests.php index 9b892327c8db..bbb04f21b420 100755 --- a/run-tests.php +++ b/run-tests.php @@ -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', @@ -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', ]; /** @@ -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] = ''; From 5ada9398bda54b170caf1c4e57de4642f2be8ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 3 Feb 2023 01:47:34 +0100 Subject: [PATCH 2/2] fix typos in tests --- ext/standard/tests/array/bug24198.phpt | 2 +- ext/standard/tests/array/bug24220.phpt | 2 +- ext/standard/tests/file/windows_mb_path/bug64506.phpt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/tests/array/bug24198.phpt b/ext/standard/tests/array/bug24198.phpt index a1a30afb6d3c..b7d4652846c0 100644 --- a/ext/standard/tests/array/bug24198.phpt +++ b/ext/standard/tests/array/bug24198.phpt @@ -1,4 +1,4 @@ ---TEST--n +--TEST-- Bug #24198 (array_merge_recursive() invalid recursion detection) --FILE--