mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Add basic tests.
This commit is contained in:
21
test/README.markdown
Normal file
21
test/README.markdown
Normal file
@@ -0,0 +1,21 @@
|
||||
## Testing vim-gitgutter
|
||||
|
||||
### Run the tests
|
||||
|
||||
```sh
|
||||
$ cd test
|
||||
$ ./test.sh
|
||||
```
|
||||
|
||||
### Add a new test
|
||||
|
||||
1. Add new test function to `test.vim`.
|
||||
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
|
||||
|
||||
Currently the tests are order-dependent because the sign id counter isn't reset between tests.
|
||||
4
test/addLines.ok
Normal file
4
test/addLines.ok
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
--- Signs ---
|
||||
Signs for fixture.txt:
|
||||
line=2 id=3000 name=GitGutterLineAdded
|
||||
11
test/fixture.txt
Normal file
11
test/fixture.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
||||
g
|
||||
h
|
||||
i
|
||||
j
|
||||
|
||||
4
test/modifyLines.ok
Normal file
4
test/modifyLines.ok
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
--- Signs ---
|
||||
Signs for fixture.txt:
|
||||
line=1 id=3001 name=GitGutterLineModified
|
||||
2
test/noModifications.ok
Normal file
2
test/noModifications.ok
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
--- Signs ---
|
||||
4
test/orphanedSigns.ok
Normal file
4
test/orphanedSigns.ok
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
--- Signs ---
|
||||
Signs for fixture.txt:
|
||||
line=6 id=3005 name=GitGutterLineAdded
|
||||
4
test/removeFirstLines.ok
Normal file
4
test/removeFirstLines.ok
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
--- Signs ---
|
||||
Signs for fixture.txt:
|
||||
line=1 id=3003 name=GitGutterLineRemovedFirstLine
|
||||
4
test/removeLines.ok
Normal file
4
test/removeLines.ok
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
--- Signs ---
|
||||
Signs for fixture.txt:
|
||||
line=4 id=3002 name=GitGutterLineRemoved
|
||||
13
test/test.sh
Executable file
13
test/test.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
rm -f *.out
|
||||
|
||||
# Run the tests.
|
||||
vim -N -u NONE -S test.vim
|
||||
|
||||
# Verify the outputs.
|
||||
for expected in *.ok; do
|
||||
name=${expected%.*}
|
||||
actual=$name.out
|
||||
diff $expected $actual && echo "$name ok" || echo "$name failed"
|
||||
done
|
||||
82
test/test.vim
Normal file
82
test/test.vim
Normal file
@@ -0,0 +1,82 @@
|
||||
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!
|
||||
|
||||
Reference in New Issue
Block a user