From: Gabriel Caruso Date: Tue, 27 Feb 2018 05:05:31 +0000 (-0300) Subject: Small improvements to run-tests X-Git-Tag: php-7.3.0alpha1~140 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=543cab8a00f054bacd55633eeb312f7bbc1f5a21;p=php Small improvements to run-tests * substr instead of preg_match * cast instead of settype * remove $borked and check if $bork_info isn't null to report borked tests * remove some error control operators --- diff --git a/run-tests.php b/run-tests.php index e66eeba34e..82918c002f 100644 --- a/run-tests.php +++ b/run-tests.php @@ -778,7 +778,7 @@ HELP; if (!$testfile && strpos($argv[$i], '*') !== false && function_exists('glob')) { - if (preg_match("/\.phpt$/", $argv[$i])) { + if (substr($argv[$i], -5) == '.phpt') { $pattern_match = glob($argv[$i]); } else if (preg_match("/\*$/", $argv[$i])) { $pattern_match = glob($argv[$i] . '.phpt'); @@ -792,7 +792,7 @@ HELP; } else if (is_dir($testfile)) { find_files($testfile); - } else if (preg_match("/\.phpt$/", $testfile)) { + } else if (substr($testfile, -5) == '.phpt') { $test_files[] = $testfile; } else { die('Cannot find test file "' . $argv[$i] . '".' . PHP_EOL); @@ -883,7 +883,7 @@ $test_dirs = array(); $optionals = array('tests', 'ext', 'Zend', 'sapi'); foreach($optionals as $dir) { - if (@filetype($dir) == 'dir') { + if (is_dir($dir)) { $test_dirs[] = $dir; } } @@ -1268,23 +1268,19 @@ TEST $file $fp = fopen($file, "rb") or error("Cannot open test file: $file"); - $borked = false; - $bork_info = ''; + $bork_info = null; if (!feof($fp)) { $line = fgets($fp); if ($line === false) { $bork_info = "cannot read test"; - $borked = true; } } else { $bork_info = "empty test [$file]"; - $borked = true; } - if (!$borked && strncmp('--TEST--', $line, 8)) { + if ($bork_info === null && strncmp('--TEST--', $line, 8)) { $bork_info = "tests must start with --TEST-- [$file]"; - $borked = true; } $section = 'TEST'; @@ -1300,12 +1296,10 @@ TEST $file // Match the beginning of a section. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { - $section = $r[1]; - settype($section, 'string'); + $section = (string) $r[1]; if (isset($section_text[$section]) && $section_text[$section]) { $bork_info = "duplicated $section section"; - $borked = true; } // check for unknown sections @@ -1319,7 +1313,6 @@ TEST $file 'CREDITS', 'DESCRIPTION', ))) { $bork_info = 'Unknown section "' . $section . '"'; - $borked = true; } $section_text[$section] = ''; @@ -1341,24 +1334,20 @@ TEST $file // the redirect section allows a set of tests to be reused outside of // a given test dir - if (!$borked) { - if (@count($section_text['REDIRECTTEST']) == 1) { + if ($bork_info === null) { + if (isset($section_text['REDIRECTTEST'])) { if ($IN_REDIRECT) { - $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; - } else { - $borked = false; } } else { if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { $bork_info = "missing section --FILE--"; - $borked = true; } - if (@count($section_text['FILEEOF']) == 1) { + if (isset($section_text['FILEEOF'])) { $section_text['FILE'] = preg_replace("/[\r\n]+$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } @@ -1366,7 +1355,7 @@ TEST $file foreach (array( 'FILE', 'EXPECT', 'EXPECTF', 'EXPECTREGEX' ) as $prefix) { $key = $prefix . '_EXTERNAL'; - if (@count($section_text[$key]) == 1) { + if (isset($section_text[$key])) { // don't allow tests to retrieve files from anywhere but this subdirectory $section_text[$key] = dirname($file) . '/' . trim(str_replace('..', '', $section_text[$key])); @@ -1375,14 +1364,12 @@ TEST $file unset($section_text[$key]); } else { $bork_info = "could not load --" . $key . "-- " . dirname($file) . '/' . trim($section_text[$key]); - $borked = true; } } } if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; - $borked = true; } } } @@ -1391,7 +1378,7 @@ TEST $file $shortname = str_replace(TEST_PHP_SRCDIR . '/', '', $file); $tested_file = $shortname; - if ($borked) { + if ($bork_info !== null) { show_result("BORK", $bork_info, $tested_file); $PHP_FAILED_TESTS['BORKED'][] = array ( 'name' => $file, @@ -1683,7 +1670,7 @@ TEST $file return 'SKIPPED'; } - if (@count($section_text['REDIRECTTEST']) == 1) { + if (isset($section_text['REDIRECTTEST'])) { $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); @@ -2080,7 +2067,7 @@ COMMAND $cmd $startOffset = $end + 2; } $wanted_re = $temp; - + // Stick to basics $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace('%s', '[^\r\n]+', $wanted_re);