@@ -4,12 +4,18 @@ set cpoptions&vim
4
4
5
5
let s: current = get (s: , ' current' , {})
6
6
let s: runner = get (s: , ' runner' , {})
7
+ let s: tests = get (s: , ' tests' , {})
8
+
9
+ " Expose s:tests for custom scripting
10
+ function ! OmniSharp#testrunner#GetTests () abort
11
+ return s: tests
12
+ endfunction
7
13
8
14
9
15
function ! OmniSharp#testrunner#Debug () abort
10
16
let filename = ' '
11
17
let line = getline (' .' )
12
- if line = ~# ' ^\a ' || line = ~# ' ^ \f'
18
+ if line = ~# ' ^; ' || line = ~# ' ^ \f'
13
19
return s: utils .log .warn (' Select a test to debug' )
14
20
else
15
21
let test = s: utils .findTest ()
@@ -35,17 +41,12 @@ endfunction
35
41
function ! OmniSharp#testrunner#Run () abort
36
42
let filename = ' '
37
43
let line = getline (' .' )
38
- if line = ~# ' ^\a '
44
+ if line = ~# ' ^; '
39
45
" Project selected - run all tests
40
- let projectname = getline (' .' )
41
- for sln_or_dir in OmniSharp#proc#ListRunningJobs ()
42
- let job = OmniSharp#proc#GetJob (sln_or_dir)
43
- if has_key (job, ' tests' ) && has_key (job.tests, projectname)
44
- let filenames = filter (keys (job.tests[projectname]),
45
- \ {_,f - > ! get (job.tests[projectname][f ], ' __OmniSharp__removed' )})
46
- call OmniSharp#actions#test#RunInFile (1 , filenames)
47
- endif
48
- endfor
46
+ let projectname = matchlist (getline (' .' ), ' ^\S\+' )[0 ]
47
+ let filenames = filter (keys (s: tests [projectname].files ),
48
+ \ {_,f - > s: tests [projectname].files [f ].visible})
49
+ call OmniSharp#actions#test#RunInFile (1 , filenames)
49
50
elseif line = ~# ' ^ \f'
50
51
" File selected
51
52
let filename = trim (line )
@@ -63,31 +64,19 @@ endfunction
63
64
function ! OmniSharp#testrunner#Remove () abort
64
65
let filename = ' '
65
66
let line = getline (' .' )
66
- if line = ~# ' ^\a '
67
+ if line = ~# ' ^; '
67
68
" Project selected - run all tests
68
- let projectname = getline (' .' )
69
- for sln_or_dir in OmniSharp#proc#ListRunningJobs ()
70
- let job = OmniSharp#proc#GetJob (sln_or_dir)
71
- if has_key (job, ' tests' ) && has_key (job.tests, projectname)
72
- let job.tests[projectname].__OmniSharp__removed = 1
73
- break
74
- endif
75
- endfor
69
+ let projectname = matchlist (getline (' .' ), ' ^\S\+' )[0 ]
70
+ let s: tests [projectname].visible = 0
76
71
elseif line = ~# ' ^ \f'
77
72
" File selected
78
73
let filename = fnamemodify (trim (line ), ' :p' )
79
- let projectline = search (' ^\a ' , ' bcnWz' )
74
+ let projectline = search (' ^; ' , ' bcnWz' )
80
75
let projectname = matchlist (getline (projectline), ' ^\S\+' )[0 ]
81
- for sln_or_dir in OmniSharp#proc#ListRunningJobs ()
82
- let job = OmniSharp#proc#GetJob (sln_or_dir)
83
- if has_key (job, ' tests' ) && has_key (job.tests, projectname)
84
- let job.tests[projectname][filename].__OmniSharp__removed = 1
85
- break
86
- endif
87
- endfor
76
+ let s: tests [projectname].files [filename].visible = 0
88
77
else
89
78
let test = s: utils .findTest ()
90
- let test.__OmniSharp__removed = 1
79
+ let test.state = ' hidden '
91
80
endif
92
81
call s: Paint ()
93
82
endfunction
@@ -100,7 +89,7 @@ function! OmniSharp#testrunner#Navigate() abort
100
89
let lnum = -1
101
90
let col = -1
102
91
let line = getline (' .' )
103
- if line = ~# ' ^\a '
92
+ if line = ~# ' ^; '
104
93
" Project selected - do nothing
105
94
elseif line = ~# ' ^ \f'
106
95
" File selected
@@ -216,64 +205,63 @@ function! s:Paint() abort
216
205
call add (lines , repeat (delimiter , 80 ))
217
206
endif
218
207
219
- for sln_or_dir in OmniSharp#proc#ListRunningJobs ()
220
- let job = OmniSharp#proc#GetJob (sln_or_dir)
221
- if ! has_key (job, ' tests' ) | continue | endif
222
- for testproject in sort (keys (job.tests))
223
- if get (job.tests[testproject], ' __OmniSharp__removed' ) | continue | endif
224
- let errors = get (get (job, ' testerrors' , {}), testproject, [])
225
- call add (lines , testproject . (len (errors) ? ' - ERROR' : ' ' ))
226
- for errorline in errors
227
- call add (lines , ' < ' . trim (errorline, ' ' , 2 ))
228
- endfor
229
- let loglevel = get (g: , ' OmniSharp_testrunner_loglevel' , ' error' )
230
- if loglevel == ? ' all' || (loglevel == ? ' error' && len (errors))
231
- " The diagnostic logs (build output) are only displayed when a single file
232
- " is tested, otherwise multiple build outputs are intermingled
233
- if OmniSharp#GetHost (s: current .singlebuffer).sln_or_dir == # sln_or_dir
234
- if len (errors) > 0 && len (s: current .log ) > 1
208
+ for key in sort (keys (s: tests ))
209
+ let [assembly, sln] = split (key , ' ;' )
210
+ if ! s: tests [key ].visible | continue | endif
211
+ call add (lines , key . (len (s: tests [key ].errors) ? ' ERROR' : ' ' ))
212
+ for errorline in s: tests [key ].errors
213
+ call add (lines , ' < ' . trim (errorline, ' ' , 2 ))
214
+ endfor
215
+ let loglevel = get (g: , ' OmniSharp_testrunner_loglevel' , ' error' )
216
+ if loglevel == ? ' all' || (loglevel == ? ' error' && len (s: tests [key ].errors))
217
+ " The diagnostic logs (build output) are only displayed when a single file
218
+ " is tested, otherwise multiple build outputs are intermingled
219
+ if s: current .singlebuffer != -1
220
+ let [ssln, sass, _] = s: utils .getProject (s: current .singlebuffer)
221
+ if ssln == # sln && sass == # assembly
222
+ if len (s: tests [key ].errors) > 0 && len (s: current .log ) > 1
235
223
call add (lines , ' < ' . repeat (delimiter , 10 ))
236
224
endif
237
225
for log in s: current .log
238
226
call add (lines , ' < ' . trim (log , ' ' , 2 ))
239
227
endfor
240
228
endif
241
229
endif
242
- for testfile in sort (keys (job.tests[testproject]))
243
- let tests = job.tests[testproject][testfile]
244
- if get (tests, ' __OmniSharp__removed' ) | continue | endif
245
- call add (lines , ' ' . fnamemodify (testfile, ' :.' ))
246
- for name in sort (keys (tests), {a ,b - > tests[a ].lnum > tests[b ].lnum})
247
- let test = tests[name]
248
- if get (test, ' __OmniSharp__removed' ) | continue | endif
249
- let state = s: utils .state2char[test.state ]
250
- call add (lines , printf (' %s %s' , state , name))
251
- if state == # ' -' && ! has_key (test, ' spintimer' )
252
- call s: spinner .start (test, len (lines ))
230
+ endif
231
+ for testfile in sort (keys (s: tests [key ].files ))
232
+ if ! s: tests [key ].files [testfile].visible | continue | endif
233
+ let tests = s: tests [key ].files [testfile].tests
234
+ call add (lines , ' ' . fnamemodify (testfile, ' :.' ))
235
+ for name in sort (keys (tests), {a ,b - > tests[a ].lnum > tests[b ].lnum})
236
+ let test = tests[name]
237
+ if test.state == # ' hidden' | continue | endif
238
+ let state = s: utils .state2char[test.state ]
239
+ call add (lines , printf (' %s %s' , state , name))
240
+ if state == # ' -' && ! has_key (test, ' spintimer' )
241
+ call s: spinner .start (test, len (lines ))
242
+ endif
243
+ for messageline in get (test, ' message' , [])
244
+ call add (lines , ' > ' . trim (messageline, ' ' , 2 ))
245
+ endfor
246
+ for stacktraceline in get (test, ' stacktrace' , [])
247
+ let line = trim (stacktraceline.text)
248
+ if has_key (stacktraceline, ' filename' )
249
+ let line = ' __ ' . line . ' ___ ' . stacktraceline.filename . ' __ '
250
+ else
251
+ let line = ' _._ ' . line . ' _._ '
253
252
endif
254
- for messageline in get (test, ' message' , [])
255
- call add (lines , ' > ' . trim (messageline, ' ' , 2 ))
256
- endfor
257
- for stacktraceline in get (test, ' stacktrace' , [])
258
- let line = trim (stacktraceline.text)
259
- if has_key (stacktraceline, ' filename' )
260
- let line = ' __ ' . line . ' ___ ' . stacktraceline.filename . ' __ '
261
- else
262
- let line = ' _._ ' . line . ' _._ '
263
- endif
264
- if has_key (stacktraceline, ' lnum' )
265
- let line .= ' line ' . stacktraceline.lnum
266
- endif
267
- call add (lines , ' > ' . line )
268
- endfor
269
- for outputline in get (test, ' output' , [])
270
- call add (lines , ' // ' . trim (outputline, ' ' , 2 ))
271
- endfor
253
+ if has_key (stacktraceline, ' lnum' )
254
+ let line .= ' line ' . stacktraceline.lnum
255
+ endif
256
+ call add (lines , ' > ' . line )
257
+ endfor
258
+ for outputline in get (test, ' output' , [])
259
+ call add (lines , ' // ' . trim (outputline, ' ' , 2 ))
272
260
endfor
273
- call add (lines , ' __' )
274
261
endfor
275
- call add (lines , ' ' )
262
+ call add (lines , ' __ ' )
276
263
endfor
264
+ call add (lines , ' ' )
277
265
endfor
278
266
279
267
if bufnr () == s: runner .bufnr | let winview = winsaveview () | endif
@@ -318,29 +306,22 @@ endfunction
318
306
function ! OmniSharp#testrunner#SetTests (bufferTests) abort
319
307
let winid = win_getid ()
320
308
for buffer in a: bufferTests
321
- let job = OmniSharp#GetHost (buffer .bufnr ).job
322
- let job.tests = get (job, ' tests' , {})
323
- let projectname = s: utils .getProjectName (buffer .bufnr )
324
- let testproject = get (job.tests, projectname, {})
325
- if has_key (testproject, ' __OmniSharp__removed' )
326
- unlet testproject.__OmniSharp__removed
327
- endif
328
- let job.tests[projectname] = testproject
309
+ let [sln, assembly, key ] = s: utils .getProject (buffer .bufnr )
310
+ let project = get (s: tests , key , { ' files' : {}, ' errors' : [] })
311
+ let project.visible = 1
312
+ let s: tests [key ] = project
329
313
let filename = fnamemodify (bufname (buffer .bufnr ), ' :p' )
330
- let filetests = get (testproject, filename, {})
331
- if has_key (testproject, ' __OmniSharp__removed' )
332
- unlet testproject.__OmniSharp__removed
333
- endif
334
- let testproject[filename] = filetests
314
+ let testfile = get (project.files , filename, { ' tests' : {} })
315
+ let testfile.visible = 1
316
+ let project.files [filename] = testfile
335
317
for buffertest in buffer .tests
336
- let test = get (filetests, buffertest.name, { ' state' : ' Not run' })
337
- if has_key (test, ' __OmniSharp__removed' )
338
- unlet test.__OmniSharp__removed
339
- endif
340
- let filetests[buffertest.name] = test
341
- let test.name = buffertest.name
318
+ let name = buffertest.name
319
+ let test = get (testfile.tests, name, { ' state' : ' Not run' })
320
+ let testfile.tests[name] = test
321
+ let test.name = name
342
322
let test.filename = filename
343
- let test.projectname = projectname
323
+ let test.assembly = assembly
324
+ let test.sln = sln
344
325
let test.framework = buffertest.framework
345
326
let test.lnum = buffertest.nameRange.Start.Line
346
327
endfor
@@ -352,12 +333,10 @@ endfunction
352
333
353
334
function ! s: UpdateState (bufnr , state , ... ) abort
354
335
let opts = a: 0 ? a: 1 : {}
355
- let job = OmniSharp#GetHost (a: bufnr ).job
356
- let projectname = s: utils .getProjectName (a: bufnr )
357
- let job.testerrors = get (job, ' testerrors' , {})
358
- let job.testerrors[projectname] = get (opts, ' errors' , [])
336
+ let [sln, assembly, key ] = s: utils .getProject (a: bufnr )
337
+ let s: tests [key ].errors = get (opts, ' errors' , [])
359
338
let filename = fnamemodify (bufname (a: bufnr ), ' :p' )
360
- let tests = job. tests[projectname] [filename]
339
+ let tests = s: tests [key ]. files [filename].tests
361
340
for testname in get (opts, ' testnames' , s: current .testnames[a: bufnr ])
362
341
if has_key (tests, testname)
363
342
let stacktrace = []
@@ -507,25 +486,22 @@ function! s:utils.findTest() abort
507
486
endif
508
487
if testline > 0
509
488
let testname = matchlist (getline (testline), ' [-|*!] \zs.*$' )[0 ]
510
- let projectline = search (' ^\a ' , ' bcnWz' )
489
+ let projectline = search (' ^; ' , ' bcnWz' )
511
490
let projectname = matchlist (getline (projectline), ' ^\S\+' )[0 ]
512
491
let fileline = search (' ^ \f' , ' bcnWz' )
513
492
let filename = matchlist (getline (fileline), ' ^ \zs.*$' )[0 ]
514
493
let filename = fnamemodify (filename, ' :p' )
515
- for sln_or_dir in OmniSharp#proc#ListRunningJobs ()
516
- let job = OmniSharp#proc#GetJob (sln_or_dir)
517
- if has_key (job, ' tests' ) && has_key (job.tests, projectname)
518
- return job.tests[projectname][filename][testname]
519
- endif
520
- endfor
494
+ return s: tests [projectname].files [filename].tests[testname]
521
495
endif
522
496
return {}
523
497
endfunction
524
498
525
- function ! s: utils .getProjectName (bufnr ) abort
526
- let project = OmniSharp#GetHost (a: bufnr ).project
527
- let msbuildproject = get (project, ' MsBuildProject' , {})
528
- return get (msbuildproject, ' AssemblyName' , ' _Default' )
499
+ function ! s: utils .getProject (bufnr ) abort
500
+ let host = OmniSharp#GetHost (a: bufnr )
501
+ let msbuildproject = get (host.project, ' MsBuildProject' , {})
502
+ let sln = host.sln_or_dir
503
+ let assembly = get (msbuildproject, ' AssemblyName' , ' _Default' )
504
+ return [sln, assembly, printf (' ;%s;%s;' , assembly, sln)]
529
505
endfunction
530
506
531
507
function ! s: utils .log .echo (highlightGroup, message) abort
0 commit comments