Skip to content

Commit 7b1a837

Browse files
committed
Update test state when starting/completing a test
1 parent e8ff9b9 commit 7b1a837

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

autoload/OmniSharp/actions/test.vim

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function! s:run.single.test(bufferTests) abort
115115
return s:utils.log.warn('No test found')
116116
endif
117117
let s:run.running = 1
118+
call OmniSharp#testrunner#StateRunning(bufnr, currentTest.name)
118119
let project = OmniSharp#GetHost(bufnr).project
119120
let targetFramework = project.MsBuildProject.TargetFramework
120121
let opts = {
@@ -132,17 +133,22 @@ function! s:run.single.test(bufferTests) abort
132133
endfunction
133134

134135
function! s:run.single.complete(summary) abort
136+
if a:summary.pass && len(a:summary.locations) == 0
137+
echomsg 'No tests were run'
138+
" Do we ever reach here?
139+
" call OmniSharp#testrunner#StateSkipped(bufnr)
140+
endif
141+
let location = a:summary.locations[0]
142+
call s:run.updatestate(location)
135143
if a:summary.pass
136-
if len(a:summary.locations) == 0
137-
echomsg 'No tests were run'
138-
elseif get(a:summary.locations[0], 'type', '') ==# 'W'
139-
call s:utils.log.warn(a:summary.locations[0].name . ': skipped')
144+
if get(location, 'type', '') ==# 'W'
145+
call s:utils.log.warn(location.name . ': skipped')
140146
else
141-
call s:utils.log.emphasize(a:summary.locations[0].name . ': passed')
147+
call s:utils.log.emphasize(location.name . ': passed')
142148
endif
143149
else
144-
echomsg a:summary.locations[0].name . ': failed'
145-
let title = 'Test failure: ' . a:summary.locations[0].name
150+
echomsg location.name . ': failed'
151+
let title = 'Test failure: ' . location.name
146152
let what = {}
147153
if len(a:summary.locations) > 1
148154
let what.quickfixtextfunc = {info->
@@ -187,7 +193,9 @@ function! s:run.multiple.prepare(bufferTests) abort
187193
for btests in a:bufferTests
188194
let bufnr = btests.bufnr
189195
let tests = btests.tests
196+
let testnames = map(copy(tests), {_,t -> t.name})
190197
if len(tests)
198+
call OmniSharp#testrunner#StateRunning(bufnr, testnames)
191199
call add(Requests, funcref('s:run.multiple.inBuffer', [bufnr, tests]))
192200
endif
193201
endfor
@@ -232,6 +240,9 @@ function! s:run.multiple.complete(summary) abort
232240
let pass = 0
233241
endif
234242
endfor
243+
for location in locations
244+
call s:run.updatestate(location)
245+
endfor
235246
if pass
236247
let title = len(locations) . ' tests passed'
237248
call s:utils.log.emphasize(title)
@@ -271,6 +282,8 @@ function! s:run.process(Callback, bufnr, tests, response) abort
271282
for result in a:response.Body.Results
272283
" Strip namespace and classname from test method name
273284
let location = {
285+
\ 'bufnr': a:bufnr,
286+
\ 'fullname': result.MethodName,
274287
\ 'filename': bufname(a:bufnr),
275288
\ 'name': substitute(result.MethodName, '^.*\.', '', '')
276289
\}
@@ -336,6 +349,16 @@ function! s:run.process(Callback, bufnr, tests, response) abort
336349
call a:Callback(summary)
337350
endfunction
338351

352+
function! s:run.updatestate(location) abort
353+
if get(a:location, 'type', '') ==# 'E'
354+
call OmniSharp#testrunner#StateFailed(a:location.bufnr, a:location.fullname)
355+
elseif get(a:location, 'type', '') ==# 'W'
356+
call OmniSharp#testrunner#StateSkipped(a:location.bufnr, a:location.fullname)
357+
else
358+
call OmniSharp#testrunner#StatePassed(a:location.bufnr, a:location.fullname)
359+
endif
360+
endfunction
361+
339362

340363
function! OmniSharp#actions#test#Validate() abort
341364
return s:utils.capabilities()

autoload/OmniSharp/testrunner.vim

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ function s:Open() abort
4545
call s:Paint()
4646
endfunction
4747

48-
function! OmniSharp#testrunner#Repaint() abort
49-
" Check that the test runner has been initialised and is still a loaded buffer
48+
function! s:Repaint() abort
5049
if !exists('s:testrunner_bufnr') | return | endif
5150
if getbufvar(s:testrunner_bufnr, '&ft') !=# 'omnisharptest' | return | endif
5251
" If the buffer is listed in a window in the current tab, then focus it
@@ -112,6 +111,39 @@ function! OmniSharp#testrunner#SetTests(bufferTests) abort
112111
call win_gotoid(winid)
113112
endfunction
114113

114+
function! s:UpdateState(bufnr, testnames, state) abort
115+
let job = OmniSharp#GetHost(a:bufnr).job
116+
let filename = fnamemodify(bufname(a:bufnr), ':p')
117+
let tests = get(job.tests, filename, {})
118+
for testname in a:testnames
119+
if has_key(tests, testname)
120+
let tests[testname].state = a:state
121+
endif
122+
endfor
123+
call s:Repaint()
124+
endfunction
125+
126+
function! OmniSharp#testrunner#StateRunning(bufnr, testnames) abort
127+
let testnames = type(a:testnames) == type([]) ? a:testnames : [a:testnames]
128+
let s:lasttestnames = testnames
129+
call s:UpdateState(a:bufnr, testnames, 'Running')
130+
endfunction
131+
132+
function! OmniSharp#testrunner#StateSkipped(bufnr, ...) abort
133+
let testnames = a:0 ? (type(a:1) == type([]) ? a:1 : [a:1]) : s:lasttestnames
134+
call s:UpdateState(a:bufnr, testnames, 'Not run')
135+
endfunction
136+
137+
function! OmniSharp#testrunner#StatePassed(bufnr, ...) abort
138+
let testnames = a:0 ? (type(a:1) == type([]) ? a:1 : [a:1]) : s:lasttestnames
139+
call s:UpdateState(a:bufnr, testnames, 'Passed')
140+
endfunction
141+
142+
function! OmniSharp#testrunner#StateFailed(bufnr, ...) abort
143+
let testnames = a:0 ? (type(a:1) == type([]) ? a:1 : [a:1]) : s:lasttestnames
144+
call s:UpdateState(a:bufnr, testnames, 'Failed')
145+
endfunction
146+
115147
let &cpoptions = s:save_cpo
116148
unlet s:save_cpo
117149

0 commit comments

Comments
 (0)