Code Monkey home page Code Monkey logo

vim-test's Introduction

test.vim

CI workflow

A Vim wrapper for running tests on different granularities.

usage overview

Features

  • Zero dependencies
  • Zero configuration required (it Does the Right Thing™, see Philosophy)
  • Wide range of test runners which are automagically detected
  • Polyfills for nearest tests (by constructing regexes)
  • Wide range of execution environments ("strategies")
  • Fully customized CLI options configuration
  • Extendable with new runners and strategies

Test.vim consists of a core which provides an abstraction over running any kind of tests from the command-line. Concrete test runners are then simply plugged in, so they all work in the same unified way. Currently the following test runners are supported:

Language Test Runners Identifiers
C# .NET xunit, dotnettest
C++ CTest,Make ctest, make
Clojure Fireplace.vim, Leiningen fireplacetest, leintest
Crystal Crystal crystalspec
Dart Dart Test, Flutter Test darttest, fluttertest
Elixir ESpec, ExUnit espec, exunit
Elm elm-test elmtest
Erlang CommonTest, EUnit, PropEr commontest, eunit, proper
Go Ginkgo, Go, Rich-Go, Delve ginkgo, gotest, richgo, delve
Groovy Maven, Gradle maventest, gradletest
Haskell stack, cabal stacktest, cabaltest
Java Maven, Gradle (Groovy and Kotlin DSL) maventest, gradletest
JavaScript Ava, Cucumber.js, Cypress, Deno, Ember, Intern, Jasmine, Jest, Karma, Lab, Mocha, ng test, NX, Playwright, ReactScripts, TAP, Teenytest, WebdriverIO ava, cucumberjs, cypress, deno, ember exam, intern, jasmine, jest, karma, lab, mocha, ngtest , nx, playwright, reactscripts, tap, teenytest, webdriverio, vue-test-utils, vitest
Kotlin Gradle (Groovy and Kotlin DSL) gradletest
Lua Busted busted
Mint Mint minttest
Nim Nim unittest
PHP Behat, Codeception, Kahlan, Peridot, Pest, PHPUnit, Sail, PHPSpec, Dusk behat, codeception, dusk, kahlan, peridot, phpunit, sail, phpspec, pest
Perl Prove prove
Python Behave, Django, Mamba, Nose, Nose2, PyTest, PyUnit behave, djangotest, djangonose, mamba, nose, nose2, pytest, pyunit
Racket RackUnit rackunit
Ruby Cucumber, M, Minitest, Rails, RSpec, TestBench cucumber, m, minitest, rails, rspec, testbench
Rust Cargo, cargo-nextest cargotest, cargonextest
Scala SBT, Bloop sbttest, blooptest
Shell Bats, ShellSpec bats, shellspec
Swift Swift Package Manager swiftpm
VimScript Vader.vim, Vroom, VSpec, Themis, Testify vader, vroom, vspec, themis, testify
Zig ZigTest zigtest

Setup

Using vim-plug, add

Plug 'vim-test/vim-test'

to your .vimrc file (see vim-plug documentation for where), and run :PlugInstall.

Add your preferred mappings to your .vimrc file:

nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
nmap <silent> <leader>a :TestSuite<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
Command Description
:TestNearest In a test file runs the test nearest to the cursor, otherwise runs the last nearest test. In test frameworks that don't support line numbers it will polyfill this functionality with regexes.
:TestClass In a test file runs the first test class found on the same line as or above the cursor. (Currently only supported by Pytest)
:TestFile In a test file runs all tests in the current file, otherwise runs the last file tests.
:TestSuite Runs the whole test suite (if the current file is a test file, runs that framework's test suite, otherwise determines the test framework from the last run test).
:TestLast Runs the last test.
:TestVisit Visits the test file from which you last run your tests (useful when you're trying to make a test pass, and you dive deep into application code and close your test buffer to make more space, and once you've made it pass you want to go back to the test file to write more tests).

Strategies

Test.vim can run tests using different execution environments called "strategies". To use a specific strategy, assign it to a variable:

" make test commands execute using dispatch.vim
let test#strategy = "dispatch"
Strategy Identifier Description
Basic (default) basic Runs test commands with :! on Vim, and with :terminal on Neovim.
Make make make_bang Runs test commands with :make or :make!.
Neovim neovim Runs test commands with :terminal in a split window.
Neovim sticky neovim_sticky Runs test commands with :terminal in a split window, but keeps it open for subsequent runs.
Vim8 Terminal vimterminal Runs test commands with term_start() in a split window.
Dispatch dispatch dispatch_background Runs test commands with :Dispatch or :Dispatch!.
Vimux vimux Runs test commands in a small tmux pane at the bottom of your terminal.
Tslime tslime Runs test commands in a tmux pane you specify.
Slimux slimux Runs test commands in a tmux pane you specify.
Neoterm neoterm Runs test commands with :T, see neoterm docs for display customization.
Toggleterm toggleterm Runs test commands with TermExec
Floaterm floaterm Runs test commands within floating/popup terminal, see floaterm docs for display customization.
Neomake neomake Runs test commands asynchronously with :NeomakeProject.
MakeGreen makegreen Runs test commands with :MakeGreen.
VimShell vimshell Runs test commands in a shell written in VimScript.
Vim Tmux Runner vtr Runs test commands in a small tmux pane.
Tmuxify tmuxify Runs test commands in a small tmux pane at the bottom of your terminal.
VimProc vimproc Runs test commands asynchronously.
AsyncRun asyncrun asyncrun_background asyncrun_background_term Runs test commands asynchronosuly using new APIs in Vim 8 and NeoVim (:AsyncRun, :AsyncRun -mode=async -silent, or :AsyncRun -mode=term -pos=tab -focus=0 -listed=0).
Terminal.app terminal Sends test commands to Terminal (useful in MacVim GUI).
iTerm2.app iterm Sends test commands to iTerm2 >= 2.9 (useful in MacVim GUI).
Kitty kitty Sends test commands to Kitty terminal.
Shtuff shtuff Sends test commands to remote terminal via shtuff.
Harpoon harpoon Sends test commands to neovim terminal using a terminal managed by harpoon. By default commands are sent to terminal number 1, you can choose your terminal by setting g:test#harpoon_term with the terminal you want
WezTerm wezterm Sends test commands to an adjacent WezTerm pane.

You can also set up strategies per granularity:

let test#strategy = {
  \ 'nearest': 'neovim',
  \ 'file':    'dispatch',
  \ 'suite':   'basic',
\}

