Skip to content

Commit

Permalink
Add assertion messages (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Oct 31, 2024
1 parent 8f3a56b commit 083ff95
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/junitxml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ export type JunitXml = {
}

function assertJunitXml(x: unknown): asserts x is JunitXml {
assert(typeof x === 'object')
assert(x != null)
assert(typeof x === 'object', 'root document must be an object')
assert(x != null, 'root document must not be null')

if ('testsuites' in x) {
assert(typeof x.testsuites === 'object')
assert(x.testsuites != null)
assert(typeof x.testsuites === 'object', 'testsuites must be an object')
assert(x.testsuites != null, 'testsuites must not be null')

if ('testsuite' in x.testsuites) {
assert(Array.isArray(x.testsuites.testsuite))
assert(Array.isArray(x.testsuites.testsuite), 'testsuite must be an array')
for (const testsuite of x.testsuites.testsuite) {
assertTestSuite(testsuite)
}
}
}

if ('testsuite' in x) {
assert(Array.isArray(x.testsuite))
assert(Array.isArray(x.testsuite), 'testsuite must be an array')
for (const testsuite of x.testsuite) {
assertTestSuite(testsuite)
}
Expand All @@ -40,21 +40,21 @@ export type TestSuite = {
}

function assertTestSuite(x: unknown): asserts x is TestSuite {
assert(typeof x === 'object')
assert(x != null)
assert('@_name' in x)
assert(typeof x['@_name'] === 'string')
assert('@_time' in x)
assert(typeof x['@_time'] === 'number')
assert(typeof x === 'object', 'testsuite must be an object')
assert(x != null, 'testsuite must not be null')
assert('@_name' in x, 'testsuite must have name attribute')
assert(typeof x['@_name'] === 'string', 'name attribute must be a string')
assert('@_time' in x, 'testsuite must have time attribute')
assert(typeof x['@_time'] === 'number', 'time attribute must be a number')

if ('testsuite' in x) {
assert(Array.isArray(x.testsuite))
assert(Array.isArray(x.testsuite), 'testsuite must be an array')
for (const testsuite of x.testsuite) {
assertTestSuite(testsuite)
}
}
if ('testcase' in x) {
assert(Array.isArray(x.testcase))
assert(Array.isArray(x.testcase), 'testcase must be an array')
for (const testcase of x.testcase) {
assertTestCase(testcase)
}
Expand All @@ -75,31 +75,31 @@ export type TestCase = {
}

function assertTestCase(x: unknown): asserts x is TestCase {
assert(typeof x === 'object')
assert(x != null)
assert('@_name' in x)
assert(typeof x['@_name'] === 'string')
assert('@_time' in x)
assert(typeof x['@_time'] === 'number')
assert(typeof x === 'object', 'testcase must be an object')
assert(x != null, 'testcase must not be null')
assert('@_name' in x, 'testcase must have name attribute')
assert(typeof x['@_name'] === 'string', 'name attribute must be a string')
assert('@_time' in x, 'testcase must have time attribute')
assert(typeof x['@_time'] === 'number', 'time attribute must be a number')

if ('@_classname' in x) {
assert(typeof x['@_classname'] === 'string')
assert(typeof x['@_classname'] === 'string', 'classname attribute must be a string')
}
if ('@_file' in x) {
assert(typeof x['@_file'] === 'string')
assert(typeof x['@_file'] === 'string', 'file attribute must be a string')
}
if ('failure' in x) {
assert(typeof x.failure === 'object')
assert(x.failure != null)
assert(typeof x.failure === 'object', 'failure must be an object')
assert(x.failure != null, 'failure must not be null')
if ('@_message' in x.failure) {
assert(typeof x.failure['@_message'] === 'string')
assert(typeof x.failure['@_message'] === 'string', 'message attribute of failure element must be a string')
}
}
if ('error' in x) {
assert(typeof x.error === 'object')
assert(x.error != null)
assert(typeof x.error === 'object', 'error must be an object')
assert(x.error != null, 'error must not be null')
if ('@_message' in x.error) {
assert(typeof x.error['@_message'] === 'string')
assert(typeof x.error['@_message'] === 'string', 'message attribute of error element must be a string')
}
}
}
Expand Down

0 comments on commit 083ff95

Please sign in to comment.