Ⅰ. 插件描述
Run and navigate from/to unittests in vimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'torbiak/rut-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'torbiak/rut-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'torbiak/rut-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/torbiak/rut.vim
Ⅳ. 文档说明
rut.txt run and navigate to/from unit tests
==============================================================================
Contents
Introduction |rut-intro|
Installation |rut-installation|
Usage |rut-usage|
Options |rut-options|
Command Mappings |rut-mappings|
Commands |rut-commands|
Acknowledgements |rut-acknowledgements|
License |rut-license|
==============================================================================
Introduction rut-intro
Run and navigate to/from unittests.
You need to tell |rut| how to work with your project using |g:rut_projects|,
and then tests can be run using the |RutFile| and |RutAll| commands. Vim's
|:make| and |errorformat| facilities are used to run the tests and populate
the |quickfix| list. This lets you quickly navigate to failures and view the
failure messages in the |quickfix-window|.
The |RutOther| and |RutOtherSplit| commands quickly navigate between a source
file and its tests.
The root directory of the project is determined by finding a version control
meta-directory, like .git/, .hg/, etc.
Neovim's async |job-control| features are used when available unless
|g:rut_async| is set to 0. If a multiline errorformat pattern is used output is
buffered so that errorformat can match as expected; otherwise output is
streamed to the quickfix list.
==============================================================================
Installation rut-installation
Install Pathogen (https://github.com/tpope/vim-pathogen) and clone the repo: >
git clone https://github.com/torbaik/rut.vim.git ~/.vim/bundle/rut.vimAlternatively, use one of the fancier Vim package managers, like Vundle or
vim-plug.
==============================================================================
Usage rut-usage
Define projects for rut:
g:rut_projects (default: []) g:rut_projects
A list of dicts containing the following keys:
pattern: Used to determine which project is currently in use.
pattern must match the absolute path to the repository root.
test_dir: repo-relative path to test directory
source2unit: Funcref to convert a source filepath to the corresponding
test filepath, where the paths are relative to the repo root.
Alternatively, a pair of [pat, sub] args for Vim's substitute()
function can be assigned here.
unit2source: Same as source2unit, in the other direction.
runner: Runner command. Executed from the repo root.
If RutFile is invoked then the runner command is given the filepath for
the tests corresponding to the current window and should only the tests
in that file.
If RutAll is invoked then the runner command is given the test_dir
directory for the project and should run all the project's unit tests.
errorformat: Vim |errorformat| string to find errors in the test runner
output.
For example, for a Python project with source under py_proj/ and tests under
tests/ put something like this in your .vimrc: >
let g:rut_projects = [{
\'pattern': '/py_proj$',
\'test_dir': 'tests',
\'source2unit': ['\v.*/py_proj/(.*)/([^/]*)', '\1/test_\2'],
\'unit2source': ['\v.*/tests/(.*)/test_([^/]*)', 'py_proj/\1/\2'],
\'runner': 'nosetests',
\'errorformat': '%C %.%#,%A File "%f"\, line %l%.%#,%Z%[%^ ]%\@=%m',
\}]<
Or for a Ruby project using RSpec: >
let g:rut_projects = [{
\'pattern': '/rb_proj$',
\'test_dir': 'spec',
\'source2unit': ['\v.*/rb_proj/?(.*)/([^/]*).rb', 'spec/\1/\2_spec.rb'],
\'unit2source': ['\v.*/spec/(.*)/([^/]*)_spec.rb', 'rb_proj/\1/\2.rb'],
\'runner': 'rspec',
\'errorformat': '%A %#Failure/Error:%.%#,%Z %## %f:%l:%m,%C%m,%C%.%#',
\}]<
Note that these examples assume the Python and Ruby import paths are setup
appropriately for your project.
Navigate between source and test files using |:RutOther| and |:RutOtherSplit|
and run unit tests for a file, from either the source or test file, using
|:RutFile|. Run all the tests for a project using |:RutAll|.
==============================================================================
Options rut-options
g:rut_openQuickFix (default: 0) g:rut_openQuickFix
If 1, open the quickfix window when tests fail.
g:rut_async (default: 1) g:rut_async
If 1, use neovim's |job-control| features when available.
g:rut_job_id g:rut_job_id
Use this to kill a neovim job that's gone out-of-control.
And you're right, it's not an option.
==============================================================================
Mappings rut-mappings
If not already mapped, the following mappings are created: >
nnoremap <leader>ur :RutFile<cr>
nnoremap <leader>ua :RutAll<cr>
nnoremap <leader>uo :RutOther<cr>
nnoremap <leader>us :RutOtherSplit<cr>==============================================================================
Commands rut-commands
*:RutFile*:RutFile Run the tests for the current window's source or test
file.
*:RutAll*:RutAll Run the tests for the current window's source or test
file.
*:RutOther*:RutOther Toggle between editing source and tests.
*:RutOtherSplit*:RutOtherSplit Open a split with the corresponding source or tests.
==============================================================================
Acknowledgements rut-acknowledgements
Greetz fly out to buddies on the automation team who gave feedback on earlier
incarnations of this script.
==============================================================================
License rut-license
Copyright (c) 2015 Jordan Torbiak
MIT