2017-11-24 13:54:40 +00:00
|
|
|
" Make sure some options are set to sane defaults and output all messages in
|
|
|
|
" English.
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" vint: -ProhibitSetNoCompatible
|
|
|
|
set nocompatible nomore shellslash encoding=utf-8 shortmess+=WIF
|
|
|
|
lang mess C
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Initialize variables.
|
|
|
|
let s:total_started = reltime()
|
2017-02-11 13:01:38 +00:00
|
|
|
let s:fail = 0
|
|
|
|
let s:done = 0
|
|
|
|
let s:logs = []
|
2017-11-24 13:54:40 +00:00
|
|
|
let s:gopath = $GOPATH
|
|
|
|
|
|
|
|
" Source the passed test file.
|
|
|
|
source %
|
|
|
|
|
|
|
|
" cd into the folder of the test file.
|
|
|
|
let s:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
|
|
|
let s:testfile = expand('%:t')
|
|
|
|
execute s:cd . expand('%:p:h')
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Export root path to vim-go dir.
|
|
|
|
let g:vim_go_root = fnamemodify(getcwd(), ':p')
|
|
|
|
|
|
|
|
" Get a list of all Test_ functions for the given file.
|
2017-02-11 13:01:38 +00:00
|
|
|
redir @q
|
2017-11-24 13:54:40 +00:00
|
|
|
silent function /^Test_
|
2017-02-11 13:01:38 +00:00
|
|
|
redir END
|
|
|
|
let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
|
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Iterate over all tests and execute them.
|
2017-02-11 13:01:38 +00:00
|
|
|
for s:test in sort(s:tests)
|
2017-11-24 13:54:40 +00:00
|
|
|
" Since we extract the tests from a regexp the "abort" keyword is also in the
|
|
|
|
" list, which is not a test name :-)
|
|
|
|
if s:test == 'abort'
|
|
|
|
continue
|
|
|
|
endif
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
let s:started = reltime()
|
|
|
|
call add(s:logs, printf("=== RUN %s", s:test[:-3]))
|
2017-02-11 13:01:38 +00:00
|
|
|
exe 'call ' . s:test
|
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Restore GOPATH after each test.
|
|
|
|
let $GOPATH = s:gopath
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
let s:elapsed_time = substitute(reltimestr(reltime(s:started)), '^\s*\(.\{-}\)\s*$', '\1', '')
|
2017-02-11 13:01:38 +00:00
|
|
|
let s:done += 1
|
|
|
|
|
|
|
|
if len(v:errors) > 0
|
|
|
|
let s:fail += 1
|
2017-11-24 13:54:40 +00:00
|
|
|
call add(s:logs, printf("--- FAIL %s (%ss)", s:test[:-3], s:elapsed_time))
|
2017-02-11 13:01:38 +00:00
|
|
|
call extend(s:logs, map(v:errors, '" ". v:val'))
|
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Reset so we can capture failures of the next test.
|
2017-02-11 13:01:38 +00:00
|
|
|
let v:errors = []
|
|
|
|
else
|
2017-11-24 13:54:40 +00:00
|
|
|
call add(s:logs, printf("--- PASS %s (%ss)", s:test[:-3], s:elapsed_time))
|
2017-02-11 13:01:38 +00:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Create an empty fail to indicate that at least one test failed.
|
2017-02-11 13:01:38 +00:00
|
|
|
if s:fail > 0
|
2017-11-24 13:54:40 +00:00
|
|
|
split /tmp/vim-go-test/FAILED
|
|
|
|
silent write
|
2017-02-11 13:01:38 +00:00
|
|
|
endif
|
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
let s:total_elapsed_time = substitute(reltimestr(reltime(s:total_started)), '^\s*\(.\{-}\)\s*$', '\1', '')
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Add all messages (usually errors).
|
|
|
|
redir => s:mess
|
|
|
|
silent messages
|
2017-02-11 13:01:38 +00:00
|
|
|
redir END
|
2017-11-24 13:54:40 +00:00
|
|
|
let s:logs = s:logs + filter(split(s:mess, "\n"), 'v:val !~ "^Messages maintainer"')
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Also store all internal messages from s:logs as well.
|
|
|
|
silent! split /tmp/vim-go-test/test.tmp
|
2017-02-11 13:01:38 +00:00
|
|
|
call append(line('$'), s:logs)
|
2017-11-24 13:54:40 +00:00
|
|
|
call append(line('$'), printf("%s%s %s / %s tests",
|
|
|
|
\ (s:fail > 0 ? 'FAIL ' : 'ok '),
|
|
|
|
\ s:testfile, s:total_elapsed_time, s:done))
|
|
|
|
silent! write
|
2017-02-11 13:01:38 +00:00
|
|
|
|
2017-11-24 13:54:40 +00:00
|
|
|
" Our work here is done.
|
2017-02-11 13:01:38 +00:00
|
|
|
qall!
|
2017-11-24 13:54:40 +00:00
|
|
|
|
|
|
|
" vim:ts=2:sts=2:sw=2:et
|