Skip to content

Commit fda953f

Browse files
authored
ESQL: Fix skipping of generative tests (#132390) (#132436)
The error message can sometimes be split into multiple lines with backslashes marking the line boundaries. Let's make our skips work even in case of overlong lines. (cherry picked from commit ccfbf49) # Conflicts: # muted-tests.yml
1 parent 90f66ad commit fda953f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static CommandGenerator.ValidationResult checkResults(
144144
);
145145
if (outputValidation.success() == false) {
146146
for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) {
147-
if (allowedError.matcher(outputValidation.errorMessage()).matches()) {
147+
if (isAllowedError(outputValidation.errorMessage(), allowedError)) {
148148
return outputValidation;
149149
}
150150
}
@@ -155,13 +155,24 @@ private static CommandGenerator.ValidationResult checkResults(
155155

156156
private void checkException(EsqlQueryGenerator.QueryExecuted query) {
157157
for (Pattern allowedError : ALLOWED_ERROR_PATTERNS) {
158-
if (allowedError.matcher(query.exception().getMessage()).matches()) {
158+
if (isAllowedError(query.exception().getMessage(), allowedError)) {
159159
return;
160160
}
161161
}
162162
fail("query: " + query.query() + "\nexception: " + query.exception().getMessage());
163163
}
164164

165+
/**
166+
* Long lines in exceptions can be split across several lines. When a newline is inserted, the end of the current line and the beginning
167+
* of the new line are marked with a backslash {@code \}; the new line will also have whitespace before the backslash for aligning.
168+
*/
169+
private static final Pattern ERROR_MESSAGE_LINE_BREAK = Pattern.compile("\\\\\n\\s*\\\\");
170+
171+
private static boolean isAllowedError(String errorMessage, Pattern allowedPattern) {
172+
String errorWithoutLineBreaks = ERROR_MESSAGE_LINE_BREAK.matcher(errorMessage).replaceAll("");
173+
return allowedPattern.matcher(errorWithoutLineBreaks).matches();
174+
}
175+
165176
@SuppressWarnings("unchecked")
166177
private EsqlQueryGenerator.QueryExecuted execute(String command, int depth) {
167178
try {

0 commit comments

Comments
 (0)