diff --git a/test/README.markdown b/test/README.markdown new file mode 100644 index 0000000..6444381 --- /dev/null +++ b/test/README.markdown @@ -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 `.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. diff --git a/test/addLines.ok b/test/addLines.ok new file mode 100644 index 0000000..8e2c2ec --- /dev/null +++ b/test/addLines.ok @@ -0,0 +1,4 @@ + +--- Signs --- +Signs for fixture.txt: + line=2 id=3000 name=GitGutterLineAdded diff --git a/test/fixture.txt b/test/fixture.txt new file mode 100644 index 0000000..f5c6aff --- /dev/null +++ b/test/fixture.txt @@ -0,0 +1,11 @@ +a +b +c +d +e +f +g +h +i +j + diff --git a/test/modifyLines.ok b/test/modifyLines.ok new file mode 100644 index 0000000..ca2daee --- /dev/null +++ b/test/modifyLines.ok @@ -0,0 +1,4 @@ + +--- Signs --- +Signs for fixture.txt: + line=1 id=3001 name=GitGutterLineModified diff --git a/test/noModifications.ok b/test/noModifications.ok new file mode 100644 index 0000000..aa8cd86 --- /dev/null +++ b/test/noModifications.ok @@ -0,0 +1,2 @@ + +--- Signs --- diff --git a/test/orphanedSigns.ok b/test/orphanedSigns.ok new file mode 100644 index 0000000..b37ee1b --- /dev/null +++ b/test/orphanedSigns.ok @@ -0,0 +1,4 @@ + +--- Signs --- +Signs for fixture.txt: + line=6 id=3005 name=GitGutterLineAdded diff --git a/test/removeFirstLines.ok b/test/removeFirstLines.ok new file mode 100644 index 0000000..4249f5d --- /dev/null +++ b/test/removeFirstLines.ok @@ -0,0 +1,4 @@ + +--- Signs --- +Signs for fixture.txt: + line=1 id=3003 name=GitGutterLineRemovedFirstLine diff --git a/test/removeLines.ok b/test/removeLines.ok new file mode 100644 index 0000000..284b83e --- /dev/null +++ b/test/removeLines.ok @@ -0,0 +1,4 @@ + +--- Signs --- +Signs for fixture.txt: + line=4 id=3002 name=GitGutterLineRemoved diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..d527811 --- /dev/null +++ b/test/test.sh @@ -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 diff --git a/test/test.vim b/test/test.vim new file mode 100644 index 0000000..b2fafff --- /dev/null +++ b/test/test.vim @@ -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\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! +