Skip to content

Commit

Permalink
JBEHAVE-806: Jbehave doesn't reformat stack traces on Windows
Browse files Browse the repository at this point in the history
added cr/lf conversion to StackTraceFormatter, added unit test for an Exception
  • Loading branch information
alexlehm committed Jul 30, 2012
1 parent 991b54c commit 3a938a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String stackTrace(Throwable cause) {
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
cause.printStackTrace(new PrintStream(out));
return stackTrace(out.toString());
return stackTrace(out.toString().replaceAll("\r",""));
}

protected String stackTrace(String stackTrace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,18 @@ public void stackTracesShouldBeCompressible() throws IOException {
"\tat org.jbehave.core.embedder.StoryRunner$FineSoFar.run(StoryRunner.java:261)", formatter.stackTrace(start));
}

@Test
public void exceptionShouldBeCompressible() throws IOException {
// Given a compressing formatter
StackTraceFormatter formatter = new StackTraceFormatter(true);

// When I format an Exception
String trace=formatter.stackTrace(new Exception("some cause"));

// Then it looks like
assertEquals("java.lang.Exception: some cause\n"
+ "\tat org.jbehave.core.reporters.StackTraceFormatterBehaviour.exceptionShouldBeCompressible(StackTraceFormatterBehaviour.java:100)\n"
+ "\t(reflection-invoke)\n"
+ "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)", trace);
}
}

0 comments on commit 3a938a3

Please sign in to comment.