Skip to content
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

WIP: Test runner #789

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4364a0b
Refactor test-running code for readability
nickspoons May 26, 2022
fa4a6c8
Namespace test functions in function dictionaries
nickspoons May 27, 2022
d768ddf
Refactor test extraction into initialisation
nickspoons May 29, 2022
42c9426
Add new test runner buffer
nickspoons Jun 2, 2022
b4bab8c
Add initial omnisharptest syntax file
nickspoons Jun 3, 2022
f1f0db9
Add testrunner Repaint function for updating state
nickspoons Jun 3, 2022
9acd572
Update test state when starting/completing a test
nickspoons Jun 4, 2022
0fba289
Add spinner for running tests
nickspoons Jun 5, 2022
3b2d256
Add option to disable quickfix for test results
nickspoons Jun 5, 2022
109d923
Update testrunner state when debugging test
nickspoons Jun 5, 2022
1b60e7f
Display Console output and fold syntax regions
nickspoons Jun 10, 2022
d5e247a
Display failure message and exception stack trace
nickspoons Jun 11, 2022
939147b
Add default utf-8 running spinner
nickspoons Jun 11, 2022
c4b0840
Clean up output and conceal namespaces
nickspoons Jun 12, 2022
2e3411a
Extend testrunner quick-help banner
nickspoons Jun 13, 2022
a831962
Add <F1> mapping and variable to toggle banner
nickspoons Jun 13, 2022
063b3b9
Handle server-side errors and failed builds
nickspoons Jun 14, 2022
f682f1e
Display diagnostic test output (build status)
nickspoons Jun 14, 2022
a3771d0
Add option for when to display build output
nickspoons Jun 15, 2022
ebbd022
Improve highlighting of concealed elements
nickspoons Jun 16, 2022
09e3f91
Navigate to test locations
nickspoons Jun 16, 2022
05a2fb5
Add <Plug> and default testrunner mappings
nickspoons Jun 16, 2022
2793374
Add space between projects to fix fold levels
nickspoons Jun 20, 2022
ca1da95
Run test/tests in file/tests in project
nickspoons Jun 23, 2022
7aafe93
Add F9 mapping to set breakpoints on stacktrace
nickspoons Jun 25, 2022
6450ab8
Add single break-point when error is under cursor
nickspoons Jun 25, 2022
4642e11
Debug test from test runner
nickspoons Jun 26, 2022
0f34524
Add mapping to remove test/file/proj from runner
nickspoons Jun 27, 2022
4d38a67
Refactor test dict from job.tests to s:tests
nickspoons Jun 29, 2022
7d3b690
Add foldtext for testrunner folds
nickspoons Jul 3, 2022
fe9bff8
Toggle banner without repainting buffer
nickspoons Jul 14, 2022
4719213
Update test without repainting buffer
nickspoons Jul 15, 2022
37967f6
Only repaint when initializing new tests
nickspoons Jul 15, 2022
7f561c7
Add success/failure glyph beside completed tests
nickspoons Jul 16, 2022
d95a041
Set g:OmniSharp_runtests_echo_output default to 0
nickspoons Jul 19, 2022
00f7b41
Namespace test functions in function dictionaries
nickspoons Jul 19, 2022
7a6b45a
Document g:OmniSharp_runtests_quickfix
nickspoons Jul 19, 2022
8cd8375
Add option not to automatically open testrunner
nickspoons Jul 19, 2022
e8221e3
Repaint project output/errors on UpdateState
nickspoons Jul 20, 2022
44c338e
Center banner title
nickspoons Jul 28, 2022
7df4b20
Repaint correctly after hiding (removing) project
nickspoons Jul 28, 2022
27dd928
Allow selection of running test
nickspoons Aug 13, 2022
a012145
Document the omnisharp-testrunner feature
nickspoons Aug 29, 2022
fc53ee2
Strip method signature from NUnit test name
nickspoons Sep 21, 2022
76d05a9
Add test Discover function
nickspoons Oct 4, 2022
9446021
"Discover" tests before calling test runners
nickspoons Oct 4, 2022
969c34a
Update state and repaint multiple NUnit sources
nickspoons Oct 4, 2022
034dea5
Correctly run multiple NUnit tests (RunInFile)
nickspoons Oct 29, 2022
4d2b315
Exclude quickfix stack locations from runner
nickspoons Feb 27, 2023
ce1c0f4
Allow opening test runner while test is running
nickspoons Feb 27, 2023
e97eab6
Add :OmniSharpTestRunnerReset command
nickspoons Apr 24, 2023
57f602a
Refactor documentation
nickspoons Apr 24, 2023
d5a1415
Wrap popups at word boundaries by default
nickspoons Apr 24, 2023
66a2d62
Fix incorrect help tag
nickspoons Oct 16, 2024
File filter

