Skip to content

Commit cde0ff3

Browse files
committed
patch 8.2.0509: various code is not properly tested.
Problem: various code is not properly tested. Solution: Add more tests. (Yegappan Lakshmanan, closes #5871)
1 parent d77a852 commit cde0ff3

14 files changed

Lines changed: 452 additions & 15 deletions

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ parse_command_name(mparm_T *parmp)
19661966
#endif
19671967
}
19681968

1969-
// Checking for "ex" here may catch some weir names, such as "vimex" or
1969+
// Checking for "ex" here may catch some weird names, such as "vimex" or
19701970
// "viewex", we assume the user knows that.
19711971
if (STRNICMP(initstr, "ex", 2) == 0)
19721972
{

src/testdir/check.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,13 @@ func CheckNotRoot()
133133
throw 'Skipped: cannot run test as root'
134134
endif
135135
endfunc
136+
137+
" Command to check that the current language is English
138+
command CheckEnglish call CheckEnglish()
139+
func CheckEnglish()
140+
if v:lang != "C" && v:lang !~ '^[Ee]n'
141+
throw 'Skipped: only works in English language environment'
142+
endif
143+
endfunc
144+
145+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/shared.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,5 @@ func IsRoot()
337337
endif
338338
return v:false
339339
endfunc
340+
341+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/term_util.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func RunVimInTerminal(arguments, options)
8282
let cols = term_getsize(buf)[1]
8383
endif
8484

85+
call term_wait(buf)
86+
8587
" Wait for "All" or "Top" of the ruler to be shown in the last line or in
8688
" the status line of the last window. This can be quite slow (e.g. when
8789
" using valgrind).
@@ -113,3 +115,5 @@ func StopVimInTerminal(buf)
113115
call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))})
114116
only!
115117
endfunc
118+
119+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_clientserver.vim

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ CheckFeature clientserver
66

77
source shared.vim
88

9-
func Test_client_server()
10-
let cmd = GetVimCommand()
11-
if cmd == ''
12-
return
13-
endif
9+
func Check_X11_Connection()
1410
if has('x11')
1511
if empty($DISPLAY)
1612
throw 'Skipped: $DISPLAY is not set'
@@ -19,11 +15,19 @@ func Test_client_server()
1915
call remote_send('xxx', '')
2016
catch
2117
if v:exception =~ 'E240:'
22-
throw 'Skipped: no connection to the X server'
18+
throw 'Skipped: no connection to the X server'
2319
endif
2420
" ignore other errors
2521
endtry
2622
endif
23+
endfunc
24+
25+
func Test_client_server()
26+
let cmd = GetVimCommand()
27+
if cmd == ''
28+
return
29+
endif
30+
call Check_X11_Connection()
2731

2832
let name = 'XVIMTEST'
2933
let cmd .= ' --servername ' . name
@@ -72,6 +76,10 @@ func Test_client_server()
7276
endif
7377
let g:testvar = 'myself'
7478
call assert_equal('myself', remote_expr(v:servername, 'testvar'))
79+
call remote_send(v:servername, ":let g:testvar2 = 75\<CR>")
80+
call feedkeys('', 'x')
81+
call assert_equal(75, g:testvar2)
82+
call assert_fails('let v = remote_expr(v:servername, "/2")', 'E449:')
7583

7684
call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
7785
call assert_equal('got it', g:myserverid->remote_read(2))
@@ -92,6 +100,55 @@ func Test_client_server()
92100
call assert_equal('another', g:peek_result)
93101
call assert_equal('another', remote_read(g:myserverid, 2))
94102

