To: vim_dev@googlegroups.com Subject: Patch 8.0.1526 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1526 Problem: No test using a screen dump yet. Solution: Add a test for C syntax highlighting. Add helper functions. Files: src/terminal.c, src/testdir/test_syntax.vim, src/testdir/shared.vim, src/testdir/screendump.vim, src/testdir/dumps/Test_syntax_c_01.dump, runtime/doc/terminal.txt, src/testdir/README.txt *** ../vim-8.0.1525/src/terminal.c 2018-02-19 21:50:38.346102072 +0100 --- src/terminal.c 2018-02-20 15:41:00.512381833 +0100 *************** *** 410,419 **** if (!opt->jo_hidden) { ! /* only one size was taken care of with :new, do the other one */ ! if (opt->jo_term_rows > 0 && (cmdmod.split & WSP_VERT)) win_setheight(opt->jo_term_rows); ! if (opt->jo_term_cols > 0 && !(cmdmod.split & WSP_VERT)) win_setwidth(opt->jo_term_cols); } --- 410,422 ---- if (!opt->jo_hidden) { ! /* Only one size was taken care of with :new, do the other one. With ! * "curwin" both need to be done. */ ! if (opt->jo_term_rows > 0 && (opt->jo_curwin ! || (cmdmod.split & WSP_VERT))) win_setheight(opt->jo_term_rows); ! if (opt->jo_term_cols > 0 && (opt->jo_curwin ! || !(cmdmod.split & WSP_VERT))) win_setwidth(opt->jo_term_cols); } *** ../vim-8.0.1525/src/testdir/test_syntax.vim 2017-06-27 15:43:46.266992420 +0200 --- src/testdir/test_syntax.vim 2018-02-20 15:11:30.624526041 +0100 *************** *** 5,10 **** --- 5,13 ---- endif source view_util.vim + if has('terminal') + source screendump.vim + endif func GetSyntaxItem(pat) let c = '' *************** *** 497,503 **** bw! endfunc ! fun Test_synstack_synIDtrans() new setfiletype c syntax on --- 500,506 ---- bw! endfunc ! func Test_synstack_synIDtrans() new setfiletype c syntax on *************** *** 520,522 **** --- 523,558 ---- syn clear bw! endfunc + + " Check highlighting for a small piece of C code with a screen dump. + func Test_syntax_c() + if !has('terminal') + return + endif + call writefile([ + \ '/* comment line at the top */', + \ ' int', + \ 'main(int argc, char **argv)// another comment', + \ '{', + \ '#if 0', + \ ' int not_used;', + \ '#else', + \ ' int used;', + \ '#endif', + \ ' printf("Just an example piece of C code\n");', + \ ' return 0x0ff;', + \ '}', + \ ' static void', + \ 'myFunction(const double count, struct nothing, long there) {', + \ ' // 123: nothing to read here', + \ ' for (int i = 0; i < count; ++i) {', + \ ' break;', + \ ' }', + \ '}', + \ ], 'Xtest.c') + let buf = RunVimInTerminal('Xtest.c', {}) + call VerifyScreenDump(buf, 'Test_syntax_c_01') + call StopVimInTerminal(buf) + + call delete('Xtest.c') + endfun *** ../vim-8.0.1525/src/testdir/shared.vim 2017-11-04 18:48:39.170316937 +0100 --- src/testdir/shared.vim 2018-02-20 14:59:34.029274134 +0100 *************** *** 178,194 **** " The Makefile writes it as the first line in the "vimcmd" file. func GetVimProg() if !filereadable('vimcmd') ! return '' endif return readfile('vimcmd')[0] endfunc " Get the command to run Vim, with -u NONE and --not-a-term arguments. " If there is an argument use it instead of "NONE". - " Returns an empty string on error. func GetVimCommand(...) if !filereadable('vimcmd') ! return '' endif if a:0 == 0 let name = 'NONE' --- 178,197 ---- " The Makefile writes it as the first line in the "vimcmd" file. func GetVimProg() if !filereadable('vimcmd') ! " Assume the script was sourced instead of running "make". ! return '../vim' endif return readfile('vimcmd')[0] endfunc " Get the command to run Vim, with -u NONE and --not-a-term arguments. " If there is an argument use it instead of "NONE". func GetVimCommand(...) if !filereadable('vimcmd') ! echo 'Cannot read the "vimcmd" file, falling back to ../vim.' ! let lines = ['../vim'] ! else ! let lines = readfile('vimcmd') endif if a:0 == 0 let name = 'NONE' *************** *** 199,205 **** " "vimcmd" file, including environment options. " Other Makefiles just write the executable in the first line, so fall back " to that if there is no second line. - let lines = readfile('vimcmd') let cmd = get(lines, 1, lines[0]) let cmd = substitute(cmd, '-u \f\+', '-u ' . name, '') if cmd !~ '-u '. name --- 202,207 ---- *************** *** 210,215 **** --- 212,225 ---- return cmd endfunc + " Get the command to run Vim, with --clean. + func GetVimCommandClean() + let cmd = GetVimCommand() + let cmd = substitute(cmd, '-u NONE', '--clean', '') + let cmd = substitute(cmd, '--not-a-term', '', '') + return cmd + endfunc + " Run Vim, using the "vimcmd" file and "-u NORC". " "before" is a list of Vim commands to be executed before loading plugins. " "after" is a list of Vim commands to be executed after loading plugins. *** ../vim-8.0.1525/src/testdir/screendump.vim 2018-02-20 15:40:04.424769276 +0100 --- src/testdir/screendump.vim 2018-02-20 15:49:09.257013834 +0100 *************** *** 0 **** --- 1,65 ---- + " Functions shared by tests making screen dumps. + + " Only load this script once. + if exists('*RunVimInTerminal') + finish + endif + + source shared.vim + + " Run Vim with "arguments" in a new terminal window. + " By default uses a size of 20 lines and 75 columns. + " Returns the buffer number of the terminal. + " + " Options is a dictionary (not used yet). + func RunVimInTerminal(arguments, options) + " Make a horizontal and vertical split, so that we can get exactly the right + " size terminal window. Works only when we currently have one window. + call assert_equal(1, winnr('$')) + split + vsplit + + " Always doo this with 256 colors and a light background. + set t_Co=256 + hi Normal ctermfg=0 ctermbg=15 + + let cmd = GetVimCommandClean() + let cmd .= ' ' . a:arguments + let buf = term_start(cmd, {'curwin': 1, 'term_rows': 20, 'term_cols': 75}) + call assert_equal([20, 75], term_getsize(buf)) + + return buf + endfunc + + " Stop a Vim running in terminal buffer "buf". + func StopVimInTerminal(buf) + call assert_equal("running", term_getstatus(a:buf)) + call term_sendkeys(a:buf, ":qa!\") + call WaitFor('term_getstatus(' . a:buf . ') == "finished"') + only! + endfunc + + " Verify that Vim running in terminal buffer "buf" matches the screen dump. + " The file name used is "dumps/{filename}.dump". + " Will wait for up to a second for the screen dump to match. + func VerifyScreenDump(buf, filename) + let reference = 'dumps/' . a:filename . '.dump' + let testfile = a:filename . '.dump.failed' + + let i = 0 + while 1 + call delete(testfile) + call term_dumpwrite(a:buf, testfile) + if readfile(reference) == readfile(testfile) + call delete(testfile) + break + endif + if i == 100 + " Leave the test file around for inspection. + call assert_report('See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")') + break + endif + sleep 10m + let i += 1 + endwhile + endfunc *** ../vim-8.0.1525/src/testdir/dumps/Test_syntax_c_01.dump 1970-01-01 01:00:00.000000000 +0100 --- src/testdir/dumps/Test_syntax_c_01.dump 2018-02-20 15:07:13.990249310 +0100 *************** *** 0 **** --- 1,20 ---- + |/+0#0000e05#ffffff16|*| |c|o|m@1|e|n|t| |l|i|n|e| |a|t| |t|h|e| |t|o|p| |*|/| +0#0000001&@45 + | @1|i+0#00e0003&|n|t| +0#0000001&@69 + |m|a|i|n|(|i+0#00e0003&|n|t| +0#0000001&|a|r|g|c|,| |c+0#00e0003&|h|a|r| +0#0000001&|*@1|a|r|g|v|)|/+0#0000e05&@1| |a|n|o|t|h|e|r| |c|o|m@1|e|n|t| +0#0000001&@29 + |{| @73 + |#+0#e000e06&|i|f| |0| +0#0000001&@69 + | +0#0000e05&@2|i|n|t| @2|n|o|t|_|u|s|e|d|;| +0#0000001&@56 + |#+0#e000e06&|e|l|s|e| +0#0000001&@69 + | @2|i+0#00e0003&|n|t| +0#0000001&@2|u|s|e|d|;| @60 + |#+0#e000e06&|e|n|d|i|f| +0#0000001&@68 + | @2|p|r|i|n|t|f|(|"+0#e000002&|J|u|s|t| |a|n| |e|x|a|m|p|l|e| |p|i|e|c|e| |o|f| |C| |c|o|d|e|\+0#e000e06&|n|"+0#e000002&|)+0#0000001&|;| @27 + | @2|r+0#af5f00255&|e|t|u|r|n| +0#0000001&|0+0#e000002&|x|0|f@1|;+0#0000001&| @58 + |}| @73 + | @2|s+0#00e0003&|t|a|t|i|c| +0#0000001&|v+0#00e0003&|o|i|d| +0#0000001&@60 + |m|y|F|u|n|c|t|i|o|n|(|c+0#00e0003&|o|n|s|t| +0#0000001&|d+0#00e0003&|o|u|b|l|e| +0#0000001&|c|o|u|n|t|,| |s+0#00e0003&|t|r|u|c|t| +0#0000001&|n|o|t|h|i|n|g|,| |l+0#00e0003&|o|n|g| +0#0000001&|t|h|e|r|e|)| |{| @14 + | @1|/+0#0000e05&@1| |1+0#e000002&|2|3|:+0#0000e05&| |n|o|t|h|i|n|g| |t|o| |r|e|a|d| |h|e|r|e| +0#0000001&@44 + | @1|f+0#af5f00255&|o|r| +0#0000001&|(|i+0#00e0003&|n|t| +0#0000001&|i| |=| |0+0#e000002&|;+0#0000001&| |i| |<| |c|o|u|n|t|;| |+@1|i|)| |{| @39 + | @3|b+0#af5f00255&|r|e|a|k|;+0#0000001&| @64 + | @1|}| @71 + |}| @73 + |"|X|t|e|s|t|.|c|"| |1|9|L|,| |3|6|4|C| @37|1|,|1| @10|A|l@1| *** ../vim-8.0.1525/runtime/doc/terminal.txt 2017-11-21 18:11:23.653015937 +0100 --- runtime/doc/terminal.txt 2018-02-20 15:23:28.291652069 +0100 *************** *** 1,4 **** ! *terminal.txt* For Vim version 8.0. Last change: 2017 Nov 17 VIM REFERENCE MANUAL by Bram Moolenaar --- 1,4 ---- ! *terminal.txt* For Vim version 8.0. Last change: 2018 Feb 20 VIM REFERENCE MANUAL by Bram Moolenaar *************** *** 14,38 **** If the result is "1" you have it. ! 1. Basic use |terminal-use| ! Typing |terminal-typing| ! Size and color |terminal-size-color| ! Syntax |:terminal| ! Resizing |terminal-resizing| ! Terminal Modes |Terminal-mode| ! Cursor style |terminal-cursor-style| ! Special keys |terminal-special-keys| ! Unix |terminal-unix| ! MS-Windows |terminal-ms-windows| ! 2. Remote testing |terminal-testing| ! 3. Debugging |terminal-debug| ! Starting |termdebug-starting| ! Example session |termdebug-example| ! Stepping through code |termdebug-stepping| ! Inspecting variables |termdebug-variables| ! Other commands |termdebug-commands| ! Communication |termdebug-communication| ! Customizing |termdebug-customizing| {Vi does not have any of these commands} {only available when compiled with the |+terminal| feature} --- 14,42 ---- If the result is "1" you have it. ! 1. Basic use |terminal-use| ! Typing |terminal-typing| ! Size and color |terminal-size-color| ! Syntax |:terminal| ! Resizing |terminal-resizing| ! Terminal Modes |Terminal-mode| ! Cursor style |terminal-cursor-style| ! Special keys |terminal-special-keys| ! Unix |terminal-unix| ! MS-Windows |terminal-ms-windows| ! 2. Remote testing |terminal-testing| ! 3. Diffing screen dumps |terminal-diff| ! Writing a screen dump test for Vim |terminal-dumptest| ! Creating a screen dump |terminal-screendump| ! Comparing screen dumps |terminal-diffscreendump| ! 4. Debugging |terminal-debug| ! Starting |termdebug-starting| ! Example session |termdebug-example| ! Stepping through code |termdebug-stepping| ! Inspecting variables |termdebug-variables| ! Other commands |termdebug-commands| ! Communication |termdebug-communication| ! Customizing |termdebug-customizing| {Vi does not have any of these commands} {only available when compiled with the |+terminal| feature} *************** *** 122,128 **** For a color terminal the 'background' option is used to decide whether the terminal window will start with a white or black background. ! To use a different color the Terminal highlight group can be used: > hi Terminal ctermbg=lightgrey ctermfg=blue guibg=lightgrey guifg=blue --- 126,133 ---- For a color terminal the 'background' option is used to decide whether the terminal window will start with a white or black background. ! To use a different color the Terminal highlight group can be used, for ! example: > hi Terminal ctermbg=lightgrey ctermfg=blue guibg=lightgrey guifg=blue *************** *** 148,158 **** keys in the terminal window. For MS-Windows see the ++eof argument below. - Two comma separated numbers are used as "rows,cols". - E.g. `:24,80gdb` opens a terminal with 24 rows and 80 - columns. However, if the terminal window spans the - Vim window with, there is no vertical split, the Vim - window width is used. *term++close* *term++open* Supported [options] are: ++close The terminal window will close --- 153,158 ---- *************** *** 167,175 **** ++hidden Open the terminal in a hidden buffer, no window will be used. ++rows={height} Use {height} for the terminal window ! height. ++cols={width} Use {width} for the terminal window ! width. ++eof={text} when using [range]: text to send after the last line was written. Cannot contain white space. A CR is --- 167,181 ---- ++hidden Open the terminal in a hidden buffer, no window will be used. ++rows={height} Use {height} for the terminal window ! height. If the terminal uses the full ! Vim height (no window above or below ! th terminal window) the command line ! height will be reduced as needed. ++cols={width} Use {width} for the terminal window ! width. If the terminal uses the full ! Vim width (no window left or right of ! the terminal window) this value is ! ignored. ++eof={text} when using [range]: text to send after the last line was written. Cannot contain white space. A CR is *************** *** 358,364 **** ============================================================================== ! 3. Debugging *terminal-debug* The Terminal debugging plugin can be used to debug a program with gdb and view the source code in a Vim window. Since this is completely contained inside --- 364,460 ---- ============================================================================== ! 3. Diffing screen dumps *terminal-diff* ! ! In some cases it can be bothersome to test that Vim displays the right ! characters on the screen. E.g. with syntax highlighting. To make this ! simpler it is possible to take a screen dump of a terminal and compare it to ! an expected screen dump. ! ! Vim uses the window size, text, color and other attributes as displayed. The ! Vim screen size, font and other properties do not matter. Therefore this ! mechanism is portable across systems. A convential screenshot would reflect ! all differences, including font size and family. ! ! ! Writing a screen dump test for Vim ~ ! *terminal-dumptest* ! For an example see the Test_syntax_c() function in ! src/testdir/test_syntax.vim. The main parts are: ! - Write a file you want to test with. This is useful for testing syntax ! highlighting. You can also start Vim with en empty buffer. ! - Run Vim in a terminal with a specific size. The default is 20 lines of 75 ! characters. This makes sure the dump is always this size. The function ! RunVimInTerminal() takes care of this. Pass it the arguments for the Vim ! command. ! - Send any commands to Vim using term_sendkeys(). For example: > ! call term_sendkeys(buf, ":echo &lines &columns\") ! - Check that the screen is now in the expected state, using ! VerifyScreenDump(). This expects the reference screen dump to be in the ! src/testdir/dumps/ directory. Pass the name without ".dump". It is ! recommended to use the name of the test function and a sequence number, so ! that we know what test is using the file. ! - Repeat sending commands and checking the state. ! - Finally stop Vim by calling StopVimInTerminal(). ! ! The first time you do this you won't have a screen dump yet. Create an empty ! file for now, e.g.: > ! touch src/testdir/dumps/Test_function_name_01.dump ! ! The test will then fail, giving you the command to compare the reference dump ! and the failed dump, e.g.: > ! call term_dumpdiff("Test_func.dump.failed", "dumps/Test_func.dump") ! ! Use this command in Vim, with the current directory set to src/testdir. ! Once you are satisfied with the test, move the failed dump in place of the ! reference: > ! :!mv Test_func.dump.failed dumps/Test_func.dump ! ! ! Creating a screen dump ~ ! *terminal-screendump* ! ! To create the screen dump, run Vim (or any other program) in a terminal and ! make it show the desired state. Then use the term_dumpwrite() function to ! create a screen dump file. For example: > ! :call term_dumpwrite(77, "mysyntax.dump") ! ! Here "77" is the buffer number of the terminal. Use `:ls!` to see it. ! ! You can view the screen dump with term_dumpload(): > ! :call term_dumpload("mysyntax.dump") ! ! To verify that Vim still shows exactly the same screen, run Vim again with ! exactly the same way to show the desired state. Then create a screen dump ! again, using a different file name: > ! :call term_dumpwrite(88, "test.dump") ! ! To assert that the files are exactly the same use assert_equalfile(): > ! call assert_equalfile("mysyntax.dump", "test.dump") ! ! If there are differences then v:errors will contain the error message. ! ! ! Comparing screen dumps ~ ! *terminal-diffscreendump* ! ! assert_equalfile() does not make it easy to see what is different. ! To spot the problem use term_dumpdiff(): > ! call term_dumpdiff("mysyntax.dump", "test.dump") ! ! This will open a window consisting of three parts: ! 1. The contents of the first dump ! 2. The difference between the first and second dump ! 3. The contents of the second dump ! ! You can usually see what differs in the second part. Use the 'ruler' to ! relate it to the postion in the first or second dump. ! ! Alternatively, press "s" to swap the first and second dump. Do this everal ! times so that you can spot the difference in the context of the text. ! ! ============================================================================== ! 4. Debugging *terminal-debug* The Terminal debugging plugin can be used to debug a program with gdb and view the source code in a Vim window. Since this is completely contained inside *************** *** 370,381 **** Load the plugin with this command: > packadd termdebug < *:Termdebug* ! To start debugging use `:TermDebug` folowed by the command name, for example: > :Termdebug vim This opens two windows: gdb window A terminal window in which "gdb vim" is executed. Here you can directly interact with gdb. The buffer name is "!gdb". program window A terminal window for the executed program. When "run" is used in gdb the program I/O will happen in this window, so that it does not interfere with controlling gdb. The buffer --- 466,479 ---- Load the plugin with this command: > packadd termdebug < *:Termdebug* ! To start debugging use `:Termdebug` followed by the command name, for example: > :Termdebug vim This opens two windows: + gdb window A terminal window in which "gdb vim" is executed. Here you can directly interact with gdb. The buffer name is "!gdb". + program window A terminal window for the executed program. When "run" is used in gdb the program I/O will happen in this window, so that it does not interfere with controlling gdb. The buffer *************** *** 471,489 **** :Delete delete a breakpoint at the current line :Step execute the gdb "step" command ! :Over execute the gdb "next" command (:Next is a Vim command) :Finish execute the gdb "finish" command :Continue execute the gdb "continue" command :Stop interrupt the program ! The plugin adds a window toolbar with these entries: Step :Step Next :Over Finish :Finish Cont :Continue Stop :Stop Eval :Evaluate ! This way you can use the mouse to perform the most common commands. Inspecting variables ~ --- 569,588 ---- :Delete delete a breakpoint at the current line :Step execute the gdb "step" command ! :Over execute the gdb "next" command (:Next is a Vim command) :Finish execute the gdb "finish" command :Continue execute the gdb "continue" command :Stop interrupt the program ! If 'mouse' is set the plugin adds a window toolbar with these entries: Step :Step Next :Over Finish :Finish Cont :Continue Stop :Stop Eval :Evaluate ! This way you can use the mouse to perform the most common commands. You need ! to have the 'mouse' option set to enable mouse clicks. Inspecting variables ~ *************** *** 520,525 **** --- 619,625 ---- Undefined command: "new-ui". Try "help".~ Then your gdb is too old. + *hl-debugPC* *hl-debugBreakpoint* The color of the signs can be adjusted with these highlight groups: - debugPC the current position - debugBreakpoint a breakpoint *** ../vim-8.0.1525/src/testdir/README.txt 2017-01-10 13:51:05.587236267 +0100 --- src/testdir/README.txt 2018-02-20 15:36:03.802435018 +0100 *************** *** 35,40 **** --- 35,46 ---- - See the start of runtest.vim for more help. + TO ADD A SCREEN DUMP TEST: + + Mostly the same as writing a new style test. Additonally, see help on + "terminal-dumptest". Put the reference dump in "dumps/Test_func_name.dump". + + TO ADD AN OLD STYLE TEST: 1) Create test_.in and test_.ok files. *** ../vim-8.0.1525/src/version.c 2018-02-19 23:09:57.385619337 +0100 --- src/version.c 2018-02-20 15:40:12.152715877 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1526, /**/ -- An indication you must be a manager: You can explain to somebody the difference between "re-engineering", "down-sizing", "right-sizing", and "firing people's asses". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///