From 593df501b3a3687abb14a84299716bcd328b6ff8 Mon Sep 17 00:00:00 2001 From: watiko Date: Sun, 13 Dec 2015 12:19:54 +0900 Subject: vim-patch:7.4.944 Problem: Writing tests for Vim script is hard. Solution: Add assertEqual(), assertFalse() and assertTrue() functions. Add the v:errors variable. Add the runtest script. Add a first new style test script. https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801 --- src/nvim/testdir/Makefile | 18 +++++++- src/nvim/testdir/runtest.vim | 97 ++++++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_assert.vim | 19 ++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/nvim/testdir/runtest.vim create mode 100644 src/nvim/testdir/test_assert.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 1a414a8847..57d356705e 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -31,6 +31,8 @@ SCRIPTS := test_eval.out \ test_command_count.out \ test_cdo.out \ +NEW_TESTS = test_assert.res + SCRIPTS_GUI := test16.out @@ -62,9 +64,9 @@ ifdef TESTNUM SCRIPTS := test$(TESTNUM).out endif -nongui: nolog $(SCRIPTS) report +nongui: nolog $(SCRIPTS) newtests report -gui: nolog $(SCRIPTS) $(SCRIPTS_GUI) report +gui: nolog $(SCRIPTS) $(SCRIPTS_GUI) newtests report .gdbinit: echo 'set $$_exitcode = -1\nrun\nif $$_exitcode != -1\n quit\nend' > .gdbinit @@ -91,6 +93,7 @@ RUN_VIM := VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(TOOL) $(VIMPROG) clean: -rm -rf *.out \ *.failed \ + *.res \ *.rej \ *.orig \ test.log \ @@ -147,3 +150,14 @@ test49.out: test49.vim nolog: -rm -f test.log + + +# New style of tests uses Vim script with assert calls. These are easier +# to write and a lot easier to read and debug. +# Limitation: Only works with the +eval feature. +RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -u unix.vim -U NONE --noplugin + +newtests: $(NEW_TESTS) + +%.res: %.vim .gdbinit + $(RUN_VIMTEST) -u runtest.vim $*.vim diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim new file mode 100644 index 0000000000..8589bf6935 --- /dev/null +++ b/src/nvim/testdir/runtest.vim @@ -0,0 +1,97 @@ +" This script is sourced while editing the .vim file with the tests. +" When the script is successful the .res file will be created. +" Errors are appended to the test.log file. +" +" The test script may contain anything, only functions that start with +" "Test_" are special. These will be invoked and should contain assert +" functions. See test_assert.vim for an example. +" +" It is possible to source other files that contain "Test_" functions. This +" can speed up testing, since Vim does not need to restart. But be careful +" that the tests do not interfere with each other. +" +" If an error cannot be detected properly with an assert function add the +" error to the v:errors list: +" call add(v:errors, 'test foo failed: Cannot find xyz') +" +" If preparation for each Test_ function is needed, define a SetUp function. +" It will be called before each Test_ function. +" +" If cleanup after each Test_ function is needed, define a TearDown function. +" It will be called after each Test_ function. + +" Without the +eval feature we can't run these tests, bail out. +if 0 + quit! +endif + +" Check that the screen size is at least 24 x 80 characters. +if &lines < 24 || &columns < 80 + let error = 'Screen size too small! Tests require at least 24 lines with 80 characters' + echoerr error + split test.log + $put =error + w + cquit +endif + +" Source the test script. First grab the file name, in case the script +" navigates away. +let testname = expand('%') +source % + +" Locate Test_ functions and execute them. +redir @q +function /^Test_ +redir END +let tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) + +let done = 0 +let fail = 0 +let errors = [] +for test in tests + if exists("*SetUp") + call SetUp() + endif + + let done += 1 + try + exe 'call ' . test + catch + let fail += 1 + call add(v:errors, 'Caught exception in ' . test . ': ' . v:exception . ' @ ' . v:throwpoint) + endtry + + if len(v:errors) > 0 + let fail += 1 + call add(errors, 'Found errors in ' . test . ':') + call extend(errors, v:errors) + let v:errors = [] + endif + + if exists("*TearDown") + call TearDown() + endif +endfor + +if fail == 0 + " Success, create the .res file so that make knows it's done. + split %:r.res + write +endif + +if len(errors) > 0 + " Append errors to test.log + split test.log + call append(line('$'), '') + call append(line('$'), 'From ' . testname . ':') + call append(line('$'), errors) + write +endif + +echo 'Executed ' . done . (done > 1 ? ' tests': ' test') +if fail > 0 + echo fail . ' FAILED' +endif + +qall! diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim new file mode 100644 index 0000000000..049ce98859 --- /dev/null +++ b/src/nvim/testdir/test_assert.vim @@ -0,0 +1,19 @@ +" Test that the methods used for testing work. + +func Test_assert_false() + call assert_false(0) +endfunc + +func Test_assert_true() + call assert_true(1) + call assert_true(123) +endfunc + +func Test_assert_equal() + let s = 'foo' + call assert_equal('foo', s) + let n = 4 + call assert_equal(4, n) + let l = [1, 2, 3] + call assert_equal([1, 2, 3], l) +endfunc -- cgit From 008c014cbe0fd4862dd989287aca1050d2ed89b1 Mon Sep 17 00:00:00 2001 From: watiko Date: Sun, 13 Dec 2015 20:15:48 +0900 Subject: vim-patch:7.4.945 Problem: New style testing is incomplete. Solution: Add the runtest script to the list of distributed files. Add the new functions to the function overview. Rename the functions to match Vim function style. Move undolevels testing into a new style test script. https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb --- src/nvim/testdir/Makefile | 3 ++- src/nvim/testdir/test_undolevels.vim | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/nvim/testdir/test_undolevels.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 57d356705e..23a9b97d91 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -31,7 +31,8 @@ SCRIPTS := test_eval.out \ test_command_count.out \ test_cdo.out \ -NEW_TESTS = test_assert.res +NEW_TESTS = test_assert.res \ + test_undolevels.res SCRIPTS_GUI := test16.out diff --git a/src/nvim/testdir/test_undolevels.vim b/src/nvim/testdir/test_undolevels.vim new file mode 100644 index 0000000000..427cece24c --- /dev/null +++ b/src/nvim/testdir/test_undolevels.vim @@ -0,0 +1,46 @@ +" Tests for 'undolevels' + +set nocompatible viminfo+=nviminfo + +func FillBuffer() + for i in range(1,13) + put=i + " Set 'undolevels' to split undo. + exe "setg ul=" . &g:ul + endfor +endfunc + +func Test_global_local_undolevels() + new one + set undolevels=5 + call FillBuffer() + " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines + earlier 10 + call assert_equal(5, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + call assert_equal('7', getline('$')) + + new two + setlocal undolevels=2 + call FillBuffer() + " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines + earlier 10 + call assert_equal(5, &g:undolevels) + call assert_equal(2, &l:undolevels) + call assert_equal('10', getline('$')) + + setlocal ul=10 + call assert_equal(5, &g:undolevels) + call assert_equal(10, &l:undolevels) + + " Setting local value in "two" must not change local value in "one" + wincmd p + call assert_equal(5, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + + new three + setglobal ul=50 + call assert_equal(50, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + +endfunc -- cgit From 2586459118ca589c8393121a5d3696802ed1a606 Mon Sep 17 00:00:00 2001 From: watiko Date: Sun, 13 Dec 2015 22:40:23 +0900 Subject: vim-patch:7.4.953 Problem: When a test script navigates to another buffer the .res file is created with the wrong name. Solution: Use the "testname" for the .res file. (Damien) https://github.com/vim/vim/commit/de0ad40cb3c1bc691a754698ed16a5b6cdb4086b --- src/nvim/testdir/runtest.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 8589bf6935..0dc142eb97 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -76,7 +76,7 @@ endfor if fail == 0 " Success, create the .res file so that make knows it's done. - split %:r.res + exe 'split ' . fnamemodify(testname, ':r') . '.res' write endif -- cgit From 6c8e572d098457868c9090fa562d9628c6537849 Mon Sep 17 00:00:00 2001 From: watiko Date: Sun, 10 Jan 2016 09:10:17 +0900 Subject: vim-patch:7.4.1055 Problem: Running "make newtests" in src/testdir has no output. Solution: List the messages file when a test fails. (Christian Brabandt) Update the list of tests. https://github.com/vim/vim/commit/e7893a4088d6ea796bcab6195d232cb26c12c317 --- src/nvim/testdir/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 23a9b97d91..efcb8a68d2 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -158,7 +158,12 @@ nolog: # Limitation: Only works with the +eval feature. RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -u unix.vim -U NONE --noplugin -newtests: $(NEW_TESTS) +newtests: newtestssilent + @/bin/sh -c "if test -f messages && grep -q 'FAILED' messages; then \ + cat messages && cat test.log; \ + fi" \ + +newtestssilent: $(NEW_TESTS) %.res: %.vim .gdbinit $(RUN_VIMTEST) -u runtest.vim $*.vim -- cgit From d8e07deff6e3763166259f04c57b8f253bb2db46 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 17 Dec 2015 17:22:19 +0900 Subject: tests: Migrate legacy test assert. --- src/nvim/testdir/Makefile | 3 +-- src/nvim/testdir/test_assert.vim | 19 ------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 src/nvim/testdir/test_assert.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index efcb8a68d2..381d1727da 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -31,8 +31,7 @@ SCRIPTS := test_eval.out \ test_command_count.out \ test_cdo.out \ -NEW_TESTS = test_assert.res \ - test_undolevels.res +NEW_TESTS = test_undolevels.res SCRIPTS_GUI := test16.out diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim deleted file mode 100644 index 049ce98859..0000000000 --- a/src/nvim/testdir/test_assert.vim +++ /dev/null @@ -1,19 +0,0 @@ -" Test that the methods used for testing work. - -func Test_assert_false() - call assert_false(0) -endfunc - -func Test_assert_true() - call assert_true(1) - call assert_true(123) -endfunc - -func Test_assert_equal() - let s = 'foo' - call assert_equal('foo', s) - let n = 4 - call assert_equal(4, n) - let l = [1, 2, 3] - call assert_equal([1, 2, 3], l) -endfunc -- cgit From 9c5ab23ef2e0adf45b09d9f0586e5c914db9658f Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 17 Dec 2015 17:55:34 +0900 Subject: tests: Migrate legacy test undolevels. --- src/nvim/testdir/Makefile | 2 +- src/nvim/testdir/test_undolevels.vim | 46 ------------------------------------ 2 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 src/nvim/testdir/test_undolevels.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 381d1727da..b4292dbd4b 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -31,7 +31,7 @@ SCRIPTS := test_eval.out \ test_command_count.out \ test_cdo.out \ -NEW_TESTS = test_undolevels.res +NEW_TESTS = SCRIPTS_GUI := test16.out diff --git a/src/nvim/testdir/test_undolevels.vim b/src/nvim/testdir/test_undolevels.vim deleted file mode 100644 index 427cece24c..0000000000 --- a/src/nvim/testdir/test_undolevels.vim +++ /dev/null @@ -1,46 +0,0 @@ -" Tests for 'undolevels' - -set nocompatible viminfo+=nviminfo - -func FillBuffer() - for i in range(1,13) - put=i - " Set 'undolevels' to split undo. - exe "setg ul=" . &g:ul - endfor -endfunc - -func Test_global_local_undolevels() - new one - set undolevels=5 - call FillBuffer() - " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines - earlier 10 - call assert_equal(5, &g:undolevels) - call assert_equal(-123456, &l:undolevels) - call assert_equal('7', getline('$')) - - new two - setlocal undolevels=2 - call FillBuffer() - " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines - earlier 10 - call assert_equal(5, &g:undolevels) - call assert_equal(2, &l:undolevels) - call assert_equal('10', getline('$')) - - setlocal ul=10 - call assert_equal(5, &g:undolevels) - call assert_equal(10, &l:undolevels) - - " Setting local value in "two" must not change local value in "one" - wincmd p - call assert_equal(5, &g:undolevels) - call assert_equal(-123456, &l:undolevels) - - new three - setglobal ul=50 - call assert_equal(50, &g:undolevels) - call assert_equal(-123456, &l:undolevels) - -endfunc -- cgit