or even per command:

:TestFile -strategy=neovim

Some strategies clear the screen before executing the test command, but you can disable this:

let g:test#preserve_screen = 1

The Vimux strategy will not clear the screen by default, but you can enable it by explicitly setting test#preserve_screen to 0.

On Neovim the "basic" and "neovim" strategies will run test commands using Neovim's terminal, and leave you in insert mode, so that you can just press "Enter" to close the terminal session and go back to editing. If you want to scroll through the test command output, you'll have to first switch to normal mode. The built-in mapping for exiting terminal insert mode is CTRL-\ CTRL-n, which is difficult to press, so I recommend mapping it to CTRL-o:

if has('nvim')
  tmap <C-o> <C-\><C-n>
endif

If you prefer, you can instead have the terminal open in normal mode, so it does not close on key press.

let g:test#neovim#start_normal = 1 " If using neovim strategy
let g:test#basic#start_normal = 1 " If using basic strategy

By default vim-test will echo the test command before running it. You can disable this behavior with:

let g:test#echo_command = 0

With the Neovim sticky strategy, if an additional test run is requested before the previous one has finished, it will either wait or fail to run at all. You can customize this behavior with the following options:

let g:test#neovim_sticky#kill_previous = 1  " Try to abort previous run
let g:test#preserve_screen = 0  " Clear screen from previous run
let test#neovim_sticky#reopen_window = 1 " Reopen terminal split if not visible

Kitty strategy setup

