Skip to content

Commit bcba690

Browse files
committed
Fixed YAML tests skipping YAML file with parsing issue
1 parent 8d8980b commit bcba690

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

util/YamlTests.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use RecursiveDirectoryIterator;
2323
use RecursiveIteratorIterator;
2424
use stdClass;
25+
use Throwable;
2526

2627
use function yaml_parse;
2728

@@ -34,6 +35,10 @@ class YamlTests
3435
const TEMPLATE_FUNCTION_SKIPPED = __DIR__ . '/template/test/function-skipped';
3536
const ELASTICSEARCH_GIT_URL = 'https://github.com/elastic/elasticsearch/tree/%s/rest-api-spec/src/main/resources/rest-api-spec/test/%s';
3637

38+
const YAML_FILES_TO_OMIT = [
39+
'platinum/eql/10_basic.yml'
40+
];
41+
3742
const SKIPPED_TEST_OSS = [
3843
'Cat\Nodeattrs\_10_BasicTest::TestCatNodesAttrsOutput' => 'Regexp error, it seems not compatible with PHP',
3944
'Cat\Shards\_10_BasicTest::TestCatShardsOutput' => 'Regexp error, it seems not compatible with PHP',
@@ -142,22 +147,41 @@ private function getAllTests(string $dir): array
142147
$parsed = [];
143148
// Iterate over the Yaml test files
144149
foreach (new RecursiveIteratorIterator($it) as $file) {
145-
if ($file->getExtension() === 'yml') {
146-
$content = file_get_contents($file->getPathname());
147-
$content = str_replace(' y: ', " 'y': ", $content); // replace "y:" with "'y':" due the y/true conversion in YAML 1.1
150+
if ($file->getExtension() !== 'yml') {
151+
continue;
152+
}
153+
$omit = false;
154+
foreach (self::YAML_FILES_TO_OMIT as $fileOmit) {
155+
if (false !== strpos($file->getPathname(), $fileOmit)) {
156+
$omit = true;
157+
break;
158+
}
159+
}
160+
if ($omit) {
161+
continue;
162+
}
163+
$content = file_get_contents($file->getPathname());
164+
$content = str_replace(' y: ', " 'y': ", $content); // replace "y:" with "'y':" due the y/true conversion in YAML 1.1
165+
try {
148166
$test = yaml_parse($content, -1, $ndocs, [
149167
YAML_MAP_TAG => function($value, $tag, $flags) {
150168
return empty($value) ? new stdClass : $value;
151169
}
152170
]);
153-
if (false === $test) {
154-
throw new Exception(sprintf(
155-
"YAML parse error file %s",
156-
$file->getPathname()
157-
));
158-
}
159-
$parsed[$file->getPathname()] = $test;
171+
} catch (Throwable $e) {
172+
throw new Exception(sprintf(
173+
"YAML parse error file %s: %s",
174+
$file->getPathname(),
175+
$e->getMessage()
176+
));
177+
}
178+
if (false === $test) {
179+
throw new Exception(sprintf(
180+
"YAML parse error file %s",
181+
$file->getPathname()
182+
));
160183
}
184+
$parsed[$file->getPathname()] = $test;
161185
}
162186
return $parsed;
163187
}

0 commit comments

Comments
 (0)