annotate src/testdir/screendump.vim @ 14019:dc67449d648c v8.1.0027

patch 8.1.0027: difficult to make a plugin that feeds a line to a job commit https://github.com/vim/vim/commit/f273245f6433d5d43a5671306b520a3230c35787 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 3 14:47:35 2018 +0200 patch 8.1.0027: difficult to make a plugin that feeds a line to a job Problem: Difficult to make a plugin that feeds a line to a job. Solution: Add the nitial code for the "prompt" buftype.
author Christian Brabandt <cb@256bit.org>
date Sun, 03 Jun 2018 15:00:07 +0200
parents f22db93bd887
children eb5ee7479d31
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Functions shared by tests making screen dumps.
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Only load this script once.
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
4 if exists('*CanRunVimInTerminal')
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 finish
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endif
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
8 " For most tests we need to be able to run terminal Vim with 256 colors. On
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
9 " MS-Windows the console only has 16 colors and the GUI can't run in a
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
10 " terminal.
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
11 func CanRunVimInTerminal()
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
12 return has('terminal') && !has('win32')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
13 endfunc
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
14
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
15 " Skip the rest if there is no terminal feature at all.
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
16 if !has('terminal')
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
17 finish
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
18 endif
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
19
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 source shared.vim
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 " Run Vim with "arguments" in a new terminal window.
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 " By default uses a size of 20 lines and 75 columns.
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 " Returns the buffer number of the terminal.
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 "
13541
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
26 " Options is a dictionary, these items are recognized:
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
27 " "rows" - height of the terminal window (max. 20)
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
28 " "cols" - width of the terminal window (max. 78)
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 func RunVimInTerminal(arguments, options)
13515
eb960e9c75c8 patch 8.0.1631: testing with Vim running in terminal is a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
30 " If Vim doesn't exit a swap file remains, causing other tests to fail.
eb960e9c75c8 patch 8.0.1631: testing with Vim running in terminal is a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
31 " Remove it here.
eb960e9c75c8 patch 8.0.1631: testing with Vim running in terminal is a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
32 call delete(".swp")
eb960e9c75c8 patch 8.0.1631: testing with Vim running in terminal is a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
33
13529
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
34 if exists('$COLORFGBG')
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
35 " Clear $COLORFGBG to avoid 'background' being set to "dark", which will
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
36 " only be corrected if the response to t_RB is received, which may be too
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
37 " late.
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
38 let $COLORFGBG = ''
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
39 endif
f5655d70484f patch 8.0.1638: popup test fails depending on environment variable
Christian Brabandt <cb@256bit.org>
parents: 13515
diff changeset
40
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 " Make a horizontal and vertical split, so that we can get exactly the right
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13529
diff changeset
42 " size terminal window. Works only when the current window is full width.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13529
diff changeset
43 call assert_equal(&columns, winwidth(0))
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 split
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 vsplit
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
13322
0dc2e4998a15 patch 8.0.1535: C syntax test still fails when using gvim
Christian Brabandt <cb@256bit.org>
parents: 13320
diff changeset
47 " Always do this with 256 colors and a light background.
0dc2e4998a15 patch 8.0.1535: C syntax test still fails when using gvim
Christian Brabandt <cb@256bit.org>
parents: 13320
diff changeset
48 set t_Co=256 background=light
0dc2e4998a15 patch 8.0.1535: C syntax test still fails when using gvim
Christian Brabandt <cb@256bit.org>
parents: 13320
diff changeset
49 hi Normal ctermfg=NONE ctermbg=NONE
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50
13541
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
51 " Make the window 20 lines high and 75 columns, unless told otherwise.
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
52 let rows = get(a:options, 'rows', 20)
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
53 let cols = get(a:options, 'cols', 75)
13537
3fa880445c99 patch 8.0.1642: running Vim in terminal fails with two windows
Christian Brabandt <cb@256bit.org>
parents: 13535
diff changeset
54
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 let cmd = GetVimCommandClean()
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
56
13320
a90063ec1cd6 patch 8.0.1534: C syntax test fails when using gvim
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
57 " Add -v to have gvim run in the terminal (if possible)
a90063ec1cd6 patch 8.0.1534: C syntax test fails when using gvim
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
58 let cmd .= ' -v ' . a:arguments
13541
296d02b0637f patch 8.0.1644: terminal API tests still fail
Christian Brabandt <cb@256bit.org>
parents: 13537
diff changeset
59 let buf = term_start(cmd, {'curwin': 1, 'term_rows': rows, 'term_cols': cols})
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13798
diff changeset
60 if &termwinsize == ''
13698
404b89cb1e2a patch 8.0.1721: no test for using the 'termsize' option
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
61 call assert_equal([rows, cols], term_getsize(buf))
404b89cb1e2a patch 8.0.1721: no test for using the 'termsize' option
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
62 else
404b89cb1e2a patch 8.0.1721: no test for using the 'termsize' option
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
63 let rows = term_getsize(buf)[0]
404b89cb1e2a patch 8.0.1721: no test for using the 'termsize' option
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
64 let cols = term_getsize(buf)[1]
404b89cb1e2a patch 8.0.1721: no test for using the 'termsize' option
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
65 endif
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
67 " Wait for "All" or "Top" of the ruler to be shown in the last line or in
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
68 " the status line of the last window. This can be quite slow (e.g. when
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
69 " using valgrind).
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
70 " If it fails then show the terminal contents for debugging.
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
71 try
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
72 call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - 1)) >= cols - 1})
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
73 catch /timed out after/
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
74 let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
75 call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
76 endtry
13559
af68603e213d patch 8.0.1653: screen dump is made too soon
Christian Brabandt <cb@256bit.org>
parents: 13541
diff changeset
77
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 return buf
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 endfunc
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 " Stop a Vim running in terminal buffer "buf".
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 func StopVimInTerminal(buf)
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 call assert_equal("running", term_getstatus(a:buf))
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 13845
diff changeset
84 call term_sendkeys(a:buf, "\<Esc>:qa!\<cr>")
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13698
diff changeset
85 call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))})
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 only!
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 endfunc
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 " Verify that Vim running in terminal buffer "buf" matches the screen dump.
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
90 " "options" is passed to term_dumpwrite().
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 " The file name used is "dumps/{filename}.dump".
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 " Will wait for up to a second for the screen dump to match.
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
93 func VerifyScreenDump(buf, filename, options)
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 let reference = 'dumps/' . a:filename . '.dump'
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 let testfile = a:filename . '.dump.failed'
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 let i = 0
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 while 1
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call delete(testfile)
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13322
diff changeset
100 call term_dumpwrite(a:buf, testfile, a:options)
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 if readfile(reference) == readfile(testfile)
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 call delete(testfile)
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 break
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 endif
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 if i == 100
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 " Leave the test file around for inspection.
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 call assert_report('See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")')
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 break
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 endif
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 sleep 10m
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 let i += 1
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 endwhile
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 endfunc