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

Feature Request: Failure Navigation #14

Closed
sheluchin opened this issue Jan 29, 2015 · 12 comments
Closed

Feature Request: Failure Navigation #14

sheluchin opened this issue Jan 29, 2015 · 12 comments

Comments

@sheluchin
Copy link

It would be convenient if there was an option to feed failures to the quickfix window and to be able to navigate to the failure lines the usual quickfix mappings. I've seen other vim testing plugins do this.

@janko
Copy link
Member

janko commented Jan 29, 2015

There already are even two ways to do it in vim-test:

  1. Instruct vim-test to use the "make" strategy for running tests. That will select the appropriate Vim compiler (if it's available), and run the command with Vim's built-in :make, which loads the errors into a quickfix.

    let test#strategy = 'make'
  2. Instruct vim-test to use the "dispatch" strategy for running tests. This uses Dispatch.vim's :Make command, which is like an asynchronous :make.

    let test#strategy = 'dispatch'

It's included in the readme, but I will try to emphasize it more and explain what each strategy does.

@janko janko closed this as completed Jan 29, 2015
@sheluchin
Copy link
Author

From what I can tell, using either make or dispatch feeds the entire result set into the quickfix window. Once there, it's possible to traverse the output as one might expect. This is different from what I meant.

I've seen other testing plugins feed the results into the quickfix window and allow the user to jump to the specific line on which each test failed using :cnext and :cprevious. These commands would navigate to the lines in the code where the failures occurred rather than navigating through the test output.

Is similar functionality available through vim-test?

@janko
Copy link
Member

janko commented Feb 2, 2015

What test runner are you using with vim-test? When a quickfix list is loaded with the output, but the failures are not "linked" to the file locations, that happens when the "compiler" for that test runner doesn't exist. What Vim compilers do is they are able to read the test output, and create a quickfix list out of it (which can be traverse with :cnext and :cprevious).

Unfortunately, if the compiler doesn't exist for your test runner, vim-test can't provide it for you, because I would like to limit the scope of what vim-test does.

@janko
Copy link
Member

janko commented Feb 2, 2015

Also, which other testing plugins do the quickfix? I would just like to take a look.

@sheluchin
Copy link
Author

I am using py.test for my test runner.

I can't recall exactly which testing plugin it was. It was some time ago. I believe it was https://github.com/reinh/vim-makegreen with the following command: map <leader>dt :set makeprg=python\ manage.py\ test\|:call MakeGreen()<CR>. At the time I was just using the Django test runner and not py.test.

@janko
Copy link
Member

janko commented Feb 3, 2015

For Python there is a "pyunit" Vim compiler, maybe it works for py.test. Try

:compiler pyunit
:set makeprg=py.test\ your\ test\ command

Then run :make and see if the errors are loaded in the quickfix. If yes, I can configure vim-test to use "pyunit" compiler for Python tests.

@sheluchin
Copy link
Author

Unfortunately that did not produce new results.

testresults

It looks about the same when the failure is within the code being tested rather than in the test itself.

@nixon
Copy link
Contributor

nixon commented Nov 30, 2015

I'm using the vim-makegreen plugin as a custom strategy in vim-test with this in ~/.vimrc:

function MakeGreenStrategy(cmd) abort
    call MakeGreen(join(split(a:cmd)[1:]))
endfunction
let g:test#custom_strategies = {'makegreen': function('MakeGreenStrategy')}
let g:test#strategy = 'makegreen'

It may also be necessary to have the following ~/.vim/ftplugin/python.vim:

setlocal makeprg=nosetests
setlocal errorformat=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m

This works for me to show the green or red bar at the bottom, plus the command output goes into the quickfix buffer.

@benoittgt
Copy link

In quite the same subject (tell me if I'm out of thread), is it possible to jump to the first failed test ?

I'm working essentially with rspec and minitest.

@janko
Copy link
Member

janko commented Mar 1, 2016

Well, since dispatch.vim generates a quickfix list with file locations from the test runner output, you can jump to the first failed test in the same way as you would jump to any first item in a quickfix list, with :cc.

@codeinabox
Copy link
Collaborator

I have noticed that this is a common question and until recently I didn't know you could leverage Dispatch and the compiler functionality to do so. If I get time I will create a PR that explains this in the README.

@janko
Copy link
Member

janko commented Jun 17, 2017

@codeinabox I was hoping that people would just take a look at the documentation for each strategy to see if there is one that populates the quickfix list, but I guess it makes sense to explicitly document Dispatch.vim as it's probably the most comfortable strategy. You could also mention that make, neomake, and now makegreen strategies also populate the quickfix, and that they use Dispatch.vim to automatically find the appropriate compiler if Dispatch.vim is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants