/** * Determines the most interesting frame for the user. When user * double-clicks on a failed test method, the editor will jump to the * location corresponding to that frame. * * @param trouble description of the test failure * @return string describing the chosen call-stack frame, or {@code null} if * no frame has been chosen */ public static String determineStackFrame(Trouble trouble) { String[] frames = trouble.getStackTrace(); return ((frames != null) && (frames.length != 0)) ? frames[frames.length - 1] : null; }
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; }
public DiffViewAction(Testcase testcase) { this(testcase.getTrouble() != null ? testcase.getTrouble().getComparisonFailure() : null); }
String[] stArray = tr.getStackTrace(); if (stArray == null){ tr.setStackTrace(new String[]{line}); setComparisonFailure(tr, line); } else { List<String> stList = new ArrayList(Arrays.asList(trouble.getStackTrace())); if (!line.startsWith(stList.get(stList.size()-1))){ stList.add(line); tr.setStackTrace(stList.toArray(new String[stList.size()]));
String[] stArray = trouble.getStackTrace(); if (stArray == null){ trouble.setStackTrace(new String[]{line}); 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), List<String> stList = new ArrayList(Arrays.asList(testcase.getTrouble().getStackTrace())); if (!line.startsWith(stList.get(stList.size()-1))){ stList.add(line); trouble.setStackTrace(stList.toArray(new String[stList.size()]));
@Override @NbBundle.Messages("LBL_CopyStackTrace=&Copy Stack Trace") public Action[] getActions(boolean context) { List<Action> actions = new ArrayList<Action>(); if ((testcase.getTrouble() != null) && (testcase.getTrouble().getComparisonFailure() != null)){ actions.add(new DiffViewAction(testcase)); } if (testcase.getTrouble() != null && testcase.getTrouble().getStackTrace() != null) { StringBuilder callStack = new StringBuilder(); for(String stack : testcase.getTrouble().getStackTrace()) { if(stack != null) { callStack.append(stack.concat("\n")); } } if (callStack.length() > 0) { final String trace = callStack.toString(); actions.add(new AbstractAction(Bundle.LBL_CopyStackTrace()) { @Override public void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(trace), null); } }); } } return actions.toArray(new Action[actions.size()]); }
/** */ private boolean tryParseBriefHeader(String testcaseHeader) { final Matcher matcher = regexp.getTestcaseHeaderBriefPattern() .matcher(testcaseHeader); if (matcher.matches()) { String methodName = matcher.group(1); String clsName = matcher.group(2); boolean error = (matcher.group(3) == null); testcase = findTest(testSession.getCurrentSuite(), methodName); if (testcase == null){ // probably TestListener interface not reported test progress for some reason (for ex. debug mode) testcase = new JUnitTestcase(methodName, "JUnit test", testSession); testSession.addTestCase(testcase); } testcase.setClassName(clsName); Trouble trouble = testcase.getTrouble(); if (trouble == null){ trouble = new Trouble(error); testcase.setTrouble(trouble); }else{ trouble.setError(error); trouble.setStackTrace(null); } return true; } else { return false; } }
return; testSession.getCurrentTestCase().setTrouble(new Trouble(shortMsg.equals(ADD_ERROR_PREFIX))); boolean hasErrMsg = (commaIndex != -1) && ((commaIndex + 2) <= insideBrackets.length()); // #166912
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; } }
trouble = new Trouble(state == STATE_ERROR);
/** * Determines the most interesting frame for the user. * When user double-clicks on a failed test method, the editor will jump * to the location corresponding to that frame. * * @param trouble description of the test failure * @return string describing the chosen call-stack frame, * or {@code null} if no frame has been chosen */ static String determineStackFrame(Trouble trouble) { String[] frames = trouble.getStackTrace(); return ((frames != null) && (frames.length != 0)) ? frames[frames.length - 1] : null; }
@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 }
/** */ @Override protected void addNotify() { Trouble trouble = testcase.getTrouble(); int stackTraceLength = trouble.getStackTrace() != null ? trouble.getStackTrace().length : 0; Node[] children = new Node[stackTraceLength]; TestRunnerNodeFactory nodeFactory = Manager.getInstance().getNodeFactory(); for (int i = 0; i < stackTraceLength; i++) { if (i == 0 && stackTraceLength >= 2) { children[i] = nodeFactory.createCallstackFrameNode(trouble.getStackTrace()[1], trouble.getStackTrace()[0]); } else { children[i] = nodeFactory.createCallstackFrameNode(trouble.getStackTrace()[i], null); } } add(children); } }
if (INLINE_RESULTS && testcase.getTrouble() != null && testcase.getTrouble().getStackTrace() != null && testcase.getTrouble().getStackTrace().length > 0) { try { cause = XMLUtil.toElementContent(testcase.getTrouble().getStackTrace()[0]).replace("\n", " "); // NOI18N } catch (CharConversionException ex) {
String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if (st != null) { stack.append("\n"); String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if ((st != null) && (st.length > 0)) { int index = st.length - 1;
String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if (st != null) { stack.append("\n"); String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if ((st != null) && (st.length > 0)) { int index = st.length - 1;
String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if ((st != null) && (st.length > 0)) { int index = st.length - 1;
public void openCallstackFrame(Node node, String frameInfo) { if(!(node instanceof TestNGMethodNode)) { return; } TestNGMethodNode methodNode = (TestNGMethodNode) UIJavaUtils.getTestMethodNode(node); FileLocator locator = methodNode.getTestcase().getSession().getFileLocator(); if (locator == null) { return; } final int[] lineNumStorage = new int[1]; FileObject file = UIJavaUtils.getFile(frameInfo, lineNumStorage, locator); if ((file == null) && (methodNode.getTestcase().getTrouble() != null)) { String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if ((st != null) && (st.length > 0)) { file = UIJavaUtils.getFile(st[st.length - 1], lineNumStorage, locator); } } UIJavaUtils.openFile(file, lineNumStorage[0]); } }