Skip to content

Commit c6d8893

Browse files
committed
Displaying only start of stack trace
1 parent 73be39c commit c6d8893

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

docker/kotlin-compiler-junit-runner.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
echo "TECHIO> terminal"
2+
#echo "TECHIO> terminal"
33
# Can be invoked as:
44
# xxx.sh SOURCE_DIR TestClass
55
# xxx.sh SOURCE_DIR TestClass#testMethod
@@ -37,7 +37,5 @@ compilationExitCode=$?
3737
if [ $compilationExitCode -eq 0 ]; then
3838
java -cp "${WORKSPACE_DIR}:$classpath:/opt/techio/junit-runner/junit-runner.jar" io.tech.runner.junit.JUnitTestListRunner $1
3939
else
40-
sleep 1000
4140
exit $compilationExitCode
4241
fi
43-
sleep 1000

maven3-junit4-runner/src/main/java/io/tech/runner/junit/JUnitTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class JUnitTest {
1212
* This captures ClassName or ClassName#methodName (e.g. TestBoid#testUnique)
1313
*/
1414
private static final Pattern COMMAND_PATTERN = Pattern.compile("(?<class>[^#]+)(?:#(?<method>[^#]+))?");
15+
16+
private String stackStop = null;
1517

1618
int run(String testcaseSpecification) {
1719
Request request = findRequest(testcaseSpecification);
@@ -31,9 +33,11 @@ Request findRequest(String testcaseSpecification) {
3133
String method = matcher.group("method");
3234
if (method != null) {
3335
request = Request.method(clazz, method);
36+
stackStop = clazz.getName() + "." + method;
3437
}
3538
else {
3639
request = Request.aClass(clazz);
40+
stackStop = clazz.getName();
3741
}
3842
}
3943
catch (ClassNotFoundException ignored) {}
@@ -43,7 +47,7 @@ Request findRequest(String testcaseSpecification) {
4347

4448
private int runTestCase(Request request) {
4549
JUnitCore jUnitCore = new JUnitCore();
46-
jUnitCore.addListener(new TestResultFormatter());
50+
jUnitCore.addListener(new TestResultFormatter(stackStop));
4751
return jUnitCore.run(request).wasSuccessful() ? 0 : 1;
4852
}
4953
}
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
11
package io.tech.runner.junit;
22

3+
import java.io.BufferedOutputStream;
4+
import java.io.PrintStream;
5+
36
import org.junit.runner.notification.Failure;
47
import org.junit.runner.notification.RunListener;
58

69
public class TestResultFormatter extends RunListener {
10+
11+
private String stackStop;
12+
13+
public TestResultFormatter(String stackStop) {
14+
this.stackStop = stackStop;
15+
}
16+
717
@Override
818
public void testFailure(Failure failure) {
9-
failure.getException().printStackTrace();
19+
20+
String[] stackLines = failure.getTrace().split("\n");
21+
22+
int excludeStart = stackLines.length;
23+
int excludeStop = stackLines.length;
24+
25+
for (int i = 0, il = stackLines.length; i < il; i++) {
26+
if (stackLines[i].contains(stackStop)) {
27+
excludeStart = i + 1;
28+
break;
29+
}
30+
}
31+
for (int i = excludeStart, il = stackLines.length; i < il; i++) {
32+
if (stackLines[i].contains("Caused by")) {
33+
excludeStop = i - 1;
34+
break;
35+
}
36+
}
37+
38+
PrintStream ps = new PrintStream(new BufferedOutputStream(System.err));
39+
40+
for (int i = 0, il = stackLines.length; i < il; i++) {
41+
if (i < excludeStart || i > excludeStop) {
42+
ps.print(stackLines[i]);
43+
}
44+
}
1045
}
1146
}

0 commit comments

Comments
 (0)