Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw useful error on bad docs snippets #25389

Merged
merged 1 commit into from
Jun 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
*/
Set<String> unconvertedCandidates = new HashSet<>()

/**
* The last non-TESTRESPONSE snippet.
*/
Snippet previousTest

/**
* Called each time a snippet is encountered. Tracks the snippets and
* calls buildTest to actually build the test.
Expand All @@ -142,6 +147,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
}
if (snippet.testSetup) {
setup(snippet)
previousTest = snippet
return
}
if (snippet.testResponse) {
Expand All @@ -150,6 +156,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
}
if (snippet.test || snippet.console) {
test(snippet)
previousTest = snippet
return
}
// Must be an unmarked snippet....
Expand All @@ -158,7 +165,18 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
private void test(Snippet test) {
setupCurrent(test)

if (false == test.continued) {
if (test.continued) {
/* Catch some difficult to debug errors with // TEST[continued]
* and throw a helpful error message. */
if (previousTest == null || previousTest.path != test.path) {
throw new InvalidUserDataException("// TEST[continued] " +
"cannot be on first snippet in a file: $test")
}
if (previousTest != null && previousTest.testSetup) {
throw new InvalidUserDataException("// TEST[continued] " +
"cannot immediately follow // TESTSETUP: $test")
}
} else {
current.println('---')
current.println("\"line_$test.start\":")
/* The Elasticsearch test runner doesn't support the warnings
Expand Down