Skip to content

add python support #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
python test progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 27, 2020
commit 3df91512e8ec35321c9248fc743208648dbab2da
30 changes: 14 additions & 16 deletions src/services/testRunner/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ ok 4 test_add_two_numbers (tests.math_test.MathTest)
expect(parser(example)).toEqual({
ok: true,
passed: [
{ message: 'test_add_no_numbers' },
{ message: 'test_add_one_number' },
{ message: 'test_add_three_numbers' },
{ message: 'test_add_two_numbers' },
{ message: 'add no numbers' },
{ message: 'add one number' },
{ message: 'add three numbers' },
{ message: 'add two numbers' },
],
failed: [],
logs: [],
summary: {
test_add_no_numbers: true,
test_add_one_number: true,
test_add_three_numbers: true,
test_add_two_numbers: true,
'add no numbers': true,
'add one number': true,
'add three numbers': true,
'add two numbers': true,
},
})
})
Expand All @@ -229,14 +229,14 @@ not ok 1 test_add_no_numbers (tests.math_test.MathTest)
passed: [],
failed: [
{
message: 'test_add_no_numbers',
message: 'add no numbers',
details:
'Traceback (most recent call last):\n Fail Message\nAssertionError: 42 != 0 : Should return 0 with no params',
},
],
logs: [],
summary: {
test_add_no_numbers: false,
'add no numbers': false,
},
})
})
Expand All @@ -252,20 +252,18 @@ not ok 2 test_add_one_number (tests.math_test.MathTest)
`
expect(parser(example)).toEqual({
ok: true,
passed: [{ message: 'test_add_no_numbers' }],
passed: [{ message: 'add no numbers' }],
failed: [
{
message: 'test_add_one_number',
message: 'add one number',
details:
'Traceback (most recent call last):\n Fail Message\nAssertionError: 2 != 1 : Should add one number to 0',
},
],
logs: [],
summary: {
test_add_no_numbers: true,
test_add_one_number: true,
test_add_three_numbers: true,
test_add_two_numbers: true,
'add no numbers': true,
'add one number': false,
},
})
})
Expand Down
41 changes: 30 additions & 11 deletions src/services/testRunner/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,39 @@ export interface ParserOutput {
}

const r = {
start: /^1\.\.[0-9]+$/,
fail: /^not ok \d+\s(\-\s)?(.+)+$/,
pass: /^ok \d+\s(\-\s)?(.+)+$/,
details: /^#\s{2}(.+)$/,
ignore: /^#\s+(tests|pass|fail|skip)\s+[0-9]+$/,
start: /^(not ok)|(ok)/,
fail: /^not ok (?<index>\d+)\s(\-\s)?(?<message>.+)$/,
pass: /^ok (?<index>\d+)\s(\-\s)?(?<message>.+)$/,
details: /^#\s{2}(?<message>.+)$/,
ignore: /^(1\.\.[0-9]+)|(#\s+(tests|pass|fail|skip)\s+[0-9]+)$/,
}

const detect = (type: 'fail' | 'pass' | 'details', text: string) => r[type].exec(text)
const detect = (type: 'fail' | 'pass' | 'details', text: string) => {
const match = r[type].exec(text)
if (!match) {
return null
}
return match.groups
}

// see comment below for extracting logic into custom consumer later
const formatMessage = (message: string): string => {
// specific for python tap.py output
const isTappy = message.match(/^test_(?<underscoredMessage>.+)\s(?<testPath>.+)$/)
if (isTappy?.groups?.underscoredMessage) {
return isTappy.groups.underscoredMessage.split('_').join(' ').trim()
}
return message.trim()
}

// TODO: consider creating custom TAP consumers for languages
// otherwise code here will eventually get out of hand
// currently supports: mocha, python tap.py
const parser = (text: string): ParserOutput => {
const lineList = text.split('\n')
// start after 1..n output
const startingPoint = lineList.findIndex((t) => t.match(r.start))
const lines = lineList.slice(startingPoint + 1)
const lines = lineList.slice(startingPoint)

const result: ParserOutput = {
ok: true,
Expand All @@ -59,10 +78,10 @@ const parser = (text: string): ParserOutput => {
if (!line.length) {
continue
}
// be optimistic! check for success
// be optimistic! check for success first
const isPass = detect('pass', line)
if (!!isPass) {
const message = isPass[2].trim()
const message = formatMessage(isPass.message)
const pass: Pass = { message }
if (logs.length) {
pass.logs = logs
Expand All @@ -79,7 +98,7 @@ const parser = (text: string): ParserOutput => {
if (!!isFail) {
result.ok = false
addCurrentDetails()
const message = isFail[2].trim()
const message = formatMessage(isFail.message)
const fail: Fail = { message }
if (logs.length) {
fail.logs = logs
Expand All @@ -93,7 +112,7 @@ const parser = (text: string): ParserOutput => {
// check for error details
const isDetails = detect('details', line)
if (!!isDetails) {
const lineDetails: string = isDetails[1].trim()
const lineDetails: string = isDetails.message.trim()
if (!currentDetails) {
currentDetails = lineDetails
} else {
Expand Down