[erlang-questions] How do you do TDD in vim?

Fredrik Andersson sedrik@REDACTED
Thu Feb 17 10:37:21 CET 2011

I never intended to make my repo editor dependent, why would anyone ever do

My goal is to improve my workflow and integrating testing into vim and not
vim into the repository.

Anyway I wrote this small vimscript, it's probably full of bugs and other
horrible beings of unatural size but it works for me as of now. The plan is
to seperate it into a single vim script file and release it as a seperate
repository on github.

Feel free to comment/improve/use or contribute to this.


" ErlTDD.vim - Fredrik Andersson
" Small script to enable TDD from inside of vim
" Currently only works with environments witch will build all test using make
" test (for example raven).
" Invoke with :TDD

"Erlang TDD function
" TODO: Make more general, fit to other languages and test suits
" TODO: Make a separate scripts file for the tests
" TODO: run dialyzer on source code
" TODO: do Test for all open files that are src or test files
command! -complete=file TDD call s:Test()

"TODO: run in background and put output in quickfix window

"autocmd BufWritePost *.erl call s:Test()

function! s:Test()
    let testpath = "-pa test -pa test_hrl"
    let ebinpath = "-pa ebin"
    let libpath = "-pa ../meck/ebin"

    let theFile = expand('%:t:r')
    if matchstr(theFile, "test_") == "test_"
        let testfile = theFile

        let testfile = "test_" . theFile

    let paths = testpath . " " . ebinpath . " " . libpath
    let eunit = "eunit:test(" . testfile . ", [verbose])"
    let erlcmd = "-eval 'error_logger:tty(false), " . eunit . ", halt()'"
    let cmd = "!make; make test; erl " . paths .  " " . erlcmd
    execute cmd
    "cexpr system(cmd)
    "echo cmd


On Fri, Jan 21, 2011 at 3:31 PM, Jesper Louis Andersen <
jesper.louis.andersen@REDACTED> wrote:

> On Fri, Jan 21, 2011 at 14:58, Fredrik Andersson <sedrik@REDACTED>
> wrote:
> >
> > Nice it was things like this I was looking for. If anyone has more stuff
> > like this that is worth trying I am interesting, would love something
> > eunit/quickcheck/proper/dialyzer specific stuff aswell
> >
> The rebar tool on the command line is a nice helper for running tests
> and so on. It also has the distinct advantage that it is ${EDITOR}
> agnostic. So should you some day decide that acme[1] is a better
> editor, you can easily change to it. And your project is easier for
> others to pick up, whether or not they use the same editor as you.
> [1] http://en.wikipedia.org/wiki/Acme_(text_editor)
> --
> J.
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED

More information about the erlang-questions mailing list