Skip to content

Commit 808fe84

Browse files
committed
Fix handling of multiple test files
Test files were sourced sequentially, but their test cases persisted causing them to be run more than once. Instead, run each test file in a separate Vim session.
1 parent 090bd90 commit 808fe84

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ endif
99
all: check
1010

1111
check:
12-
$(VIM) --clean $(args) -u runtest.vim
12+
$(foreach test,$(wildcard test/*.vim),$(VIM) --clean $(args) -u runtest.vim "$(test)")
1313

1414
.PHONY: all check

runtest.vim

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1+
let s:testfile = expand('%')
12
let s:has_errors = 0
23

34
try
45
execute 'cd' fnamemodify(resolve(expand('<sfile>:p')), ':h')
5-
execute 'source' 'plugin/strip_trailing_whitespace.vim'
6+
source plugin/strip_trailing_whitespace.vim
67

7-
let s:testfiles = glob('test/*.vim', 1, 1)
8-
for s:testfile in s:testfiles
9-
execute 'source' s:testfile
10-
11-
let s:tests = map(split(execute('function /^Test_'), "\n"), {_, v -> matchstr(v, 'function \zs\k\+\ze()')})
12-
for s:test_function in s:tests
13-
let v:errors = []
14-
try
15-
echo 'Test' s:test_function
16-
execute 'call' s:test_function '()'
17-
catch
18-
call add(v:errors, "Uncaught exception in test: " .. v:exception .. " at " .. v:throwpoint)
19-
finally
20-
if !empty(v:errors)
21-
echo s:testfile .. ':1:Error'
22-
for s:error in v:errors
23-
echo s:error
24-
endfor
25-
let s:has_errors = 1
26-
endif
27-
endtry
28-
endfor
8+
source %
9+
let s:tests = map(split(execute('function /^Test_'), "\n"), {_, v -> matchstr(v, 'function \zs\k\+\ze()')})
10+
for s:test_function in s:tests
11+
let v:errors = []
12+
echo 'Test' s:test_function
13+
try
14+
execute 'call' s:test_function '()'
15+
catch
16+
call add(v:errors, "Uncaught exception in test: " .. v:exception .. " at " .. v:throwpoint)
17+
finally
18+
if !empty(v:errors)
19+
echo s:testfile .. ':1:Error'
20+
for s:error in v:errors
21+
echo s:error
22+
endfor
23+
let s:has_errors = 1
24+
endif
25+
endtry
2926
endfor
3027
catch
3128
echo v:exception

0 commit comments

Comments
 (0)