mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -05:00
Refactor tests to be isolated.
This commit is contained in:
@@ -9,13 +9,18 @@ $ ./test.sh
|
|||||||
|
|
||||||
### Add a new test
|
### Add a new test
|
||||||
|
|
||||||
1. Add new test function to `test.vim`.
|
- Add a test file named like `testFoo.vim`. It should have this structure:
|
||||||
2. Add a call to the test function in `test.vim`.
|
|
||||||
3. Run the tests.
|
|
||||||
4. Inspect output from the new test function. If good, copy it to `<blah>.ok`.
|
|
||||||
5. Run the tests to ensure new test's output is verified.
|
|
||||||
6. `rm *.out` and commit changes.
|
|
||||||
|
|
||||||
### Potential test pitfalls
|
```viml
|
||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
Currently the tests are order-dependent because the sign id counter isn't reset between tests.
|
" test code here
|
||||||
|
|
||||||
|
quit!
|
||||||
|
```
|
||||||
|
|
||||||
|
- Run the tests.
|
||||||
|
- Inspect output from the new test. If good, copy it to `foo.ok`.
|
||||||
|
- Run the tests to ensure new test's output is verified.
|
||||||
|
- `rm *.out` and commit changes.
|
||||||
|
|||||||
15
test/helper.vim
Normal file
15
test/helper.vim
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
set runtimepath+=../
|
||||||
|
source ../plugin/gitgutter.vim
|
||||||
|
|
||||||
|
function! Setup()
|
||||||
|
call system('git checkout fixture.txt')
|
||||||
|
edit! fixture.txt
|
||||||
|
sign unplace *
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! DumpSigns(filename)
|
||||||
|
execute 'redir! > ' a:filename.'.out'
|
||||||
|
silent execute 'sign place'
|
||||||
|
redir END
|
||||||
|
endfunction
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
--- Signs ---
|
--- Signs ---
|
||||||
Signs for fixture.txt:
|
Signs for fixture.txt:
|
||||||
line=1 id=3001 name=GitGutterLineModified
|
line=1 id=3000 name=GitGutterLineModified
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
--- Signs ---
|
--- Signs ---
|
||||||
Signs for fixture.txt:
|
Signs for fixture.txt:
|
||||||
line=6 id=3005 name=GitGutterLineAdded
|
line=6 id=3001 name=GitGutterLineAdded
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
--- Signs ---
|
--- Signs ---
|
||||||
Signs for fixture.txt:
|
Signs for fixture.txt:
|
||||||
line=1 id=3003 name=GitGutterLineRemovedFirstLine
|
line=1 id=3000 name=GitGutterLineRemovedFirstLine
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
--- Signs ---
|
--- Signs ---
|
||||||
Signs for fixture.txt:
|
Signs for fixture.txt:
|
||||||
line=4 id=3002 name=GitGutterLineRemoved
|
line=4 id=3000 name=GitGutterLineRemoved
|
||||||
|
|||||||
18
test/test.sh
18
test/test.sh
@@ -1,13 +1,19 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# TODO: exit with non-zero status code when tests fail.
|
||||||
|
# TODO: quit vim after each testcase inside loop below (instead of in testcase).
|
||||||
|
|
||||||
rm -f *.out
|
rm -f *.out
|
||||||
|
|
||||||
# Run the tests.
|
for testcase in test*.vim; do
|
||||||
vim -N -u NONE -S test.vim
|
vim -N -u NONE -S $testcase # testFoo.vim
|
||||||
|
testname=${testcase%.*} # testFoo
|
||||||
# Verify the outputs.
|
name=${testname:4} # Foo
|
||||||
for expected in *.ok; do
|
name="$(tr '[:upper:]' '[:lower:]' <<< ${name:0:1})${name:1}" # foo
|
||||||
name=${expected%.*}
|
expected=$name.ok
|
||||||
actual=$name.out
|
actual=$name.out
|
||||||
diff $expected $actual && echo "$name ok" || echo "$name failed"
|
diff $expected $actual && echo "$name ok" || echo "$name failed"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
git checkout fixture.txt
|
||||||
|
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
set runtimepath+=../
|
|
||||||
source ../plugin/gitgutter.vim
|
|
||||||
|
|
||||||
|
|
||||||
function! s:setup()
|
|
||||||
call system('git checkout fixture.txt')
|
|
||||||
edit! fixture.txt
|
|
||||||
sign unplace *
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:dumpSigns(filename)
|
|
||||||
execute 'redir! > ' a:filename.'.out'
|
|
||||||
silent execute 'sign place'
|
|
||||||
redir END
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
"
|
|
||||||
" The tests.
|
|
||||||
"
|
|
||||||
|
|
||||||
function! s:testNoModifications()
|
|
||||||
call s:setup()
|
|
||||||
call s:dumpSigns('noModifications')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:testAddLines()
|
|
||||||
call s:setup()
|
|
||||||
normal ggo*
|
|
||||||
write
|
|
||||||
call s:dumpSigns('addLines')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:testModifyLines()
|
|
||||||
call s:setup()
|
|
||||||
normal ggi*
|
|
||||||
write
|
|
||||||
call s:dumpSigns('modifyLines')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:testRemoveLines()
|
|
||||||
call s:setup()
|
|
||||||
execute '5d'
|
|
||||||
write
|
|
||||||
call s:dumpSigns('removeLines')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:testRemoveFirstLines()
|
|
||||||
call s:setup()
|
|
||||||
execute '1d'
|
|
||||||
write
|
|
||||||
call s:dumpSigns('removeFirstLines')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:testOrphanedSigns()
|
|
||||||
call s:setup()
|
|
||||||
execute "normal 5GoX\<CR>Y"
|
|
||||||
write
|
|
||||||
execute '6d'
|
|
||||||
write
|
|
||||||
call s:dumpSigns('orphanedSigns')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
"
|
|
||||||
" Execute the tests.
|
|
||||||
"
|
|
||||||
|
|
||||||
call s:testNoModifications()
|
|
||||||
call s:testAddLines()
|
|
||||||
call s:testModifyLines()
|
|
||||||
call s:testRemoveLines()
|
|
||||||
call s:testRemoveFirstLines()
|
|
||||||
call s:testOrphanedSigns()
|
|
||||||
|
|
||||||
|
|
||||||
"
|
|
||||||
" Cleanup.
|
|
||||||
"
|
|
||||||
|
|
||||||
call system('git checkout fixture.txt')
|
|
||||||
quit!
|
|
||||||
|
|
||||||
8
test/testAddLines.vim
Normal file
8
test/testAddLines.vim
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
normal ggo*
|
||||||
|
write
|
||||||
|
call DumpSigns('addLines')
|
||||||
|
|
||||||
|
quit!
|
||||||
8
test/testModifyLines.vim
Normal file
8
test/testModifyLines.vim
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
normal ggi*
|
||||||
|
write
|
||||||
|
call DumpSigns('modifyLines')
|
||||||
|
|
||||||
|
quit!
|
||||||
6
test/testNoModifications.vim
Normal file
6
test/testNoModifications.vim
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
call DumpSigns('noModifications')
|
||||||
|
|
||||||
|
quit!
|
||||||
10
test/testOrphanedSigns.vim
Normal file
10
test/testOrphanedSigns.vim
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
execute "normal 5GoX\<CR>Y"
|
||||||
|
write
|
||||||
|
execute '6d'
|
||||||
|
write
|
||||||
|
call DumpSigns('orphanedSigns')
|
||||||
|
|
||||||
|
quit!
|
||||||
8
test/testRemoveFirstLines.vim
Normal file
8
test/testRemoveFirstLines.vim
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
execute '1d'
|
||||||
|
write
|
||||||
|
call DumpSigns('removeFirstLines')
|
||||||
|
|
||||||
|
quit!
|
||||||
8
test/testRemoveLines.vim
Normal file
8
test/testRemoveLines.vim
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
execute '5d'
|
||||||
|
write
|
||||||
|
call DumpSigns('removeLines')
|
||||||
|
|
||||||
|
quit!
|
||||||
Reference in New Issue
Block a user