From b8907b04b1a18afa0f86aed18e103b3d59b12798 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 27 Jun 2018 15:41:44 -0400 Subject: [PATCH] Docs: Skip xpack snippet tests if no xpack (#31619) Skips tests the require xpack if we run the doc build without xpack. So this should work: ``` ./gradlew -p docs check -Dtests.distribution=oss-zip ``` This is implemented by detecting parts of the doc that look like: ``` [testenv="basic"] ``` Relates to #30665 --- .../gradle/doc/RestTestsFromSnippetsTask.groovy | 12 ++++++++++++ .../org/elasticsearch/gradle/doc/SnippetsTask.groovy | 11 ++++++++++- docs/build.gradle | 4 +++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy index 3c056a5528b..f2105086f25 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy @@ -237,6 +237,18 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { current.println(" - stash_in_path") current.println(" - stash_path_replace") current.println(" - warnings") + if (test.testEnv != null) { + switch (test.testEnv) { + case 'basic': + case 'gold': + case 'platinum': + current.println(" - xpack") + break; + default: + throw new InvalidUserDataException('Unsupported testEnv: ' + + test.testEnv) + } + } } if (test.skipTest) { if (test.continued) { diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/SnippetsTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/SnippetsTask.groovy index 7132361e163..ec012633f08 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/SnippetsTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/SnippetsTask.groovy @@ -84,6 +84,7 @@ public class SnippetsTask extends DefaultTask { Snippet snippet = null StringBuilder contents = null List substitutions = null + String testEnv = null Closure emit = { snippet.contents = contents.toString() contents = null @@ -143,10 +144,14 @@ public class SnippetsTask extends DefaultTask { } file.eachLine('UTF-8') { String line, int lineNumber -> Matcher matcher + matcher = line =~ /\[testenv="([^"]+)"\]\s*/ + if (matcher.matches()) { + testEnv = matcher.group(1) + } if (line ==~ /-{4,}\s*/) { // Four dashes looks like a snippet if (snippet == null) { Path path = docs.dir.toPath().relativize(file.toPath()) - snippet = new Snippet(path: path, start: lineNumber) + snippet = new Snippet(path: path, start: lineNumber, testEnv: testEnv) if (lastLanguageLine == lineNumber - 1) { snippet.language = lastLanguage } @@ -297,6 +302,7 @@ public class SnippetsTask extends DefaultTask { int start int end = NOT_FINISHED String contents + String testEnv Boolean console = null boolean test = false @@ -321,6 +327,9 @@ public class SnippetsTask extends DefaultTask { } if (test) { result += '// TEST' + if (testEnv != null) { + result += "[testenv=$testEnv]" + } if (catchPart) { result += "[catch: $catchPart]" } diff --git a/docs/build.gradle b/docs/build.gradle index b04016c946e..790820c9765 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -63,6 +63,8 @@ buildRestTests.docs = fileTree(projectDir) { exclude 'README.asciidoc' } +listSnippets.docs = buildRestTests.docs + Closure setupTwitter = { String name, int count -> buildRestTests.setups[name] = ''' - do: @@ -603,4 +605,4 @@ buildRestTests.setups['library'] = ''' {"index":{"_id": "The Moon is a Harsh Mistress"}} {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288} -''' \ No newline at end of file +'''