Skip to content

Commit

Permalink
- gracefully handle corrupt test export files
Browse files Browse the repository at this point in the history
  - RELATES TO #952
  • Loading branch information
mikepenz authored Oct 20, 2023
1 parent 7e43ff9 commit 7964d8e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
28 changes: 28 additions & 0 deletions __tests__/testParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,4 +1085,32 @@ action.surefire.report.email.InvalidEmailAddressException: Invalid email address
}
])
})

it('parse corrupt test output', async () => {
const result = await parseTestReports(
'',
'',
'test_results/corrupt-junit/**/target/surefire-reports/TEST-*.xml',
'',
false,
false,
[],
'',
'',
undefined,
false,
undefined
)

expect(result).toStrictEqual({
checkName: "",
summary: "",
totalCount: 0,
skipped: 0,
failed: 0,
passed: 0,
annotations: [
],
})
})
})
14 changes: 13 additions & 1 deletion src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,19 @@ export async function parseFile(
core.debug(`Parsing file ${file}`)

const data: string = fs.readFileSync(file, 'utf8')
const report = JSON.parse(parser.xml2json(data, {compact: true}))

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let report: any
try {
report = JSON.parse(parser.xml2json(data, {compact: true}))
} catch (error) {
core.error(`⚠️ Failed to parse file (${file}) with error ${error}`)
return {
totalCount: 0,
skipped: 0,
annotations: []
}
}

return parseSuite(
report,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="corrupt.CorruptTest" time="11.288" tests="1" errors="0" skipped="0" failures="1">
<properties>
<property name="idea.io.use.nio2" value="true"/>
<property name="java.ext.dirs" value="/opt/hostedtoolcache/jdk/8.0.382/x64/jre/lib/ext:/usr/java/packages/lib/ext"/>
<property name="java.class.version" value="52.0"/>
<property name="ast.loading.filter" value="false"/>
</properties>
<testcase name="testEM" classname="corrupt.CorruptTest" time="10.131">
<failure type="java.lang.AssertionError"><![CDATA[java.lang.AssertionError: WRONG COVERAGE: 41 > 26
at corrupt.core.Main$Companion.initAndRun(Main.kt:244)
at corrupt.core.Main.initAndRun(Main.kt)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
]]></failure>
<system-out><![CDATA[

0 comments on commit 7964d8e

Please sign in to comment.