Skip to content

Commit b84d366

Browse files
committed
Resolves FoundationDB#3045: Require FileOptions to be first block of yamsql
1 parent c58d548 commit b84d366

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/YamlRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ public void run() throws Exception {
9999
final var yaml = new Yaml(new CustomYamlConstructor(loaderOptions), new Representer(dumperOptions), new DumperOptions(), loaderOptions, new Resolver());
100100

101101
final var testBlocks = new ArrayList<TestBlock>();
102+
int blockCount = 0;
102103
try (var inputStream = getInputStream(resourcePath)) {
103104
for (var doc : yaml.loadAll(inputStream)) {
104-
final var block = Block.parse(doc, executionContext);
105+
final var block = Block.parse(doc, executionContext, blockCount);
105106
logger.debug("⚪️ Executing block at line {} in {}", block.getLineNumber(), resourcePath);
106107
block.execute();
107108
if (block instanceof TestBlock) {
108109
testBlocks.add((TestBlock) block);
109110
}
111+
blockCount++;
110112
}
111113
}
112114
for (var block : executionContext.getFinalizeBlocks()) {

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/block/Block.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public interface Block {
4848
*
4949
* @param document a region in the file
5050
* @param executionContext information needed to carry out the execution
51+
* @param blockCount the number of previous blocks in the file
5152
*/
52-
static Block parse(@Nonnull Object document, @Nonnull YamlExecutionContext executionContext) {
53+
static Block parse(@Nonnull Object document, @Nonnull YamlExecutionContext executionContext, final int blockCount) {
5354
final var blockObject = Matchers.map(document, "block");
5455
Assert.thatUnchecked(blockObject.size() == 1, "Illegal Format: A block is expected to be a map of size 1");
5556
final var entry = Matchers.firstEntry(blockObject, "block key-value");
@@ -63,6 +64,8 @@ static Block parse(@Nonnull Object document, @Nonnull YamlExecutionContext execu
6364
case SetupBlock.SchemaTemplateBlock.SCHEMA_TEMPLATE_BLOCK:
6465
return SetupBlock.SchemaTemplateBlock.parse(lineNumber, entry.getValue(), executionContext);
6566
case FileOptions.OPTIONS:
67+
Assert.thatUnchecked(blockCount == 0,
68+
"File level options must be the first block, but found one at line " + lineNumber);
6669
return FileOptions.parse(lineNumber, entry.getValue(), executionContext);
6770
default:
6871
throw new RuntimeException("Cannot recognize the type of block");

0 commit comments

Comments
 (0)