From b9f4173f7c455d43167a75cdbab1bdd576a57951 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Thu, 13 Nov 2014 12:32:42 +0100 Subject: [PATCH] Refactor tests to be isolated. --- test/README.markdown | 21 +++++---- test/helper.vim | 15 +++++++ test/modifyLines.ok | 2 +- test/orphanedSigns.ok | 2 +- test/removeFirstLines.ok | 2 +- test/removeLines.ok | 2 +- test/test.sh | 18 +++++--- test/test.vim | 82 ----------------------------------- test/testAddLines.vim | 8 ++++ test/testModifyLines.vim | 8 ++++ test/testNoModifications.vim | 6 +++ test/testOrphanedSigns.vim | 10 +++++ test/testRemoveFirstLines.vim | 8 ++++ test/testRemoveLines.vim | 8 ++++ 14 files changed, 92 insertions(+), 100 deletions(-) create mode 100644 test/helper.vim delete mode 100644 test/test.vim create mode 100644 test/testAddLines.vim create mode 100644 test/testModifyLines.vim create mode 100644 test/testNoModifications.vim create mode 100644 test/testOrphanedSigns.vim create mode 100644 test/testRemoveFirstLines.vim create mode 100644 test/testRemoveLines.vim diff --git a/test/README.markdown b/test/README.markdown index 6444381..afa3188 100644 --- a/test/README.markdown +++ b/test/README.markdown @@ -9,13 +9,18 @@ $ ./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. +- Add a test file named like `testFoo.vim`. It should have this structure: -### 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. diff --git a/test/helper.vim b/test/helper.vim new file mode 100644 index 0000000..c633c4a --- /dev/null +++ b/test/helper.vim @@ -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 + diff --git a/test/modifyLines.ok b/test/modifyLines.ok index ca2daee..91ad42c 100644 --- a/test/modifyLines.ok +++ b/test/modifyLines.ok @@ -1,4 +1,4 @@ --- Signs --- Signs for fixture.txt: - line=1 id=3001 name=GitGutterLineModified + line=1 id=3000 name=GitGutterLineModified diff --git a/test/orphanedSigns.ok b/test/orphanedSigns.ok index b37ee1b..1beeb65 100644 --- a/test/orphanedSigns.ok +++ b/test/orphanedSigns.ok @@ -1,4 +1,4 @@ --- Signs --- Signs for fixture.txt: - line=6 id=3005 name=GitGutterLineAdded + line=6 id=3001 name=GitGutterLineAdded diff --git a/test/removeFirstLines.ok b/test/removeFirstLines.ok index 4249f5d..1cbfd76 100644 --- a/test/removeFirstLines.ok +++ b/test/removeFirstLines.ok @@ -1,4 +1,4 @@ --- Signs --- Signs for fixture.txt: - line=1 id=3003 name=GitGutterLineRemovedFirstLine + line=1 id=3000 name=GitGutterLineRemovedFirstLine diff --git a/test/removeLines.ok b/test/removeLines.ok index 284b83e..94d8ee4 100644 --- a/test/removeLines.ok +++ b/test/removeLines.ok @@ -1,4 +1,4 @@ --- Signs --- Signs for fixture.txt: - line=4 id=3002 name=GitGutterLineRemoved + line=4 id=3000 name=GitGutterLineRemoved diff --git a/test/test.sh b/test/test.sh index d527811..fd585a8 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,13 +1,19 @@ #!/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 -# Run the tests. -vim -N -u NONE -S test.vim - -# Verify the outputs. -for expected in *.ok; do - name=${expected%.*} +for testcase in test*.vim; do + vim -N -u NONE -S $testcase # testFoo.vim + testname=${testcase%.*} # testFoo + name=${testname:4} # Foo + name="$(tr '[:upper:]' '[:lower:]' <<< ${name:0:1})${name:1}" # foo + expected=$name.ok actual=$name.out diff $expected $actual && echo "$name ok" || echo "$name failed" done + +git checkout fixture.txt + diff --git a/test/test.vim b/test/test.vim deleted file mode 100644 index b2fafff..0000000 --- a/test/test.vim +++ /dev/null @@ -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\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! - diff --git a/test/testAddLines.vim b/test/testAddLines.vim new file mode 100644 index 0000000..6c2bad3 --- /dev/null +++ b/test/testAddLines.vim @@ -0,0 +1,8 @@ +source helper.vim +call Setup() + +normal ggo* +write +call DumpSigns('addLines') + +quit! diff --git a/test/testModifyLines.vim b/test/testModifyLines.vim new file mode 100644 index 0000000..d549404 --- /dev/null +++ b/test/testModifyLines.vim @@ -0,0 +1,8 @@ +source helper.vim +call Setup() + +normal ggi* +write +call DumpSigns('modifyLines') + +quit! diff --git a/test/testNoModifications.vim b/test/testNoModifications.vim new file mode 100644 index 0000000..9ca295c --- /dev/null +++ b/test/testNoModifications.vim @@ -0,0 +1,6 @@ +source helper.vim +call Setup() + +call DumpSigns('noModifications') + +quit! diff --git a/test/testOrphanedSigns.vim b/test/testOrphanedSigns.vim new file mode 100644 index 0000000..6659f04 --- /dev/null +++ b/test/testOrphanedSigns.vim @@ -0,0 +1,10 @@ +source helper.vim +call Setup() + +execute "normal 5GoX\Y" +write +execute '6d' +write +call DumpSigns('orphanedSigns') + +quit! diff --git a/test/testRemoveFirstLines.vim b/test/testRemoveFirstLines.vim new file mode 100644 index 0000000..42f019d --- /dev/null +++ b/test/testRemoveFirstLines.vim @@ -0,0 +1,8 @@ +source helper.vim +call Setup() + +execute '1d' +write +call DumpSigns('removeFirstLines') + +quit! diff --git a/test/testRemoveLines.vim b/test/testRemoveLines.vim new file mode 100644 index 0000000..032f9d1 --- /dev/null +++ b/test/testRemoveLines.vim @@ -0,0 +1,8 @@ +source helper.vim +call Setup() + +execute '5d' +write +call DumpSigns('removeLines') + +quit!