Skip to content

Commit ed0e37a

Browse files
committed
Yet more improvement to stack trace trimming
1 parent fa9b502 commit ed0e37a

File tree

4 files changed

+50
-36
lines changed

4 files changed

+50
-36
lines changed

dist/index.js

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grader/builder/GradleBuilder.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,10 @@ export default class GradleBuilder extends Builder {
106106
const ret = testResultsContents.flatMap((result) => {
107107
return result.testSuites.flatMap((suite) => {
108108
return suite.testCases.map((test) => {
109-
const trimStackTrace = (stackTrace: string | undefined) => {
110-
if (!stackTrace) {
111-
return ''
112-
}
113-
const lines = stackTrace.split('\n')
114-
const idxOfFirstMethodAccessorImpl = lines.findIndex((line) =>
115-
line.includes('MethodAccessorImpl')
116-
)
117-
return lines.slice(0, idxOfFirstMethodAccessorImpl).join('\n')
118-
}
119109
const tr: TestResult = {
120110
name: `${suite.name}.${test.name}`,
121111
status: test.failure || test.error ? 'fail' : 'pass',
122-
output: test.failure ? trimStackTrace(test.failure.stackTrace) : '',
112+
output: test.failure?.stackTrace || test.error?.stackTrace || '',
123113
output_format: 'text'
124114
}
125115
return tr

src/grader/builder/surefire.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,36 @@ export interface SurefireReport {
4040
}
4141
}
4242

43-
function trimJunit5StackTrace(stackTrace: string): string {
43+
function trimJunitStackTrace(stackTrace: string): string {
4444
if (!stackTrace) {
4545
return ''
4646
}
4747
const lines = stackTrace.split('\n')
48-
const idxOfJunitLine = lines.findIndex((line) =>
49-
line.includes('org.junit.jupiter.engine.execution.MethodInvocation.proceed')
48+
const idxOfJunitLine = lines.findIndex(
49+
(line) =>
50+
line.includes(
51+
'org.junit.jupiter.engine.execution.MethodInvocation.proceed'
52+
) || line.includes('org.junit.runners.BlockJUnit4ClassRunner')
5053
)
51-
return idxOfJunitLine === -1
52-
? stackTrace
53-
: lines.slice(0, idxOfJunitLine).join('\n')
54+
if (idxOfJunitLine === -1) {
55+
return stackTrace
56+
}
57+
58+
let idxOfLastReflectionLineFromBottom = -1
59+
for (let i = idxOfJunitLine - 1; i >= 0; i--) {
60+
if (
61+
!lines[i].includes('jdk.internal.reflect') &&
62+
!lines[i].includes('java.lang.reflect') &&
63+
!lines[i].includes('org.junit.platform.commons.util.ReflectionUtils')
64+
) {
65+
idxOfLastReflectionLineFromBottom = i + 1
66+
break
67+
}
68+
}
69+
if (idxOfLastReflectionLineFromBottom === -1) {
70+
return lines.slice(0, idxOfJunitLine).join('\n')
71+
}
72+
return lines.slice(0, idxOfLastReflectionLineFromBottom).join('\n')
5473
}
5574

5675
export function parseSurefireXml(filePath: string): SurefireReport {
@@ -106,7 +125,7 @@ export function parseSurefireXml(filePath: string): SurefireReport {
106125
message: testCase.failure.message || '',
107126
type: testCase.failure.type || '',
108127
description: testCase.failure._text || '',
109-
stackTrace: trimJunit5StackTrace(testCase.failure._text || '')
128+
stackTrace: trimJunitStackTrace(testCase.failure._text || '')
110129
}
111130
}
112131

@@ -116,7 +135,7 @@ export function parseSurefireXml(filePath: string): SurefireReport {
116135
message: testCase.error.message || '',
117136
type: testCase.error.type || '',
118137
description: testCase.error._text || '',
119-
stackTrace: trimJunit5StackTrace(testCase.error._text || '')
138+
stackTrace: trimJunitStackTrace(testCase.error._text || '')
120139
}
121140
}
122141

0 commit comments

Comments
 (0)