103+
if !has('gui_running')
104+
" In GUI vim, the following tests display a dialog box
105+
106+
let cmd = GetVimProg() .. ' --servername ' .. name
107+
108+
" Run a separate instance to send a command to the server
109+
call remote_expr(name, 'execute("only")')
110+
call system(cmd .. ' --remote-send ":new Xfile<CR>"')
111+
call assert_equal('2', remote_expr(name, 'winnr("$")'))
112+
call assert_equal('Xfile', remote_expr(name, 'winbufnr(1)->bufname()'))
113+
call remote_expr(name, 'execute("only")')
114+
115+
" Invoke a remote-expr. On MS-Windows, the returned value has a carriage
116+
" return.
117+
let l = system(cmd .. ' --remote-expr "2 + 2"')
118+
call assert_equal(['4'], split(l, "\n"))
119+
120+
" Edit multiple files using --remote
121+
call system(cmd .. ' --remote Xfile1 Xfile2 Xfile3')
122+
call assert_equal("Xfile1\nXfile2\nXfile3\n", remote_expr(name, 'argv()'))
123+
eval name->remote_send(":%bw!\<CR>")
124+
125+
" Edit files in separate tab pages
126+
call system(cmd .. ' --remote-tab Xfile1 Xfile2 Xfile3')
127+
call assert_equal('3', remote_expr(name, 'tabpagenr("$")'))
128+
call assert_equal('Xfile2', remote_expr(name, 'bufname(tabpagebuflist(2)[0])'))
129+
eval name->remote_send(":%bw!\<CR>")
130+
131+
" Edit a file using --remote-wait
132+
eval name->remote_send(":source $VIMRUNTIME/plugin/rrhelper.vim\<CR>")
133+
call system(cmd .. ' --remote-wait +enew Xfile1')
134+
call assert_equal("Xfile1", remote_expr(name, 'bufname("#")'))
135+
eval name->remote_send(":%bw!\<CR>")
136+
137+
" Edit files using --remote-tab-wait
138+
call system(cmd .. ' --remote-tabwait +tabonly\|enew Xfile1 Xfile2')
139+
call assert_equal('1', remote_expr(name, 'tabpagenr("$")'))
140+
eval name->remote_send(":%bw!\<CR>")
141+
142+
" Error cases
143+
if v:lang == "C" || v:lang =~ '^[Ee]n'
144+
let l = split(system(cmd .. ' --remote +pwd'), "\n")
145+
call assert_equal("Argument missing after: \"+pwd\"", l[1])
146+
endif
147+
let l = system(cmd .. ' --remote-expr "abcd"')
148+
call assert_match('^E449: ', l)
149+
endif
150+
151+
eval name->remote_send(":%bw!\<CR>")
95152
eval name->remote_send(":qa!\<CR>")
96153
try
97154
call WaitForAssert({-> assert_equal("dead", job_status(job))})
@@ -102,8 +159,8 @@ func Test_client_server()
102159
endif
103160
endtry
104161

105-
call assert_fails("let x=remote_peek([])", 'E730:')
106-
call assert_fails("let x=remote_read('vim10')", 'E277:')
162+
call assert_fails("let x = remote_peek([])", 'E730:')
163+
call assert_fails("let x = remote_read('vim10')", 'E277:')
107164
endfunc
108165

109166
" Uncomment this line to get a debugging log

src/testdir/test_ex_mode.vim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ endfunc
146146
" In Ex-mode, backslashes at the end of a command should be halved.
147147
func Test_Ex_echo_backslash()
148148
" This test works only when the language is English
149-
if v:lang != "C" && v:lang !~ '^[Ee]n'
150-
return
151-
endif
149+
CheckEnglish
152150
let bsl = '\\\\'
153151
let bsl2 = '\\\'
154152
call assert_fails('call feedkeys("Qecho " .. bsl .. "\nvisual\n", "xt")',

src/testdir/test_expand.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ func Test_expandcmd()
8484
let $FOO="blue\tsky"
8585
call setline(1, "$FOO")
8686
call assert_equal("grep pat blue\tsky", expandcmd('grep pat <cfile>'))
87+
88+
" Test for expression expansion `=
89+
let $FOO= "blue"
90+
call assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`"))
91+
92+
" Test for env variable with spaces
93+
let $FOO= "foo bar baz"
94+
call assert_equal("e foo bar baz", expandcmd("e $FOO"))
95+
8796
unlet $FOO
8897
close!
8998
endfunc

src/testdir/test_functions.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ func Save_mode()
659659
return ''
660660
endfunc
661661

662+
" Test for the mode() function
662663
func Test_mode()
663664
new
664665
call append(0, ["Blue Ball Black", "Brown Band Bowl", ""])
@@ -782,6 +783,8 @@ func Test_mode()
782783
call assert_equal('c-c', g:current_modes)
783784
call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt')
784785
call assert_equal('c-cv', g:current_modes)
786+
call feedkeys("Qcall Save_mode()\<CR>vi\<CR>", 'xt')
787+
call assert_equal('c-ce', g:current_modes)
785788
" How to test Ex mode?
786789

787790
bwipe!
@@ -1284,6 +1287,19 @@ func Test_inputlist()
12841287
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx')
12851288
call assert_equal(3, c)
12861289

1290+
" Use backspace to delete characters in the prompt
1291+
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<BS>3\<BS>2\<cr>", 'tx')
1292+
call assert_equal(2, c)
1293+
1294+
" Use mouse to make a selection
1295+
call test_setmouse(&lines - 3, 2)
1296+
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx')
1297+
call assert_equal(1, c)
1298+
" Mouse click outside of the list
1299+
call test_setmouse(&lines - 6, 2)
1300+
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx')
1301+
call assert_equal(-2, c)
1302+
12871303
call assert_fails('call inputlist("")', 'E686:')
12881304
endfunc
12891305

src/testdir/test_options.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
" Test for options
22

33
source check.vim
4+
source view_util.vim
45

56
func Test_whichwrap()
67
set whichwrap=b,s
@@ -707,4 +708,12 @@ func Test_rightleftcmd()
707708
set rightleft&
708709
endfunc
709710

711+
" Test for the "debug" option
712+
func Test_debug_option()
713+
set debug=beep
714+
exe "normal \<C-c>"
715+
call assert_equal('Beep!', Screenline(&lines))
716+
set debug&
717+
endfunc
718+
710719
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)