Filter by extension

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
"Discover" tests before calling test runners
nickspoons committed Oct 18, 2024
commit 94460213a579fc82fdcf5e507d611cc54dde4e76
55 changes: 37 additions & 18 deletions autoload/OmniSharp/actions/test.vim
Original file line number Diff line number Diff line change
@@ -298,15 +298,11 @@ function! s:run.process(Callback, bufnr, tests, response) abort
\ 'locations': []
\}
for result in a:response.Body.Results
" Strip method signature from test method fullname
let fullname = substitute(result.MethodName, '(.*)$', '', '')
" Strip namespace and classname from test method name
let name = substitute(result.MethodName, '^.*\.', '', '')
let location = {
\ 'bufnr': a:bufnr,
\ 'fullname': fullname,
\ 'fullname': result.MethodName,
\ 'filename': bufname(a:bufnr),
\ 'name': name
\ 'name': substitute(result.MethodName, '^.*\.', '', '')
\}
let locations = [location]
" Write any standard output to message-history
@@ -393,22 +389,44 @@ function! s:utils.capabilities() abort
endfunction

" Find all of the test methods in a CodeStructure response
function! s:utils.extractTests(codeElements) abort
function! s:utils.extractTests(bufnr, codeElements) abort
if type(a:codeElements) != type([]) | return [] | endif
let filename = fnamemodify(bufname(a:bufnr), ':p')
let testlines = map(
\ filter(
\ copy(OmniSharp#GetHost(a:bufnr).project.tests),
\ {_,dt -> dt.CodeFilePath ==# filename}),
\ {_,dt -> dt.LineNumber})
let tests = []
for element in a:codeElements
if has_key(element, 'Properties')
\ && type(element.Properties) == type({})
\ && has_key(element.Properties, 'testMethodName')
\ && has_key(element.Properties, 'testFramework')
call add(tests, {
\ 'name': element.Properties.testMethodName,
\ 'framework': element.Properties.testFramework,
\ 'range': element.Ranges.full,
\ 'nameRange': element.Ranges.name,
\})
" Compare with project discovered tests. Note that test discovery may
" include a test multiple times, if the test can be run with different
" arguments (e.g. NUnit TestCaseSource)

" Discovered test line numbers begin at the first line of code, not the
" line containing the test name, so when the method opening brace is not
" on the same line as the test method name, the line numbers will not
" match. We therefore search ahead for the closest line number, and use
" that.
let testStart = element.Ranges.name.Start.Line
let testStart = min(filter(copy(testlines), {_,l -> l >= testStart}))
for dt in OmniSharp#GetHost(a:bufnr).project.tests
if dt.CodeFilePath ==# filename && dt.LineNumber == testStart
" \ 'name': element.Properties.testMethodName,
call add(tests, {
\ 'name': dt.FullyQualifiedName,
\ 'framework': element.Properties.testFramework,
\ 'range': element.Ranges.full,
\ 'nameRange': element.Ranges.name,
\})
endif
endfor
endif
call extend(tests, self.extractTests(get(element, 'Children', [])))
call extend(tests, self.extractTests(a:bufnr, get(element, 'Children', [])))
endfor
return tests
endfunction
@@ -429,12 +447,13 @@ function! s:utils.findTest(tests, testName) abort
return 0
endfunction

" For the given buffers, fetch the project structures, then fetch the buffer
" code structures. All operations are performed asynchronously, and the
" For the given buffers, discover the project's tests (which includes fetching
" the project structure if it hasn't already been fetched. Finally, fetch the
" buffer code structures. All operations are performed asynchronously, and the
" a:Callback is called when all buffer code structures have been fetched.
function! s:utils.initialize(buffers, Callback) abort
call OmniSharp#testrunner#Init(a:buffers)
call s:utils.init.await(a:buffers, 'OmniSharp#actions#project#Get',
call s:utils.init.await(a:buffers, 'OmniSharp#testrunner#Discover',
\ funcref('s:utils.init.await', [a:buffers, 'OmniSharp#actions#codestructure#Get',
\ funcref('s:utils.init.extract', [a:Callback])]))
endfunction
@@ -447,7 +466,7 @@ endfunction
function! s:utils.init.extract(Callback, codeStructures) abort
let bufferTests = map(a:codeStructures, {i, cs -> {
\ 'bufnr': cs[0],
\ 'tests': s:utils.extractTests(cs[1])
\ 'tests': s:utils.extractTests(cs[0], cs[1])
\}})
call OmniSharp#testrunner#SetTests(bufferTests)
let dict = { 'f': a:Callback }