Before you can run tests in a kitty terminal window using the kitty strategy, please make sure:

  • you start kitty setting up remote control and specifying a socket for kitty to listen to, like this:

    $ kitty -o allow_remote_control=yes --listen-on unix:/tmp/mykitty
    

    or via kitty.conf:

    allow_remote_control yes
    listen_on unix:/tmp/mykitty
    
  • you export an environment variable $KITTY_LISTEN_ON with the same socket, like:

    $ export KITTY_LISTEN_ON=unix:/tmp/mykitty
    

    or if via kitty.conf (it appends kitty's PID):

    $ export KITTY_LISTEN_ON=unix:/tmp/mykitty-$PPID
    

Shtuff strategy setup

This strategy lets you run commands in a remote terminal without needing tools like tmux or special terminals such as Kitty.

Before you can run tests using this strategy, you will need to have a terminal setup as a receiver, and also you'll need to set g:shtuff_receiver in your vimrc file.

In your terminal of choice:

$ shtuff as devrunner

And in your vimrc:

let g:shtuff_receiver = 'devrunner'

asyncrun_background and asyncrun_background_term setup

asyncrun_background will load test results into the quickfix buffer.

asyncrun_background_term will open a terminal in a new tab and run the tests while remaining in the current window.

These are hardcoded solutions and will not be affected by your global AsyncRun settings. If you want to switch between them then change test#strategy.

Note: the base asyncrun option will be affected by your global asyncrun settings.

Quickfix Strategies

If you want your test results to appear in the quickfix window, use one of the following strategies:

  • Make
  • Neomake
  • MakeGreen
  • Dispatch.vim
  • asyncrun_background

Regardless of which you pick, it's recommended you have Dispatch.vim installed as the strategies will automatically use it to determine the correct compiler, ensuring the test output is correctly parsed for the quickfix window.

As Dispatch.vim just determines the compiler, you need to make sure the Vim distribution or a plugin has a corresponding compiler for your test runner, or you may need to write a compiler plugin.

If the test command prefix doesn't match the compiler's makeprg then use the g:dispatch_compiler variable. For example if your test command was ./vendor/bin/phpunit but you wanted to use the phpunit2 compiler:

let g:dispatch_compilers = {}
let g:dispatch_compilers['./vendor/bin/'] = ''
let g:dispatch_compilers['phpunit'] = 'phpunit2'

Custom Strategies

Strategy is a function which takes one argument – the shell command for the test being run – and it is expected to run that command in some way. Test.vim comes with many predefined strategies (see above), but if none of them suit your needs, you can define your own custom strategy:

function! EchoStrategy(cmd)
  echo 'It works! Command for running tests: ' . a:cmd
endfunction

let g:test#custom_strategies = {'echo': function('EchoStrategy')}
let g:test#strategy = 'echo'

Transformations

You can automatically apply transformations of your test commands by registering a "transformation" function. The following example demonstrates how you could set up a transformation for Vagrant:

function! VagrantTransform(cmd) abort
  let vagrant_project = get(matchlist(s:cat('Vagrantfile'), '\vconfig\.vm.synced_folder ["''].+[''"], ["''](.+)[''"]'), 1)
  return 'vagrant ssh --command '.shellescape('cd '.vagrant_project.'; '.a:cmd)
endfunction

let g:test#custom_transformations = {'vagrant': function('VagrantTransform')}
let g:test#transformation = 'vagrant'

Commands

nearest polyfill

You can execute test.vim commands directly, and pass them CLI options:

:TestNearest --verbose
:TestFile --format documentation
:TestSuite --fail-fast
:TestLast --backtrace

If you want some options to stick around, see Configuring.

Environment variables

Environment variables are automatically detected from the arguments based on <VARIABLE>=value format, and prepended to the test command:

TestFile COVERAGE=1
" COVERAGE=1 bundle exec rspec something_spec.rb

Runner commands

Aside from the main commands, you get a corresponding Vim command for each test runner (which also accept options):

:RSpec --tag ~slow
:Mocha --grep 'API'
:ExUnit --trace
:Nose --failed

These commands are useful when using multiple testing frameworks in the same project, or as a wrapper around your executable. To avoid pollution they are not defined by default, instead you can choose the ones you want:

let g:test#runner_commands = ['Minitest', 'Mocha']

Configuring

CLI options

If you want some CLI options to stick around, you can configure them in your .vimrc:

let test#ruby#minitest#options = '--verbose'
let test#rust#cargotest#test_options = '-- --nocapture'

You can also choose a more granular approach:

let test#ruby#rspec#options = {
  \ 'nearest': '--backtrace',
  \ 'file':    '--format documentation',
  \ 'suite':   '--tag ~slow',
\}
let test#rust#cargotest#test_options = {
  \ 'nearest': ['--', '--nocapture'],
  \ 'file':    '',
\}

You can also specify a global approach along with the granular options for the specified test runner:

let test#ruby#rspec#options = {
  \ 'all':   '--backtrace',
  \ 'suite': '--tag ~slow',
\}

Vim8 / Neovim terminal position

Both the neovim and Vim8 Terminal strategy will open a split window on the bottom by default, but you can configure a different position or orientation. Whatever you put here is passed to new - so, you may also specify size (see :help opening-window or :help new for more info):

" for neovim
let test#neovim#term_position = "topleft"
let test#neovim#term_position = "vert"
let test#neovim#term_position = "vert botright 30"
" or for Vim8
let test#vim#term_position = "belowright"

For full list of variants, see :help opening-window.

Executable

You can instruct test.vim to use a custom executable for a test runner.

let test#ruby#rspec#executable = 'foreman run rspec'

File pattern

Test.vim has file pattern it uses to determine whether a file belongs to certain testing framework. You can override that pattern by overriding the file_pattern variable:

let test#ruby#minitest#file_pattern = '_spec\.rb' " the default is '\v(((^|/)test_.+)|_test)(spec)@<!\.rb$'

Filename modifier

By default test.vim generates file paths relative to the working directory. If you're using a strategy which sends commands to a shell which is cd-ed into another directory, you might want to change the filename modifier to generate absolute paths:

let test#filename_modifier = ':.' " test/models/user_test.rb (default)
let test#filename_modifier = ':p' " /User/janko/Code/my_project/test/models/user_test.rb
let test#filename_modifier = ':~' " ~/Code/my_project/test/models/user_test.rb

Working directory

Test.vim relies on you being cd-ed into the project root. However, sometimes you may want to execute tests from a different directory than Vim's current working directory. You might have a bigger project or monorepo with many subprojects, or you might be using autochdir. In any case, you can tell test.vim to use a different working directory for running tests:

let test#project_root = "/path/to/your/project"

Alternatively you can pass in a function that'll be evaluated before each test run.

function! CustomPath()
  return "~/Project"
endfunction

let test#project_root = function('CustomPath')

Language-specific

Python

If your project has a pytest configuration file, then pytest will automatically be detected. For other Python test runners, test.vim has no way of detecting which one did you intend to use. By default, the first available will be chosen, but you can force a specific one:

let test#python#runner = 'pytest'
" Runners available are 'pytest', 'nose', 'nose2', 'djangotest', 'djangonose', 'mamba', and Python's built-in unittest as 'pyunit'

The pytest and djangotest runner optionally supports pipenv. If you have a Pipfile, it will use pipenv run pytest instead of just python -m pytest. They also support poetry and will use poetry run pytest if it detects a poetry.lock. The pyunit and nose runner supports pipenv as well and will respectively use pipenv run python -m unittest or pipenv run python -m nosetests if there is a Pipfile. It also supports pdm as well and will use poetry run pytest if there is a pdm.lock file.

