Vim: run all tests in your buffers

Ovid on 2008-09-17T13:35:18

I often have a ton of tests open in one buffer. They're usually related to something I'm refactoring:

vim $(ack -l --perl 'api/v1/episode' t/)

So it's handy to be able to execute all tests in my current vim buffers. Now I can just type ,tb and do that.

map tb :call RunTestsInBuffers()
function! RunTestsInBuffers()
    let i = 1
    let tests = ''
    while (i <= bufnr("$"))
        let filename = bufname(i)
        if match(filename, '\.t$') > -1
            let tests = tests . ' "' . filename . '"'
        endif
        let i = i+1
    endwhile
    if !strlen(tests)
        echo "No tests found in buffers"
    else
        execute ':!prove ' . tests
    endif
endfunction


Collecting?

rjray on 2008-09-17T21:05:32

Are you gathering all of these vim-scripts/tips in one place? Because if not, you really should. I'm more and more tempted to start using vim over emacs, with each new one of these you post...

Re:Collecting?

Ovid on 2008-09-17T21:50:01

I'm not collecting them directly, but I use a careful Google search to find them.

Re:Collecting?

Aristotle on 2008-09-18T14:10:54

Perfect opportunity to take GitHub for a spin. ;-)

writing buffers with changes

mr_bean on 2008-09-20T13:44:13

Mmh, this gives me an idea for writing all changed buffers, something for which I don't think there is an in-built vim command.

Re:writing buffers with changes

Aristotle on 2008-09-20T17:34:54

Eh? How about :wa?