Skip to content

Commit 3df9151

Browse files
committed
python test progress
Signed-off-by: shmck <[email protected]>
1 parent 2e13c25 commit 3df9151

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

Diff for: src/services/testRunner/parser.test.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,18 @@ ok 4 test_add_two_numbers (tests.math_test.MathTest)
201201
expect(parser(example)).toEqual({
202202
ok: true,
203203
passed: [
204-
{ message: 'test_add_no_numbers' },
205-
{ message: 'test_add_one_number' },
206-
{ message: 'test_add_three_numbers' },
207-
{ message: 'test_add_two_numbers' },
204+
{ message: 'add no numbers' },
205+
{ message: 'add one number' },
206+
{ message: 'add three numbers' },
207+
{ message: 'add two numbers' },
208208
],
209209
failed: [],
210210
logs: [],
211211
summary: {
212-
test_add_no_numbers: true,
213-
test_add_one_number: true,
214-
test_add_three_numbers: true,
215-
test_add_two_numbers: true,
212+
'add no numbers': true,
213+
'add one number': true,
214+
'add three numbers': true,
215+
'add two numbers': true,
216216
},
217217
})
218218
})
@@ -229,14 +229,14 @@ not ok 1 test_add_no_numbers (tests.math_test.MathTest)
229229
passed: [],
230230
failed: [
231231
{
232-
message: 'test_add_no_numbers',
232+
message: 'add no numbers',
233233
details:
234234
'Traceback (most recent call last):\n Fail Message\nAssertionError: 42 != 0 : Should return 0 with no params',
235235
},
236236
],
237237
logs: [],
238238
summary: {
239-
test_add_no_numbers: false,
239+
'add no numbers': false,
240240
},
241241
})
242242
})
@@ -252,20 +252,18 @@ not ok 2 test_add_one_number (tests.math_test.MathTest)
252252
`
253253
expect(parser(example)).toEqual({
254254
ok: true,
255-
passed: [{ message: 'test_add_no_numbers' }],
255+
passed: [{ message: 'add no numbers' }],
256256
failed: [
257257
{
258-
message: 'test_add_one_number',
258+
message: 'add one number',
259259
details:
260260
'Traceback (most recent call last):\n Fail Message\nAssertionError: 2 != 1 : Should add one number to 0',
261261
},
262262
],
263263
logs: [],
264264
summary: {
265-
test_add_no_numbers: true,
266-
test_add_one_number: true,
267-
test_add_three_numbers: true,
268-
test_add_two_numbers: true,
265+
'add no numbers': true,
266+
'add one number': false,
269267
},
270268
})
271269
})

Diff for: src/services/testRunner/parser.ts

+30-11
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,39 @@ export interface ParserOutput {
2020
}
2121

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

30-
const detect = (type: 'fail' | 'pass' | 'details', text: string) => r[type].exec(text)
30+
const detect = (type: 'fail' | 'pass' | 'details', text: string) => {
31+
const match = r[type].exec(text)
32+
if (!match) {
33+
return null
34+
}
35+
return match.groups
36+
}
37+
38+
// see comment below for extracting logic into custom consumer later
39+
const formatMessage = (message: string): string => {
40+
// specific for python tap.py output
41+
const isTappy = message.match(/^test_(?<underscoredMessage>.+)\s(?<testPath>.+)$/)
42+
if (isTappy?.groups?.underscoredMessage) {
43+
return isTappy.groups.underscoredMessage.split('_').join(' ').trim()
44+
}
45+
return message.trim()
46+
}
3147

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

3857
const result: ParserOutput = {
3958
ok: true,
@@ -59,10 +78,10 @@ const parser = (text: string): ParserOutput => {
5978
if (!line.length) {
6079
continue
6180
}
62-
// be optimistic! check for success
81+
// be optimistic! check for success first
6382
const isPass = detect('pass', line)
6483
if (!!isPass) {
65-
const message = isPass[2].trim()
84+
const message = formatMessage(isPass.message)
6685
const pass: Pass = { message }
6786
if (logs.length) {
6887
pass.logs = logs
@@ -79,7 +98,7 @@ const parser = (text: string): ParserOutput => {
7998
if (!!isFail) {
8099
result.ok = false
81100
addCurrentDetails()
82-
const message = isFail[2].trim()
101+
const message = formatMessage(isFail.message)
83102
const fail: Fail = { message }
84103
if (logs.length) {
85104
fail.logs = logs
@@ -93,7 +112,7 @@ const parser = (text: string): ParserOutput => {
93112
// check for error details
94113
const isDetails = detect('details', line)
95114
if (!!isDetails) {
96-
const lineDetails: string = isDetails[1].trim()
115+
const lineDetails: string = isDetails.message.trim()
97116
if (!currentDetails) {
98117
currentDetails = lineDetails
99118
} else {

0 commit comments

Comments
 (0)