Java

For the same reason as Python, runner detection works the same for Java. To force a specific runner:

let test#java#runner = 'gradletest'

There is a specific strategy for Java with maven which invokes the mvn verify for a file instead of mvn test tailored for integration tests. In this way you can leverage the pre-integration goals, like firing up a database and so on. This strategy is called 'integration' and you can setup a command for it (preferably within the Java filetype plugin):

command! -nargs=* -bar IntegrationTest call test#run('integration', split(<q-args>))

With this set up you can run your integration tests with the :IntegrationTest plugin for that single file and module. As there might be some dependencies between the maven modules you might need to pass in other parameters for the tests just like any other commands in vim-test. Here is a mapping with other optional parameters:

nnoremap <silent><leader>itf :IntegrationTest -Dtest=foo -DfailIfNoTests=false -am -Dpmd.skip=true -Dcheckstyle.skip=true<CR>

The above command makes sure that no surefire tests will be run (by passing in a dummy test and makes sure that the plugin won't fail), it also makes the dependent modules, skips PMD and checkstyle checks as well.

Only for maven, the commands :TestFile and :TestNearest use the same strategy and you can use them to run the integration tests from file or method.

They use mvn verify if the filename ends with *IT, *ITCase or *Integration. The most common plugins are skipped in this strategy to improve the test time.

  • Sonar
  • PIT
  • Jacoco
  • Checkstyle
  • PMD
  • DependencyCheck
mvn verify -Dsonar.skip=true -Dpit.report.skip=true -Dpit.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true -Ddependency-check.skip=true -Djacoco.skip=true -Dfailsafe.only=true

Also, the parameter -Dfailsafe.only is added to the command by vim-test, so you can use it to configure other things in the pom.xml, for example to avoid surefire tests:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire.version}</version>
                <configuration>
                    <skipTests>${failsafe.only}</skipTests>
                ....
                </configuration>
                ...
            </plugin>

And keep the parameter -DskipTests working as expected:

    <properties>
        <failsafe.only>${skipTests}</failsafe.only>
    </properties>

Scala

For the same reason as Python, runner detection works the same for Scala. To force a specific runner:

let test#scala#runner = 'blooptest'

You may have subprojects inside your main sbt projects. Bloop project detection uses your main project to run tests. If you need to run test inside your subproject, you can specify custom projects with:

let g:test#scala#blooptest#project_name = 'custom-project'

With this configuration, the test runner will run test for custom-project:

$ bloop test custom-project

Go

For the same reason as Python, runner detection works the same for Go. To force a specific runner:

let test#go#runner = 'ginkgo'
" Runners available are 'gotest', 'ginkgo', 'richgo', 'delve'

You can also configure the delve runner with a different key mapping alongside another:

nmap <silent> t<C-n> :TestNearest<CR>
function! DebugNearest()
  let g:test#go#runner = 'delve'
  TestNearest
  unlet g:test#go#runner
endfunction
nmap <silent> t<C-d> :call DebugNearest()<CR>

If delve is selected and vim-delve is in use, breakpoints and tracepoints that have been marked with vim-delve will be included.

Ruby

Unless binstubs are detected (e.g. bin/rspec), test commands will automatically be prepended with bundle exec if a Gemfile is detected, but you can turn it off:

let test#ruby#bundle_exec = 0

If binstubs are detected, but you don't want to use them, you can turn them off:

let test#ruby#use_binstubs = 0

If your binstubs are not instrumented with spring, you can turn on using the spring bin (bin/spring) directly using:

let test#ruby#use_spring_binstub = 1

JavaScript

Test runner detection for JavaScript works by checking which runner is listed in the package.json dependencies. If you have globally installed the runner make sure it's also listed in the dependencies. When you have multiple runners listed in the package.json dependencies you can specify a runner like so:

let g:test#javascript#runner = 'jest'

Haskell

The stacktest runner is used by default. You can switch to cabaltest like so:

let g:test#haskell#runner = 'cabaltest'

You can pass additional arguments to the test runner by setting its test_command. Here's an example for cabal:

let g:test#haskell#cabaltest#test_command = 'test --test-show-details=direct'

The runners currently supports running tests with the HSpec framework.

PHP

The PHPUnit runner has support for the alternate runner ParaTest and will automatically use it if present in ./vendor/bin. If you prefer to use PHPUnit then override the executable:

let test#php#phpunit#executable = 'phpunit'

Similarly if you'd prefer to use an alternate runner such as the Laravel artisan runner then override the executable:

let test#php#phpunit#executable = 'php artisan test'

C++

Pattern for Test File: We assume all your test files are prefixed with "test_" or "Test". If not, override the following:

"Default
let g:test#cpp#catch2#file_pattern = '\v[tT]est.*(\.cpp)$'

File and Individual Test Case: We assume you are using make to compile your executables, whose names are exactly the same as the test file w/o the extension. If you would like to use change the make command, override the following:

let g:test#cpp#catch2#make_command = "make"

Creating Test Executables: We assume that a Makefile is located in a "build" directory directly below the project root. If not, override the following:

