From 7f59f5b1042a39d2b29bb79603bdf4b235971ba1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:36:38 +0200 Subject: [PATCH 1/7] vim-patch:8.1.0496: no tests for indent files Problem: No tests for indent files. Solution: Add a mechanism for running indent file tests. Add a first test for Vim indenting. https://github.com/vim/vim/commit/c0fe4978f2311be9a0221d4c2369251c719b399a --- runtime/indent/Makefile | 13 +++ runtime/indent/README.txt | 2 + runtime/indent/testdir/README.txt | 92 +++++++++++++++++++++ runtime/indent/testdir/cleantest.vim | 6 ++ runtime/indent/testdir/runtest.vim | 117 +++++++++++++++++++++++++++ runtime/indent/testdir/vim.in | 46 +++++++++++ runtime/indent/testdir/vim.ok | 46 +++++++++++ 7 files changed, 322 insertions(+) create mode 100644 runtime/indent/Makefile create mode 100644 runtime/indent/testdir/README.txt create mode 100644 runtime/indent/testdir/cleantest.vim create mode 100644 runtime/indent/testdir/runtest.vim create mode 100644 runtime/indent/testdir/vim.in create mode 100644 runtime/indent/testdir/vim.ok diff --git a/runtime/indent/Makefile b/runtime/indent/Makefile new file mode 100644 index 0000000000..fa81db0470 --- /dev/null +++ b/runtime/indent/Makefile @@ -0,0 +1,13 @@ +# Portable Makefile for running indent tests. + +VIM = vim + +# Run the tests that didn't run yet or failed previously. +# If a test succeeds a testdir/*.out file will be written. +# If a test fails a testdir/*.fail file will be written. +test: + $(VIM) --not-a-term -u testdir/runtest.vim + + +clean: + $(VIM) --not-a-term -u testdir/cleantest.vim diff --git a/runtime/indent/README.txt b/runtime/indent/README.txt index a424b4f8c0..8b114365c6 100644 --- a/runtime/indent/README.txt +++ b/runtime/indent/README.txt @@ -43,3 +43,5 @@ running. Add a test if the function exists and use ":finish", like this: The user may have several options set unlike you, try to write the file such that it works with any option settings. Also be aware of certain features not being compiled in. + +To test the indent file, see testdir/README.txt. diff --git a/runtime/indent/testdir/README.txt b/runtime/indent/testdir/README.txt new file mode 100644 index 0000000000..8efd34ed4c --- /dev/null +++ b/runtime/indent/testdir/README.txt @@ -0,0 +1,92 @@ +TESTING INDENT SCRIPTS + +We'll use FILETYPE for the filetype name here. + + +FORMAT OF THE FILETYPE.IN FILE + +First of all, create a FILETYPE.in file. It should contain: + +- A modeline setting the 'filetype' and any other option values. + This must work like a comment for FILETYPE. E.g. for vim: + " vim: set ft=vim sw=4 : + +- At least one block of lines to indent, prefixed with START_INDENT and + followed by END_INDENT. These lines must also look like a comment for your + FILETYPE. You would normally leave out all indent, so that the effect of + the indent command results in adding indent. Example: + + " START_INDENT + func Some() + let x = 1 + endfunc + " END_INDENT + +- Optionally, a line with INDENT_EXE, followed by a Vim command. This will be + executed before indenting the lines. Example: + + " START_INDENT + " INDENT_EXE let g:vim_indent_cont = 6 + let cmd = + \ 'some ' + \ 'string' + " END_INDENT + + Note that the command is not undone, you may need to reverse the effect for + the next block of lines. + +- Alternatively to indenting all the lines between START_INDENT and + END_INDENT, use a INDENT_AT line, which specifies a pattern to find the line + to indent. Example: + + " START_INDENT + " INDENT_AT this-line + func Some() + let f = x " this-line + endfunc + " END_INDENT + + Alternatively you can use INDENT_NEXT to indent the line below the matching + pattern: + + " START_INDENT + " INDENT_NEXT next-line + func Some() + " next-line + let f = x + endfunc + " END_INDENT + + Or use INDENT_PREV to indent the line above the matching pattern: + + " START_INDENT + " INDENT_PREV prev-line + func Some() + let f = x + " prev-line + endfunc + " END_INDENT + +It's best to keep the whole file valid for FILETYPE, so that syntax +highlighting works normally, and any indenting that depends on the syntax +highlighting also works. + + +RUNNING THE TEST + +Before running the test, create a FILETYPE.ok file. You can leave it empty at +first. + +Now run "make test". After Vim has done the indenting you will see a +FILETYPE.fail file. This contains the actual result of indenting, and it's +different from the FILETYPE.ok file. + +Check the contents of the FILETYPE.fail file. If it is perfectly OK, then +rename it to overwrite the FILETYPE.ok file. If you now run "make test" again, +the test will pass and create a FILETYPE.out file, which is identical to the +FILETYPE.ok file. + +If you try to run "make test" again you will notice that nothing happens, +because the FILETYPE.out file already exists. Delete it, or do "make clean", +so that the text runs again. If you edit the FILETYPE.in file, so that it's +newer than the FILETYPE.out file, the test will also run. diff --git a/runtime/indent/testdir/cleantest.vim b/runtime/indent/testdir/cleantest.vim new file mode 100644 index 0000000000..909cf812c4 --- /dev/null +++ b/runtime/indent/testdir/cleantest.vim @@ -0,0 +1,6 @@ +" Deletes all the test output files: *.fail and *.out +for fname in glob('testdir/*.out', 1, 1) + glob('testdir/*.fail', 1, 1) + call delete(fname) +endfor + +quit diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim new file mode 100644 index 0000000000..5d36512f94 --- /dev/null +++ b/runtime/indent/testdir/runtest.vim @@ -0,0 +1,117 @@ +" Runs all the indent tests for which there is no .out file + +set nocp +filetype indent on +set nowrapscan + +au! SwapExists * call HandleSwapExists() +func HandleSwapExists() + " Ignore finding a swap file for the test input and output, the user might be + " editing them and that's OK. + if expand('') =~ '.*\.\(in\|out\|fail\|ok\)' + let v:swapchoice = 'e' + endif +endfunc + +for fname in glob('testdir/*.in', 1, 1) + let root = substitute(fname, '\.in', '', '') + + " Execute the test if the .out file does not exist of when the .in file is + " newer. + let in_time = getftime(fname) + let out_time = getftime(root . '.out') + if out_time < 0 || in_time > out_time + call delete(root . '.fail') + call delete(root . '.out') + + set sw& ts& filetype= + exe 'split ' . fname + + let did_some = 0 + let failed = 0 + let end = 1 + while 1 + " Indent all the lines between "START_INDENT" and "END_INDENT" + exe end + let start = search('\') + let end = search('\') + if start <= 0 || end <= 0 || end <= start + if did_some == 0 + call append(0, 'ERROR: START_INDENT and/or END_INDENT not found') + let failed = 1 + endif + break + else + let did_some = 1 + + " Execute all commands marked with INDENT_EXE and find any pattern. + let lnum = start + let pattern = '' + let at = '' + while 1 + exe lnum + 1 + let lnum_exe = search('\') + exe lnum + 1 + let indent_at = search('\') + if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at) + exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '') + let lnum = lnum_exe + let start = lnum + elseif indent_at > 0 && indent_at < end + if pattern != '' + call append(indent_at, 'ERROR: duplicate pattern') + let failed = 1 + break + endif + let text = getline(indent_at) + let pattern = substitute(text, '.*INDENT_\S*\s*', '', '') + let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '') + let lnum = indent_at + let start = lnum + else + break + endif + endwhile + + exe start + 1 + if pattern == '' + exe 'normal =' . (end - 1) . 'G' + else + let lnum = search(pattern) + if lnum <= 0 + call append(indent_at, 'ERROR: pattern not found: ' . pattern) + let failed = 1 + break + endif + if at == 'AT' + exe lnum + elseif at == 'NEXT' + exe lnum + 1 + else + exe lnum - 1 + endif + normal == + endif + endif + endwhile + + if !failed + " Check the resulting text equals the .ok file. + if getline(1, '$') != readfile(root . '.ok') + let failed = 1 + endif + endif + + if failed + exe 'write ' . root . '.fail' + echoerr 'Test ' . fname . ' FAILED!' + sleep 2 + else + exe 'write ' . root . '.out' + endif + + quit! " close the indented file + endif +endfor + +qall! diff --git a/runtime/indent/testdir/vim.in b/runtime/indent/testdir/vim.in new file mode 100644 index 0000000000..ca105f6eda --- /dev/null +++ b/runtime/indent/testdir/vim.in @@ -0,0 +1,46 @@ +" vim: set ft=vim sw=4 : + +" START_INDENT + +func Some() +let x = 1 +endfunc + +let cmd = +\ 'some ' +\ 'string' + +" END_INDENT + +" START_INDENT +" INDENT_EXE let g:vim_indent_cont = 6 + +let cmd = +\ 'some ' +\ 'string' + +" END_INDENT + +" START_INDENT +" INDENT_EXE unlet g:vim_indent_cont +" INDENT_AT this-line +func Some() +let f = x " this-line +endfunc +" END_INDENT + +" START_INDENT +" INDENT_NEXT next-line +func Some() + " next-line +let f = x +endfunc +" END_INDENT + +" START_INDENT +" INDENT_PREV prev-line +func Some() +let f = x +" prev-line +endfunc +" END_INDENT diff --git a/runtime/indent/testdir/vim.ok b/runtime/indent/testdir/vim.ok new file mode 100644 index 0000000000..542861ec9c --- /dev/null +++ b/runtime/indent/testdir/vim.ok @@ -0,0 +1,46 @@ +" vim: set ft=vim sw=4 : + +" START_INDENT + +func Some() + let x = 1 +endfunc + +let cmd = + \ 'some ' + \ 'string' + +" END_INDENT + +" START_INDENT +" INDENT_EXE let g:vim_indent_cont = 6 + +let cmd = + \ 'some ' + \ 'string' + +" END_INDENT + +" START_INDENT +" INDENT_EXE unlet g:vim_indent_cont +" INDENT_AT this-line +func Some() + let f = x " this-line +endfunc +" END_INDENT + +" START_INDENT +" INDENT_NEXT next-line +func Some() + " next-line + let f = x +endfunc +" END_INDENT + +" START_INDENT +" INDENT_PREV prev-line +func Some() + let f = x +" prev-line +endfunc +" END_INDENT From b466f0e1141fd09847c9763aaa2d02de770e299d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:37:41 +0200 Subject: [PATCH 2/7] vim-patch:8.1.0545: when executing indent tests user preferences interfere Problem: When executing indent tests user preferences interfere. Solution: Add "--clean". https://github.com/vim/vim/commit/dc2f73a6980be13c97a83047d0de50824bc0f20f --- runtime/indent/Makefile | 4 ++-- runtime/indent/testdir/runtest.vim | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/indent/Makefile b/runtime/indent/Makefile index fa81db0470..3791f3348d 100644 --- a/runtime/indent/Makefile +++ b/runtime/indent/Makefile @@ -6,8 +6,8 @@ VIM = vim # If a test succeeds a testdir/*.out file will be written. # If a test fails a testdir/*.fail file will be written. test: - $(VIM) --not-a-term -u testdir/runtest.vim + $(VIM) --clean --not-a-term -u testdir/runtest.vim clean: - $(VIM) --not-a-term -u testdir/cleantest.vim + $(VIM) --clean --not-a-term -u testdir/cleantest.vim diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim index 5d36512f94..1cc0d3f716 100644 --- a/runtime/indent/testdir/runtest.vim +++ b/runtime/indent/testdir/runtest.vim @@ -1,4 +1,6 @@ -" Runs all the indent tests for which there is no .out file +" Runs all the indent tests for which there is no .out file. +" +" Current directory must be runtime/indent. set nocp filetype indent on From 865aaa031a06fca61d717621a26906cef42732d1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:38:07 +0200 Subject: [PATCH 3/7] vim-patch:8.1.0576: indent script tests pick up installed scripts Problem: Indent script tests pick up installed scripts. Solution: Use current runtime indent scripts. https://github.com/vim/vim/commit/30700cd5ffa258f1d684ab6b34bd03e970450dba --- runtime/indent/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/indent/Makefile b/runtime/indent/Makefile index 3791f3348d..1917e46c6b 100644 --- a/runtime/indent/Makefile +++ b/runtime/indent/Makefile @@ -1,13 +1,14 @@ # Portable Makefile for running indent tests. VIM = vim +VIMRUNTIME = .. # Run the tests that didn't run yet or failed previously. # If a test succeeds a testdir/*.out file will be written. # If a test fails a testdir/*.fail file will be written. test: - $(VIM) --clean --not-a-term -u testdir/runtest.vim + VIMRUNTIME=$(VIMRUNTIME) $(VIM) --clean --not-a-term -u testdir/runtest.vim clean: - $(VIM) --clean --not-a-term -u testdir/cleantest.vim + VIMRUNTIME=$(VIMRUNTIME) $(VIM) --clean --not-a-term -u testdir/cleantest.vim From 10c050caf99df7324f84b4595e8fd1db7f7a2c10 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:38:27 +0200 Subject: [PATCH 4/7] vim-patch:8.1.0599: without the +eval feature the indent tests don't work Problem: Without the +eval feature the indent tests don't work. Solution: Skip the body of the tests. https://github.com/vim/vim/commit/eeed665b0ecd917e88e3475c9615d52546aa124d --- runtime/indent/testdir/cleantest.vim | 13 +++++++++---- runtime/indent/testdir/runtest.vim | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/runtime/indent/testdir/cleantest.vim b/runtime/indent/testdir/cleantest.vim index 909cf812c4..69c0a1d4ba 100644 --- a/runtime/indent/testdir/cleantest.vim +++ b/runtime/indent/testdir/cleantest.vim @@ -1,6 +1,11 @@ -" Deletes all the test output files: *.fail and *.out -for fname in glob('testdir/*.out', 1, 1) + glob('testdir/*.fail', 1, 1) - call delete(fname) -endfor +" Only do this with the +eval feature +if 1 + + " Deletes all the test output files: *.fail and *.out + for fname in glob('testdir/*.out', 1, 1) + glob('testdir/*.fail', 1, 1) + call delete(fname) + endfor + +endif quit diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim index 1cc0d3f716..96c31453af 100644 --- a/runtime/indent/testdir/runtest.vim +++ b/runtime/indent/testdir/runtest.vim @@ -2,6 +2,9 @@ " " Current directory must be runtime/indent. +" Only do this with the +eval feature +if 1 + set nocp filetype indent on set nowrapscan @@ -116,4 +119,7 @@ for fname in glob('testdir/*.in', 1, 1) endif endfor +" Matching "if 1" at the start. +endif + qall! From 48b2d21d5ea328089a2e8fb3798aa93d1a15a388 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:40:06 +0200 Subject: [PATCH 5/7] vim-patch:8.1.1213: "make clean" in top dir does not cleanup indent test output Problem: "make clean" in top dir does not cleanup indent test output. Solution: Clean the indent test output. Do not rely on the vim executable for that. (closes vim/vim#4307) https://github.com/vim/vim/commit/e13a3901cae0afb4d2af30d497696af08029fd81 --- Makefile | 1 + runtime/indent/Makefile | 2 +- runtime/indent/testdir/cleantest.vim | 11 ----------- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 runtime/indent/testdir/cleantest.vim diff --git a/Makefile b/Makefile index 264ae8a470..f5b9459b0c 100644 --- a/Makefile +++ b/Makefile @@ -158,6 +158,7 @@ clean: +test -d build && $(BUILD_CMD) -C build clean || true $(MAKE) -C src/nvim/testdir clean $(MAKE) -C runtime/doc clean + $(MAKE) -C runtime/indent clean distclean: rm -rf $(DEPS_BUILD_DIR) build diff --git a/runtime/indent/Makefile b/runtime/indent/Makefile index 1917e46c6b..d192605527 100644 --- a/runtime/indent/Makefile +++ b/runtime/indent/Makefile @@ -11,4 +11,4 @@ test: clean: - VIMRUNTIME=$(VIMRUNTIME) $(VIM) --clean --not-a-term -u testdir/cleantest.vim + rm -f testdir/*.fail testdir/*.out diff --git a/runtime/indent/testdir/cleantest.vim b/runtime/indent/testdir/cleantest.vim deleted file mode 100644 index 69c0a1d4ba..0000000000 --- a/runtime/indent/testdir/cleantest.vim +++ /dev/null @@ -1,11 +0,0 @@ -" Only do this with the +eval feature -if 1 - - " Deletes all the test output files: *.fail and *.out - for fname in glob('testdir/*.out', 1, 1) + glob('testdir/*.fail', 1, 1) - call delete(fname) - endfor - -endif - -quit From 0e75a9eead33b99d8bbf30ec2b67f09257bf71ee Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:51:50 +0200 Subject: [PATCH 6/7] Update runtime/indent/testdir to latest Vim runtime Several runtime updates ignored the non-existing files. --- runtime/indent/testdir/README.txt | 23 ++++++++++++++--------- runtime/indent/testdir/runtest.vim | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/runtime/indent/testdir/README.txt b/runtime/indent/testdir/README.txt index 8efd34ed4c..65975605c2 100644 --- a/runtime/indent/testdir/README.txt +++ b/runtime/indent/testdir/README.txt @@ -22,8 +22,12 @@ First of all, create a FILETYPE.in file. It should contain: endfunc " END_INDENT -- Optionally, a line with INDENT_EXE, followed by a Vim command. This will be - executed before indenting the lines. Example: + If you just want to test normal indenting with default options, you can make + this a large number of lines. Just add all kinds of language constructs, + nested statements, etc. with valid syntax. + +- Optionally, add lines with INDENT_EXE after START_INDENT, followed by a Vim + command. This will be executed before indenting the lines. Example: " START_INDENT " INDENT_EXE let g:vim_indent_cont = 6 @@ -36,8 +40,8 @@ First of all, create a FILETYPE.in file. It should contain: the next block of lines. - Alternatively to indenting all the lines between START_INDENT and - END_INDENT, use a INDENT_AT line, which specifies a pattern to find the line - to indent. Example: + END_INDENT, use an INDENT_AT line, which specifies a pattern to find the + line to indent. Example: " START_INDENT " INDENT_AT this-line @@ -47,7 +51,8 @@ First of all, create a FILETYPE.in file. It should contain: " END_INDENT Alternatively you can use INDENT_NEXT to indent the line below the matching - pattern: + pattern. Keep in mind that quite often it will indent relative to the + matching line: " START_INDENT " INDENT_NEXT next-line @@ -77,14 +82,14 @@ RUNNING THE TEST Before running the test, create a FILETYPE.ok file. You can leave it empty at first. -Now run "make test". After Vim has done the indenting you will see a -FILETYPE.fail file. This contains the actual result of indenting, and it's -different from the FILETYPE.ok file. +Now run "make test" from the parent directory. After Vim has done the +indenting you will see a FILETYPE.fail file. This contains the actual result +of indenting, and it's different from the FILETYPE.ok file. Check the contents of the FILETYPE.fail file. If it is perfectly OK, then rename it to overwrite the FILETYPE.ok file. If you now run "make test" again, the test will pass and create a FILETYPE.out file, which is identical to the -FILETYPE.ok file. +FILETYPE.ok file. The FILETYPE.fail file will be deleted. If you try to run "make test" again you will notice that nothing happens, because the FILETYPE.out file already exists. Delete it, or do "make clean", diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim index 96c31453af..0f0051415d 100644 --- a/runtime/indent/testdir/runtest.vim +++ b/runtime/indent/testdir/runtest.vim @@ -7,7 +7,9 @@ if 1 set nocp filetype indent on +syn on set nowrapscan +set report=9999 au! SwapExists * call HandleSwapExists() func HandleSwapExists() @@ -110,7 +112,6 @@ for fname in glob('testdir/*.in', 1, 1) if failed exe 'write ' . root . '.fail' echoerr 'Test ' . fname . ' FAILED!' - sleep 2 else exe 'write ' . root . '.out' endif From 660b452440d60725f0cd68f264ba10b6add068c8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Sep 2019 22:52:22 +0200 Subject: [PATCH 7/7] vim-patch:8.1.2056: "make test" for indent files doesn't cause make to fail Problem: "make test" for indent files doesn't cause make to fail. Solution: Exit the script with ":cquit". (Daniel Hahler, closes vim/vim#4949) https://github.com/vim/vim/commit/cd67059c0c3abf1e28aa66458abdf6f338252eb2 --- .gitignore | 1 + runtime/indent/testdir/runtest.vim | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 7db3d96e2b..b7f710d1d7 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ tags /src/nvim/testdir/valgrind.* /src/nvim/testdir/.gdbinit /runtime/indent/testdir/*.out ++runtime/indent/testdir/*.fail # Generated by src/nvim/testdir/runnvim.sh. /src/nvim/testdir/*.tlog diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim index 0f0051415d..9502c42f3e 100644 --- a/runtime/indent/testdir/runtest.vim +++ b/runtime/indent/testdir/runtest.vim @@ -20,6 +20,7 @@ func HandleSwapExists() endif endfunc +let failed_count = 0 for fname in glob('testdir/*.in', 1, 1) let root = substitute(fname, '\.in', '', '') @@ -110,6 +111,7 @@ for fname in glob('testdir/*.in', 1, 1) endif if failed + let failed_count += 1 exe 'write ' . root . '.fail' echoerr 'Test ' . fname . ' FAILED!' else @@ -123,4 +125,8 @@ endfor " Matching "if 1" at the start. endif +if failed_count > 0 + " have make report an error + cquit +endif qall!