-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.vim
83 lines (70 loc) · 1.68 KB
/
run_test.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
let g:test_name = expand( "%:p:t" )
let g:test_path = expand( "%:p:h" )
let g:logfile = g:test_path . "/" . g:test_name . ".failed.log"
" Source the file that's open and close it
source %
%bwipe!
" Extract the list of functions matching ^Test_
let s:tests = split( substitute( execute( 'function /^Test_' ),
\ 'function \(\k*()\)',
\ '\1',
\ 'g' ) )
" Save all errors
let s:errors = []
function! s:EarlyExit()
call add( v:errors,
\ "Test "
\ . g:test_name
\ . ":"
\ . g:test_function
\ . " caused Vim to quit!" )
call s:EndTest()
call s:Done()
endfunction
function! s:Start()
" Truncate
call writefile( [], g:logfile, 's' )
endfunction
function! s:EndTest()
if len( v:errors ) > 0
" Append errors to test failure log
call writefile( v:errors, g:logfile, 'as' )
endif
call extend( s:errors, v:errors )
let v:errors = []
endfunction
function! s:Done()
if len( s:errors ) > 0
" Quit with an error code
cquit!
else
quit!
endif
endfunction
call s:Start()
if exists("*SetUp")
call SetUp()
endif
" ... run all of the Test_* functions
for test_function in s:tests
let g:test_function = test_function
au VimLeavePre * call s:EarlyExit()
try
execute 'call ' test_function
catch
call add( v:errors,
\ "Uncaught exception in test "
\ . g:test_name . ":" . test_function
\ . ": "
\ . v:exception
\ . " at "
\ . v:throwpoint )
finally
au! VimLeavePre
endtry
call s:EndTest()
endfor
if exists( "*TearDown" )
call TearDown()
endif
call s:Done()