" If Makefile is at top of the project root, do this instead
let g:test#cpp#catch2#relToProject_build_dir = "."

We assume that your compiled executables are stored in build directory. If not, you can override this with:

let g:test#cpp#catch2#bin_dir = "../path/to/your/binaries/dir"

Suite: We assume that you are using Cmake as your build system, and are registering each test file to it. If not, override the following command.

let g:test#cpp#catch2#suite_command = "ctest --output-on-failure"

Rust

If the nextest cargo subcommand is available, cargo-nextest is used. cargo test is used otherwise. To force a specific runner:

let g:test#rust#runner = 'cargotest'

Autocommands

In addition to running tests manually, you can also configure autocommands which run tests automatically when files are saved.

The following setup will automatically run tests when a test file or its alternate application file is saved:

augroup test
  autocmd!
  autocmd BufWrite * if test#exists() |
    \   TestFile |
    \ endif
augroup END

Projectionist integration

If projectionist.vim is present, you can run a test command from an application file, and test.vim will automatically try to run the command on the "alternate" test file.

You can disable this integration by doing

let g:test#no_alternate = 1

Custom alternate file

If you are using a different library for jumping between implementation and test file you can define a custom function that returns the test filename.

function! CustomAlternateFile(cmd)
  return "test_file_spec.rb"
endfunction

let g:test#custom_alternate_file = function('CustomAlternateFile')

Extending

If you wish to extend this plugin with your own test runners, first of all, if the runner is well-known, I would encourage to help me merge it into test.vim.

That being said, if you want to do this for yourself, you need to do 2 things. First, add your runner to the list in your .vimrc:

" First letter of runner's name must be uppercase
let test#custom_runners = {'MyLanguage': ['MyRunner']}

Second, create ~/.vim/autoload/test/mylanguage/myrunner.vim, and define the following methods:

" Returns true if the given file belongs to your test runner
function! test#mylanguage#myrunner#test_file(file)

" Returns test runner's arguments which will run the current file and/or line
function! test#mylanguage#myrunner#build_position(type, position)

" Returns processed args (if you need to do any processing)
function! test#mylanguage#myrunner#build_args(args)

" Returns the executable of your test runner
function! test#mylanguage#myrunner#executable()

See autoload/test for examples.

Choosing which runners to load

All runners are loaded by default. To select which runners to load, set this option:

let test#enabled_runners = ["mylanguage#myrunner", "ruby#rspec"]

All other runners will not be loaded.

Note that for your own custom runners, you still need to set test#custom_runners.

Running tests

Tests are run using a Ruby test runner, so you'll have to have Ruby installed. Then run

$ gem install vim-flavor

Now you can run tests with

$ vim-flavor test spec/

Or if you're inside of Vim, you can simply run :VSpec provided by test.vim.

Credits

This plugin was strongly influenced by Gary Bernhardt's Destroy All Software. I also want to thank rspec.vim, from which I borrowed GUI support for OS X, and Windows support. And also thanks to vroom.vim.

License

Copyright © Janko Marohnić. Distributed under the same terms as Vim itself. See :help license.

vim-test's People

Contributors

aaalsaleh avatar alexgenco avatar benjohnson avatar blakewilliams avatar blueyed avatar camilledejoye avatar codeinabox avatar dmitrivereshchagin avatar dradtke avatar fatboyxpc avatar gfontenot avatar giuseppemp avatar gmartsenkov avatar janko avatar jgeiger avatar jonleighton avatar markwoodhall avatar muchzill4 avatar nixon avatar p0deje avatar phongnh avatar rumblesan avatar simonrw avatar tacsiazuma avatar trisys3 avatar webdavis avatar willfish avatar woahdae avatar yannick-cw avatar yongjoon-km avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-test's Issues

Is there a way to add some indication that test is running

This is related to NeoVim apparently, didn't had this issue in Vim because everything is flickering there so you can tell that there is some activity. In NeoVim the screen is rock solid and I am always like – did it ran tests at all?

Is is possible to add some indication that test is running?

PHPUnit and Behat configuration in subdirectories

I've tested the PHPUnit and Behat runners and it works great except for when the configuration is in a subdirectory. How can I code #build_args to look for a phpunit.xml or behat.yml recursively?

error when running Go tests

Not sure quite what's going on - this is a smaller example than my actual test, which doesn't compile, but is sufficient to reproduce the issue. in this test file:

func TestSwap(t *testing.T) {
    a := &Member{
        Track: []tracks.Element{
            {Segment: tracks.TS_MAP[tracks.ELEM_FLAT]},
            {Segment: tracks.TS_MAP[tracks.ELEM_25_DEG_UP]},
        },
    }
    if a.Track[0] != "" || a.Track[1] != "" {
        t.Errorf("expected d to be %v, was %v", dexpected, d.Track)
    }
}

If I call :TestNearest from the a := line, the test runs fine. If I call it from the if statement, I get the following error:

Error detected while processing function WriteAndRunTest..test#run..test#base#build_position..test#go#gotest#build_position..<SNR>94_nearest_test..test#base#nearest_test:
line   18:
E684: list index out of range: 0
E116: Invalid arguments for function add 

