private void setComparisonFailure(Trouble tr, String line) { // #190267: exclude "big" log (if any) from the matching int logPos = line.indexOf("Log:"); // NOI18N if(logPos > 0) { line = line.substring(0, logPos); } Matcher matcher = regexp.getComparisonPattern().matcher(line.replaceAll("\n", "")); // NOI18N if (matcher.matches()){ String startExpected = "expected:<"; // NOI18N String startActual = "> but was:<"; // NOI18N tr.setComparisonFailure( new Trouble.ComparisonFailure( line.substring(line.indexOf(startExpected) + startExpected.length(), line.indexOf(startActual)), line.substring(line.indexOf(startActual) + startActual.length(), line.length() - 1)) ); return; } matcher = regexp.getComparisonHiddenPattern().matcher(line); if (matcher.matches()){ tr.setComparisonFailure( new Trouble.ComparisonFailure( matcher.group(1), matcher.group(2)) ); return; } }
static Trouble constructTrouble(@NonNull String type, @NullAllowed String message, @NullAllowed String text, boolean error) { Trouble t = new Trouble(error); if (message != null) { Matcher match = COMPARISON_PATTERN.matcher(message); if (match.matches()) { t.setComparisonFailure(new Trouble.ComparisonFailure(match.group(1), match.group(2))); } else { match = COMPARISON_PATTERN_AFTER_65.matcher(message); if (match.matches()) { t.setComparisonFailure(new Trouble.ComparisonFailure(match.group(1), match.group(2))); } } } if (text != null) { String[] strs = StringUtils.split(text, "\n"); List<String> lines = new ArrayList<String>(); if (message != null) { lines.add(message); } lines.add(type); for (int i = 1; i < strs.length; i++) { lines.add(strs[i]); } t.setStackTrace(lines.toArray(new String[0])); } return t; }
Matcher matcher = regexp.getComparisonPattern().matcher(line); if (matcher.matches()){ trouble.setComparisonFailure( new Trouble.ComparisonFailure( matcher.group(1)+matcher.group(2)+matcher.group(3), trouble.setComparisonFailure( new Trouble.ComparisonFailure( matcher.group(1),
@Override public void setFailureInfo(String message, String[] stackTrace, boolean error, Diff diff) { Parameters.notNull("message", message); // NOI18N Parameters.notNull("stackTrace", stackTrace); // NOI18N Parameters.notNull("diff", diff); // NOI18N testSuite.checkFrozen(); Trouble trouble = new Trouble(error); trouble.setStackTrace(createStackTrace(message, stackTrace)); if (diff.isValid()) { Trouble.ComparisonFailure failure = new Trouble.ComparisonFailure(diff.getExpected(), diff.getActual()); trouble.setComparisonFailure(failure); } testCase.setTrouble(trouble); Manager manager = testSuite.getTestSession().getManager(); TestSession session = testSuite.getTestSession().getTestSession(); manager.displayOutput(session, getClassName() + "::" + testCase.getName() + "()", error); // NOI18N manager.displayOutput(session, message, error); testCase.addOutputLines(Collections.singletonList("<u>" + testCase.getName() + ":</u>")); // NOI18N for (String s : stackTrace) { manager.displayOutput(session, s, error); testCase.addOutputLines(Collections.singletonList(s.replace("<", "<"))); // NOI18N } manager.displayOutput(session, "", false); // NOI18N }