From baa144e8441cd40dace467630b5de8725e41e2cf Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Mon, 29 Oct 2018 14:54:22 +0200 Subject: [PATCH] Enforce a [skip] when using [contains] (#34840) Be friendly to other runners --- .../yaml/section/ClientYamlTestSection.java | 7 ++++++ .../section/ClientYamlTestSectionTests.java | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java index 1ec2382fac5..da6ff265a1a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java @@ -99,6 +99,13 @@ public class ClientYamlTestSection implements Comparable + doSection.getLocation().lineNumber + "]"); } } + if (executableSection instanceof ContainsAssertion) { + if (false == skipSection.getFeatures().contains("contains")) { + throw new IllegalArgumentException("Attempted to add a [contains] assertion without a corresponding " + + "[skip: \"features\": \"contains\"] so runners that do not support the [contains] assertion " + + "can skip the test at line [" + executableSection.getLocation().lineNumber + "]"); + } + } this.executableSections.add(executableSection); } diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSectionTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSectionTests.java index 500cff893cb..640c99e13f1 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSectionTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSectionTests.java @@ -328,4 +328,27 @@ public class ClientYamlTestSectionTests extends AbstractClientYamlTestFragmentPa assertThat(testSection.getExecutableSections().size(), equalTo(3)); } + public void testAddingContainsWithoutSkip() { + int lineNumber = between(1, 10000); + ClientYamlTestSection section = new ClientYamlTestSection(new XContentLocation(0, 0), "test"); + if (randomBoolean()) { + section.setSkipSection(new SkipSection(null, singletonList("yaml"), null)); + } else { + section.setSkipSection(SkipSection.EMPTY); + } + Exception e = expectThrows( + IllegalArgumentException.class, + () -> section.addExecutableSection( + new ContainsAssertion( + new XContentLocation(lineNumber, 0), + randomAlphaOfLength(randomIntBetween(3, 30)), + randomDouble() + ) + ) + ); + assertEquals("Attempted to add a [contains] assertion without a corresponding " + + "[skip: \"features\": \"contains\"] so runners that do not support the [contains] assertion " + + "can skip the test at line [" + lineNumber + "]", e.getMessage()); + } + }