Not sure what's going on, I haven't dug into the guts of the plugin. Let me know if you need more data about my system. I'm running vim-test commit 5ca90c0.

Add teaspoon javascript runner

Tried to add a custom test runner for teaspoon and I'm getting the error: Not a test file
Can you show me what I'm doing wrong?

function! test#javascript#teaspoon#test_file(file) abort
 return a:file =~# '_spec\.(js|coffee|js.coffee)$'
endfunction

function! test#javascript#teaspoon#build_position(type, position) abort
  if a:type == 'nearest'
    return [a:position['file'].':'.a:position['line']]
  elseif a:type == 'file'
    return [a:position['file']]
  else
    return []
  endif
endfunction

function! test#javascript#teaspoon#build_args(args) abort
  return a:args
endfunction

function! test#javascript#teaspoon#executable() abort
  if filereadable('./bin/teaspoon')
    return './bin/teaspoon'
  elseif filereadable('Gemfile')
    return 'bundle exec teaspoon'
  else
    return 'teaspoon'
  endif
endfunction

Clear escape codes in vim-test output

When I run mocha (mochajs.org) tests with vim-test in MacVim, I get ^[[2K^[[0G appearing at the start of the line. It would be nice if those characters were filtered from the output.

Here's an example patch for this issue in vim-dispatch: tpope/vim-dispatch#86

Here is a screenshot of the issue.

TestNearest won't work with @test annotation

TestNearest wont work with test annotation:

Vim test won't recognize that functions annotated with "@test" are also test. Therefore when TestNearest is run it will behave like TestFile.

/**
 * @test
 */
public function foo()
{
    $this->assertTrue(false); # cursor here
}

The below code works

public function testFoo()
{
    $this->assertTrue(false);  # cursor here
}

If you accept I can try to write a PR. Any tips on how to run the tests?

Reversing command-line argument order?

Hi, I'm trying to pass vim-test's arguments to a Go program... which can only parse positional arguments after all keyword arguments have been passed. Eg this is fine...

myprogram.go --grep foo test/lib/client.test.js

However, Go's flag package ignores the --grep arguments here...

myprogram.go test/lib/client.test.js --grep foo

I tried editing test#javascript#mocha#build_position to change the order, like this:

function! test#javascript#mocha#build_position(type, position) abort
  if a:type == 'nearest'
    let name = s:nearest_test(a:position)
    if !empty(name) | let name = '--grep '.shellescape(name, 1) | endif
    return [name, a:position['file']] " Reversed order here.
  elseif a:type == 'file'
    return [a:position['file']]
  else
    return []
  endif
endfunction

However I get the following error: Invalid expression: s:nearest_test(a:position).

Any ideas about how I can get a Go-compliant argument order? FWIW Mocha doesn't care which order the arguments go in...

Sometimes virtualenv is lost when using dispatch

It happens randomly: sometime when running a test (using dispatch) the new tmux pane will "forget" that it is in a virtualenv, and the test cannot run. Once I get in this state, the only to get things back to normal is to restart vi.

Defining your own custom strategies

From @rschmukler:

@janko-m how would someone create a custom strategy for vim-test? Specifically, when using something like Vundle which uses version control to manage plugins (so you don't want to edit the strategies.vim file)? How do we create a custom strategy given that it appears to be using test#strategy# namespacing?

Feature Request: Failure Navigation

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.

Clojure

Hello,

What would you need to support clojure? How can I help you?
Usually, there isn't a command to run. A repl must be running and at this moment we have a vim plugin that sends code to the remote repl and presents the result (vim-fireplace). This works great, but that run last test feature would be awesome. :)

Support for shoulda-context

Great/superclean wrapper.

Any chance of adding support for the quite popular shoulda-context context framework (TestNearest, rest works), which is quite popular amongst Rails devs?

Cannot find module 'coffee-script/register'

I got the following error while attempting to use vim-test on the following file:

https://github.com/wayneashleyberry/phplint/blob/master/test/test.js

:!node_modules/.bin/mocha --compilers coffee:coffee-script/register test/test.js
module.js:338
    throw err;
          ^
Error: Cannot find module 'coffee-script/register'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /Users/Wayne/source/phplint/node_modules/mocha/bin/_mocha:300:3
    at Array.forEach (native)
    at Object.<anonymous> (/Users/Wayne/source/phplint/node_modules/mocha/bin/_mocha:294:19)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

shell returned 1
Press ENTER or type command to continue

Option for disable runner commands

vim-test is a real helpful plugin for testing, only one thing annoying (at least for me), it added lots of runner commands.

Since the runners commands names differently, they pollute my commands and could possibly lead conflict. As I can config :TestNearest :TestFile to works with different kinds of files, and I rarely have specific option for the test command, they're useless for me.

My suggestion is add an option to disable all of the runner commands.

Minitest::Spec detected as RSpec

Hi,

I'm working on a ruby project where files are named _spec.rb but they are not RSpec files, they are Minitest::Spec files.

To have my test working, I tried to override tests#runners in order to to define Minitest as the only Ruby runner available. Unfortunately it was not working because vim-test override what I set with its own default values (https://github.com/janko-m/vim-test/blob/c70614e1b7c8d8d7a8008ce3c93e202b2ff497f1/plugin/test.vim#L14..L26).

I'm wondering why test#runners is overridden with default values? Shouldn't it be the inverse: default overridden by specific?

Maybe there is a better way to achieve what I try to do?

Thank you for your help

TestNearest w/ MiniTest doesn't work when there is a question mark.

When there is a ? in a describe block TestNearest doesn't run properly because the regular expression isn't properly escaped.

Here's an example:

describe Foo do
  describe "#is_something?" do
    it "does something"do
      true.must_equal true
    end
  end
end

Output:

:!./bin/rake test TEST="test/models/foo_test.rb" TESTOPTS="--name='/Foo::#is_something?#test_\d+_does something/'"
Run options: "--name=/Foo::#is_something?#test_\\d+_does something/" --seed 1797

# Running:

Finished in 0.015936s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips 

I can easily reproduce this in MiniTest, I haven't tried rspec.

Minitest - missing TEST and TESTOPTS after Neoterm update

I'm having trouble running Minitest tests with neoterm strategy after neoterm update.
The output looks like this:

$ ./bin/rake test TEST=
rake aborted!
LoadError: cannot load such file -- /Users/aleksandar/Projects/some-project
-e:1:in `<main>'
Tasks: TOP => test:single
(See full trace by running task with --trace)

As you can see TEST does not have any value and TESTOPTS is missing. Result is the same whether I'm running single test, single file, last or all tests.

I'm using vim-plug, so I managed to trace down the issue to 8551ed5. This and all later commits cause the issue above to appear.

Rspec tests are running fine.

I'm using Neovim and settings concerning Neoterm and vim-test in my rc are:

let g:neoterm_position = 'horizontal'
let g:neoterm_automap_keys = ',tt'
let g:neoterm_size = 30

let test#strategy = "neoterm"

Make use of Spring

I'm trying out this plugin in combination with Dispatch, but it looks like the tests are not making use of Spring. Do I need to configure something for this?

Fish Shell support

Hi

There is an issue with fish shell as fish doesn't currently support && and requires and
so clear && echo 'abc' && test should become clear and echo 'abc' and test.

I am using Vimux

How to use this? Please update README

On my command line I run mocha tests. My tests are in the folder 'tests'

I can't get this plugin to work.

:Mocha tests does this:

:!clear && echo -e 'node_modules/.bin/mocha tests'\\n && node_modules/.bin/mocha tests
shell returned 1

(?)

If I run :TestFile or :TestFile . in my test file, I just get "unable to find test file"

README and help files doesn't seem to explain how to do this.

Default Python errorformat does not work with Dispatch handler

Hi! Thank you for an excellent idea to unify application testing inside Vim!

I use vim-test with tpope/vim-dispatch handler and run tests for a Python app.
I set default errorformat string that Vim help suggests for Python tracebacks:

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

Unfortunately this format doesn't match the output coming from Dispatch.
At the moment traceback is parsed and put to the quickfix list as a single error. I want to have a list of errors - separate error for each traceback item.

I can see || prefix (two pipes and a space) in each line of quickfix item (at least - in my setup). It could be a reason of failed traceback parsing.

Do you also have this prefix? Thank you in advance!

Add Always Use Absolute Path Option?

I've run into an issue with relative paths. We have a Rails project with internal engines and internal gems. To run the specs in the engines and gems you have to cd into the engines directory in the terminal.

That causes a problem the first time you run a spec because the spec doesn't run from the right directory, but it's not a big deal because you can cd in the terminal and rerun and be good for the rest of the day.

There's a bigger problem however in that after you've done that, running the specs from vim-test uses a path relative to the project root. Do you think it's worthwhile adding a config variable to vim-test that will force it to send an absolute path to the terminal for every spec run?

Capturing failing tests?

One thing I was thinking that would be very handful if it was able to capture the output of failing lists and easily let you open those files with failing tests in the buffer or perhaps as a CtrlP plugin like ctrlp-modified

Bug: Django runner incorrectly being selected, causing error

I am using the latest master branch. When running any of the test commands in one my projects, I get the following error:

|| /var/folders/kd/9_jv37r94035mc9b94b3f_6c0000gn/T/vBLw9a9/37:56: permission denied: /Users/sloria/projects/flask-projects/manage.py

Django is not in my virtualenv and there is no manage.py file, so I'm not sure why the django runner is selected. Even if I set my test runner with:

let test#python#runner = 'pytest'

The error still happens.

TestVisit toggle back to where you come from

Right now TestVisit is a pretty awesome feature to get from your code to the last test, but what happens if I want to get back to my code again (Ctrl ^ but this is a PITA), is it possible to easily add a toggle feature?

models.py :TestVist => test_models.py
test_models.py :TestVisit => models.py?

iTerm strategy not working

Hi,

I tried to look into the problem but it makes no sense to me... I have iTerm2 2.9.20150923
vim-test tries to execute the following:

:!/Users/tbastos/.dotfiles/vim/bundle/vim-test/bin/osx_iterm 'clear; echo -e '\''busted spec/config_spec.lua'\''; busted spec/config_spec.lua'
/Users/tbastos/.dotfiles/vim/bundle/vim-test/bin/osx_iterm:160:168: script error: Expected end of line but found identifier. (-2741)

Does the last error message make any sense? osx_iterm doesn't even have 160 lines...

The terminal strategy at least opens the Terminal app, but iterm just fails silently.
Meanwhile I'm using dispatch as it works properly.

Thanks for the plugin!

Add option to prevent screen clearing before test run

I run vim with t_ti and t_te blank so my scrollback buffer is not overwritten. Currently vim-test clears the screen before a test run going against the behaviour I have set and like.

Is there a configuration option perhaps e.g. let g:test#clearscreen = 0 that can be added?

Name of class incorrect when doing a TestNearest in python, contains inheritance info

I am trying to run TestNearest on a python nosetest. Here is the command which is being transferred to the neighbor tmux pane:

nosetests --doctest-tests test/scanner_manager/test_ballot_processor.py:TestBallotProcessor\(unittest\.TestCase\).test_unmatch_db_ballot_2

As you can see, it is considering the class declaration as a subclass of unittest.TestCase to be part of the name of the class, which is incorrect.
TestBallotProcessor(unittest.TestCase) --> TestBallotProcessor

dispatch strategy behaves different than Dispatch itself

When using Dispatch the opened split/window closes once the given tests ran without errors. Dispatch also opens a quickfix split if the test suite threw any errors. The dispatch strategy does neither of those things.

Is this intended and if yes how can I imitate that behavior in vim-test?

Thanks.

Not a test file

I've been trying to get vim-test v1.2.0 working with python and nosetests under linux (Slackware 14.1), but all I get is "Not a test file" when running any of the :Test* commands, regardless of the current buffer.

Running :Nose directly works fine.

Minitest without rake

Please make possibility use minitest without rake, bundle exec rake and etc..
You can run test just by running ruby file.

Pre-requisite on iTerm2 *beta*

Thanks for your work on vim-test; it's a very helpful tool. I think it would be useful to clarify in the README.md that (currently) the iterm strategy depends on a beta level of iTerm2. I was using iTerm 2.1.3; this doesn't work as it fails on the set _window to (current window) line in bin/osx_iterm. Upgrading to iTerm 2.9.20151111 fixed it; it looks like the AppleScript hooks have changed: https://iterm2.com/applescript.html.

Setting RAILS_ENV=test

I've tried setting the environment variable through vim-test configuration but it doesn't get appended in execution as a command.

When mapping with :Minitest [args] I get the following command output which results in an error.

bundle exec rake test TEST="test/**/*_test.rb" TESTOPTS="RAILS_ENV=test"

Also trying either of these two options don't work either.

let g:test#ruby#minitest#options = 'RAILS_ENV=test'
let g:test#ruby#minitest#options = {'RAILS_ENV': '=test'}

Javascript / mocha: Not a test file

My tests files are not recognized when running any of the commands (:TestNearest, :TestFile, etc.). They all report 'Not a test file'. My test files are in the 'test' directory. The :Mocha command itself does work.

Document how to run the testcases

It would be nice to be able to run the testcases prior to submitting pull requests, but I don't see any documentation on how to do that. I'm guessing it involves rspec, but not being a ruby guy, I'm not sure what to do.

Allow configuring the test file regex

Users should be able to change the default regexes that test.vim uses for detecting test files. E.g. in Minitest people may still want their test file to end with _spec.rb. This would also help people using autochdir (#40).

Running tests remotely eg Vagrant VM or SSH

I am trying to work the best way to run tests remotely, particularly in the case of running them inside in a Vagrant VM. Is there an existing plug-in that this plug-in could leverage off?

Slow with Clojure

Running Clojure tests is quite slow. Much slower than running py.test tests, which run immediately.
It can easily take several seconds to start running a test. I am using vim fireplace.

To replicate:
lein new compojure slowtest
and run the sample test there.

Use custom compiler/makeprg in dispatch strategy

Hello,
I am really liking vim-test, nice job ! However, I have my own compiler for nosetest (which I prefer to the default pyunit one). When I do the following:

:compiler mynosecompiler
:set makeprg=nosetests
:make

I get a nice output, which I can use to go from error to error with :cnext
But if I do

:let test#strategy = 'dispatch'
:TestFile

I see it is not using my compiler anymore (nor is it using my makeprg in fact).
I am not sure how this problem should be addressed, but it would be nice though.

Also, in the same vain, after populating the results in the quickfix, would it be possible to have a hook to run custom vim commands ? I have a nice piece of vimscript which folds the output of nosetests (one fold by test) and makes a nice foldtext, I would love to be able to hook that in.

NeoVim terminal closes a window

Hi,
I'm currently using NeoVim in conjunction with pytest. When I set the test strategy to be "neovim", the terminal opens just fine. However, it takes over the active split and, upon test completion, the terminal and the split get closed. Is there a way to direct the terminal to open in a new split?

Thanks!

Quickfix broken with ruby tests (minitest)

Love the idea behind this!

When I run ruby minitests over Dispatch via vim-test, I get no highlighting nor autojump to the first error. This is frustrating, as it means I have to scroll manually every time to the first error. However, when I run the test manually :Dispatch ruby -Itest % it works fine. Using neovim.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.