Skip to content

Commit ea23cc8

Browse files
committed
Rewrite tests to use tinytest framework
1 parent 250c47b commit ea23cc8

20 files changed

+358
-241
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
doc/tags
2-
test/output
32
vimproc
3+
tinytest
44
verbose.log
5+
stdout.log

install-deps.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
#!/bin/sh
22
set -e
33

4+
if [ -d tinytest ]; then
5+
(cd tinytest; git pull origin master)
6+
else
7+
git clone git://github.com/eagletmt/tinytest.git
8+
fi
9+
410
if [ -d vimproc ]; then
511
cd vimproc
612
git pull origin master
713
else
8-
git clone git://github.com/Shougo/vimproc
14+
git clone git://github.com/Shougo/vimproc.git
915
cd vimproc
1016
fi
11-
1217
make -f make_unix.mak
1318

19+
cabal update
1420
cabal install ghc-mod

test.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22

33
shopt -s nullglob
44

5-
rm -rf test/output
6-
mkdir -p test/output
7-
rm -f verbose.log
8-
95
retval=0
106
for f in test/test_*.vim
117
do
128
testname=${f#test/test_}
139
testname=${testname%.vim}
14-
if vim -e -N -u NONE -S test/before.vim -S "$f" -c quit < /dev/null; then
15-
diff -u test/ok/$testname.ok test/output/$testname.out
16-
retval=$[retval + $?]
10+
echo "Running $testname"
11+
rm -f verbose.log
12+
if vim -e -N -u NONE -S test/before.vim -S "$f" < /dev/null; then
13+
cat stdout.log
1714
else
18-
echo "$testname: vim exited with $?"
1915
retval=$[retval + 1]
16+
cat stdout.log
17+
cat verbose.log
18+
echo
2019
fi
2120
done
2221

23-
[ $retval -eq 0 ] || cat verbose.log
24-
2522
exit $retval

test/before.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ set verbosefile=verbose.log
22

33
" Remove user's runtime path
44
set runtimepath-=~/.vim runtimepath-=~/.vim/after
5-
let &runtimepath = printf('%s,%s,%s,%s', &runtimepath, fnamemodify('vimproc', ':p'), fnamemodify('.', ':p'), fnamemodify('./after', ':p'))
5+
let &runtimepath = join([
6+
\ &runtimepath,
7+
\ fnamemodify('vimproc', ':p'),
8+
\ fnamemodify('tinytest', ':p'),
9+
\ fnamemodify('.', ':p'),
10+
\ fnamemodify('./after', ':p'),
11+
\ ], ',')
612

713
syntax enable
814
filetype plugin indent on
15+
16+
let g:tinytest_default_config = { 'reporter': 'cli' }

test/ok/basedir.ok

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/ok/build_command.ok

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/ok/check.ok

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/ok/command_type.ok

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/ok/detect_module.ok

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/ok/info.ok

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/ok/lint.ok

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/ok/type.ok

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/test_basedir.vim

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
1-
let s:outputs = []
2-
3-
function! s:write()
1+
function! s:basedir()
42
" normalize path
5-
call add(s:outputs, fnamemodify(ghcmod#basedir(), ':.'))
3+
return fnamemodify(ghcmod#basedir(), ':.')
64
endfunction
75

8-
function! s:without_cabal()
9-
edit test/data/without-cabal/Main.hs
10-
call s:write()
11-
edit test/data/without-cabal/Foo/Bar.hs
12-
call s:write()
6+
let s:unit = tinytest#new()
7+
8+
function! s:unit.teardown()
9+
bdelete
1310
endfunction
1411

15-
function! s:with_cabal()
12+
function! s:unit.test_with_cabal()
1613
edit test/data/with-cabal/src/Foo.hs
17-
call s:write()
14+
call self.assert.equal('test/data/with-cabal', s:basedir())
15+
endfunction
16+
17+
function! s:unit.test_with_cabal_subdir()
1818
edit test/data/with-cabal/src/Foo/Bar.hs
19-
call s:write()
19+
call self.assert.equal('test/data/with-cabal', s:basedir())
2020
endfunction
2121

22-
function! s:main()
23-
call s:without_cabal()
24-
call s:with_cabal()
22+
function! s:unit.test_without_cabal()
23+
edit test/data/without-cabal/Main.hs
24+
call self.assert.equal('test/data/without-cabal', s:basedir())
25+
endfunction
26+
27+
function! s:unit.test_without_cabal_subdir()
28+
edit test/data/without-cabal/Foo/Bar.hs
29+
call self.assert.equal('test/data/without-cabal/Foo', s:basedir())
30+
endfunction
2531

32+
function! s:unit.test_with_cabal_opt()
2633
let g:ghcmod_use_basedir = 'test/data'
27-
call s:without_cabal()
28-
call s:with_cabal()
34+
try
35+
edit test/data/with-cabal/src/Foo/Bar.hs
36+
call self.assert.equal(g:ghcmod_use_basedir, s:basedir())
37+
finally
38+
unlet g:ghcmod_use_basedir
39+
endtry
40+
endfunction
2941

30-
call writefile(s:outputs, 'test/output/basedir.out')
42+
function! s:unit.test_without_cabal_opt()
43+
let g:ghcmod_use_basedir = 'test/data'
44+
try
45+
edit test/data/without-cabal/Foo/Bar.hs
46+
call self.assert.equal(g:ghcmod_use_basedir, s:basedir())
47+
finally
48+
unlet g:ghcmod_use_basedir
49+
endtry
3150
endfunction
3251

33-
call s:main()
52+
call s:unit.run()

test/test_build_command.vim

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,55 @@
1-
let s:outputs = []
2-
3-
function! s:write()
4-
call extend(s:outputs, map(ghcmod#build_command(['do']), 'fnamemodify(v:val, ":.")'))
5-
call add(s:outputs, '######')
1+
function! s:build()
2+
return map(ghcmod#build_command(['do']), 'fnamemodify(v:val, ":.")')
63
endfunction
74

8-
function! s:main()
9-
edit test/data/without-cabal/Main.hs
10-
call s:write()
5+
let s:unit = tinytest#new()
6+
7+
function! s:unit.teardown()
8+
bdelete
9+
endfunction
1110

12-
edit test/data/with-cabal/src/Foo.hs
13-
call s:write()
11+
function! s:unit.test_build()
12+
edit test/data/without-cabal/Foo/Bar.hs
13+
call self.assert.equal(['ghc-mod', 'do'], s:build())
14+
endfunction
1415

15-
edit test/data/with-cabal/src/Foo.hs
16+
function! s:unit.test_build_with_dist_dir()
1617
try
1718
call system('cd test/data/with-cabal; cabal configure; cabal build')
18-
call s:write()
19+
edit test/data/with-cabal/src/Foo/Bar.hs
20+
call self.assert.equal(['ghc-mod',
21+
\ '-g', '-i', '-g', 'test/data/with-cabal/dist/build/autogen',
22+
\ '-g', '-I', '-g', 'test/data/with-cabal/dist/build/autogen',
23+
\ '-g', '-optP-include',
24+
\ '-g', '-optP', '-g', 'test/data/with-cabal/dist/build/autogen/cabal_macros.h',
25+
\ '-g', '-i', '-g', 'test/data/with-cabal/dist/build',
26+
\ '-g', '-I', '-g', 'test/data/with-cabal/dist/build',
27+
\ 'do'], s:build())
1928
finally
2029
call system('cd test/data/with-cabal; rm -rf dist')
2130
endtry
31+
endfunction
2232

33+
function! s:unit.test_build_global_opt()
2334
let g:ghcmod_ghc_options = ['-Wall']
24-
edit test/data/without-cabal/Main.hs
25-
call s:write()
35+
try
36+
edit test/data/without-cabal/Main.hs
37+
call self.assert.equal(['ghc-mod', '-g', '-Wall', 'do'], s:build())
38+
finally
39+
unlet g:ghcmod_ghc_options
40+
endtry
41+
endfunction
2642

43+
function! s:unit.test_build_buffer_opt()
2744
" If b:ghcmod_ghc_options is set, g:ghcmod_ghc_options is ignored
28-
edit test/data/without-cabal/Main.hs
45+
edit test/data/without-cabal/Foo/Bar.hs
2946
let g:ghcmod_ghc_options = ['-Wall']
30-
let b:ghcmod_ghc_options = ['-W']
31-
call s:write()
32-
33-
call writefile(s:outputs, 'test/output/build_command.out')
47+
try
48+
let b:ghcmod_ghc_options = ['-W']
49+
call self.assert.equal(['ghc-mod', '-g', '-W', 'do'], s:build())
50+
finally
51+
unlet g:ghcmod_ghc_options
52+
endtry
3453
endfunction
3554

36-
call s:main()
55+
call s:unit.run()

0 commit comments

Comments
 (0)