test_startup.vim 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. " Tests for startup.
  2. source shared.vim
  3. source screendump.vim
  4. source term_util.vim
  5. source check.vim
  6. " Check that loading startup.vim works.
  7. func Test_startup_script()
  8. throw 'skipped: Nvim does not need defaults.vim'
  9. set compatible
  10. source $VIMRUNTIME/defaults.vim
  11. call assert_equal(0, &compatible)
  12. " Restore some options, so that the following tests doesn't break
  13. set nomore
  14. set noshowmode
  15. endfunc
  16. " Verify the order in which plugins are loaded:
  17. " 1. plugins in non-after directories
  18. " 2. packages
  19. " 3. plugins in after directories
  20. func Test_after_comes_later()
  21. if !has('packages')
  22. return
  23. endif
  24. let before =<< trim [CODE]
  25. set nocp viminfo+=nviminfo
  26. set guioptions+=M
  27. let $HOME = "/does/not/exist"
  28. set loadplugins
  29. set rtp=Xhere,Xdir/after,Xanother
  30. set packpath=Xhere,Xdir/after
  31. set nomore
  32. let g:sequence = ""
  33. [CODE]
  34. let after =<< trim [CODE]
  35. redir! > Xtestout
  36. scriptnames
  37. redir END
  38. redir! > Xsequence
  39. echo g:sequence
  40. redir END
  41. quit
  42. [CODE]
  43. call mkdir('Xhere/plugin', 'p')
  44. call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
  45. call mkdir('Xanother/plugin', 'p')
  46. call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
  47. call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
  48. call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
  49. call mkdir('Xdir/after/plugin', 'p')
  50. call writefile(['let g:sequence .= "after "'], 'Xdir/after/plugin/later.vim')
  51. if RunVim(before, after, '')
  52. let lines = readfile('Xtestout')
  53. let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
  54. let found = []
  55. for line in lines
  56. for one in expected
  57. if line =~ one
  58. call add(found, one)
  59. endif
  60. endfor
  61. endfor
  62. call assert_equal(expected, found)
  63. endif
  64. call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
  65. call delete('Xtestout')
  66. call delete('Xsequence')
  67. call delete('Xhere', 'rf')
  68. call delete('Xanother', 'rf')
  69. call delete('Xdir', 'rf')
  70. endfunc
  71. func Test_pack_in_rtp_when_plugins_run()
  72. if !has('packages')
  73. return
  74. endif
  75. let before =<< trim [CODE]
  76. set nocp viminfo+=nviminfo
  77. set guioptions+=M
  78. let $HOME = "/does/not/exist"
  79. set loadplugins
  80. set rtp=Xhere
  81. set packpath=Xhere
  82. set nomore
  83. [CODE]
  84. let after = [
  85. \ 'quit',
  86. \ ]
  87. call mkdir('Xhere/plugin', 'p')
  88. call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
  89. call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
  90. call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
  91. if RunVim(before, after, '')
  92. let lines = filter(readfile('Xtestout'), '!empty(v:val)')
  93. call assert_match('runtimepath=Xhere', get(lines, 0))
  94. call assert_match('autoloaded foo', get(lines, 1))
  95. endif
  96. call delete('Xtestout')
  97. call delete('Xhere', 'rf')
  98. endfunc
  99. func Test_help_arg()
  100. " This does not work with a GUI-only binary, such as on MS-Windows.
  101. CheckAnyOf Unix NotGui
  102. if RunVim([], [], '--help >Xtestout')
  103. let lines = readfile('Xtestout')
  104. call assert_true(len(lines) > 20)
  105. call assert_match('Usage:', lines[0])
  106. " check if couple of lines are there
  107. let found = []
  108. for line in lines
  109. if line =~ '-l.*Execute Lua'
  110. call add(found, 'Execute Lua')
  111. endif
  112. " Watch out for a second --version line in the Gnome version.
  113. if line =~ '--version.*Print version information'
  114. call add(found, "--version")
  115. endif
  116. endfor
  117. call assert_equal(['Execute Lua', '--version'], found)
  118. endif
  119. call delete('Xtestout')
  120. endfunc
  121. func Test_compatible_args()
  122. throw "skipped: Nvim is always 'nocompatible'"
  123. let after =<< trim [CODE]
  124. call writefile([string(&compatible)], "Xtestout")
  125. set viminfo+=nviminfo
  126. quit
  127. [CODE]
  128. if RunVim([], after, '-C')
  129. let lines = readfile('Xtestout')
  130. call assert_equal('1', lines[0])
  131. endif
  132. if RunVim([], after, '-N')
  133. let lines = readfile('Xtestout')
  134. call assert_equal('0', lines[0])
  135. endif
  136. call delete('Xtestout')
  137. endfunc
  138. " Test the -o[N] and -O[N] arguments to open N windows split
  139. " horizontally or vertically.
  140. func Test_o_arg()
  141. let after =<< trim [CODE]
  142. set cpo&vim
  143. call writefile([winnr("$"),
  144. \ winheight(1), winheight(2), &lines,
  145. \ winwidth(1), winwidth(2), &columns,
  146. \ bufname(winbufnr(1)), bufname(winbufnr(2))],
  147. \ "Xtestout")
  148. qall
  149. [CODE]
  150. if RunVim([], after, '-o2')
  151. " Open 2 windows split horizontally. Expect:
  152. " - 2 windows
  153. " - both windows should have the same or almost the same height
  154. " - sum of both windows height (+ 3 for both statusline and Ex command)
  155. " should be equal to the number of lines
  156. " - both windows should have the same width which should be equal to the
  157. " number of columns
  158. " - buffer of both windows should have no name
  159. let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
  160. call assert_equal('2', wn)
  161. call assert_inrange(0, 1, wh1 - wh2)
  162. call assert_equal(string(wh1 + wh2 + 3), ln)
  163. call assert_equal(ww1, ww2)
  164. call assert_equal(ww1, cn)
  165. call assert_equal('', bn1)
  166. call assert_equal('', bn2)
  167. endif
  168. if RunVim([], after, '-o foo bar')
  169. " Same expectations as for -o2 but buffer names should be foo and bar
  170. let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
  171. call assert_equal('2', wn)
  172. call assert_inrange(0, 1, wh1 - wh2)
  173. call assert_equal(string(wh1 + wh2 + 3), ln)
  174. call assert_equal(ww1, ww2)
  175. call assert_equal(ww1, cn)
  176. call assert_equal('foo', bn1)
  177. call assert_equal('bar', bn2)
  178. endif
  179. if RunVim([], after, '-O2')
  180. " Open 2 windows split vertically. Expect:
  181. " - 2 windows
  182. " - both windows should have the same or almost the same width
  183. " - sum of both windows width (+ 1 for the separator) should be equal to
  184. " the number of columns
  185. " - both windows should have the same height
  186. " - window height (+ 2 for the statusline and Ex command) should be equal
  187. " to the number of lines
  188. " - buffer of both windows should have no name
  189. let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
  190. call assert_equal('2', wn)
  191. call assert_inrange(0, 1, ww1 - ww2)
  192. call assert_equal(string(ww1 + ww2 + 1), cn)
  193. call assert_equal(wh1, wh2)
  194. call assert_equal(string(wh1 + 2), ln)
  195. call assert_equal('', bn1)
  196. call assert_equal('', bn2)
  197. endif
  198. if RunVim([], after, '-O foo bar')
  199. " Same expectations as for -O2 but buffer names should be foo and bar
  200. let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout')
  201. call assert_equal('2', wn)
  202. call assert_inrange(0, 1, ww1 - ww2)
  203. call assert_equal(string(ww1 + ww2 + 1), cn)
  204. call assert_equal(wh1, wh2)
  205. call assert_equal(string(wh1 + 2), ln)
  206. call assert_equal('foo', bn1)
  207. call assert_equal('bar', bn2)
  208. endif
  209. call delete('Xtestout')
  210. endfunc
  211. " Test the -p[N] argument to open N tabpages.
  212. func Test_p_arg()
  213. let after =<< trim [CODE]
  214. call writefile(split(execute("tabs"), "\n"), "Xtestout")
  215. qall
  216. [CODE]
  217. if RunVim([], after, '-p2')
  218. let lines = readfile('Xtestout')
  219. call assert_equal(4, len(lines))
  220. call assert_equal('Tab page 1', lines[0])
  221. call assert_equal('> [No Name]', lines[1])
  222. call assert_equal('Tab page 2', lines[2])
  223. call assert_equal('# [No Name]', lines[3])
  224. endif
  225. if RunVim([], after, '-p foo bar')
  226. let lines = readfile('Xtestout')
  227. call assert_equal(4, len(lines))
  228. call assert_equal('Tab page 1', lines[0])
  229. call assert_equal('> foo', lines[1])
  230. call assert_equal('Tab page 2', lines[2])
  231. call assert_equal('# bar', lines[3])
  232. endif
  233. call delete('Xtestout')
  234. endfunc
  235. " Test the -V[N] argument to set the 'verbose' option to [N]
  236. func Test_V_arg()
  237. " Can't catch the output of gvim.
  238. CheckNotGui
  239. let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
  240. call assert_equal(" verbose=0\n", out)
  241. let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq')
  242. " call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline \\d\\+: sourcing \"[^\"]*runtime[\\/]filetype\.vim\".*\n", out)
  243. call assert_match(" verbose=2\n", out)
  244. let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq')
  245. " call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out)
  246. endfunc
  247. " Test the '-q [errorfile]' argument.
  248. func Test_q_arg()
  249. CheckFeature quickfix
  250. let lines =<< trim END
  251. /* some file with an error */
  252. main() {
  253. functionCall(arg; arg, arg);
  254. return 666
  255. }
  256. END
  257. call writefile(lines, 'Xbadfile.c')
  258. let after =<< trim [CODE]
  259. call writefile([&errorfile, string(getpos("."))], "XtestoutQarg")
  260. copen
  261. w >> XtestoutQarg
  262. qall
  263. [CODE]
  264. " Test with default argument '-q'.
  265. call assert_equal('errors.err', &errorfile)
  266. call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'errors.err')
  267. if RunVim([], after, '-q')
  268. let lines = readfile('XtestoutQarg')
  269. call assert_equal(['errors.err',
  270. \ '[0, 4, 12, 0]',
  271. \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
  272. \ lines)
  273. endif
  274. call delete('XtestoutQarg')
  275. call delete('errors.err')
  276. " Test with explicit argument '-q XerrorsQarg' (with space).
  277. call writefile(["Xbadfile.c:4:12: error: expected ';' before '}' token"], 'XerrorsQarg')
  278. if RunVim([], after, '-q XerrorsQarg')
  279. let lines = readfile('XtestoutQarg')
  280. call assert_equal(['XerrorsQarg',
  281. \ '[0, 4, 12, 0]',
  282. \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
  283. \ lines)
  284. endif
  285. call delete('XtestoutQarg')
  286. " Test with explicit argument '-qXerrorsQarg' (without space).
  287. if RunVim([], after, '-qXerrorsQarg')
  288. let lines = readfile('XtestoutQarg')
  289. call assert_equal(['XerrorsQarg',
  290. \ '[0, 4, 12, 0]',
  291. \ "Xbadfile.c|4 col 12| error: expected ';' before '}' token"],
  292. \ lines)
  293. endif
  294. " Test with a non-existing error file (exits with value 3)
  295. let out = system(GetVimCommand() .. ' -q xyz.err')
  296. call assert_equal(3, v:shell_error)
  297. call delete('Xbadfile.c')
  298. call delete('XtestoutQarg')
  299. call delete('XerrorsQarg')
  300. endfunc
  301. " Test the -V[N]{filename} argument to set the 'verbose' option to N
  302. " and set 'verbosefile' to filename.
  303. func Test_V_file_arg()
  304. if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq')
  305. let out = join(readfile('Xverbosefile'), "\n")
  306. " call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out)
  307. call assert_match("\n verbose=2\n", out)
  308. call assert_match("\n verbosefile=Xverbosefile", out)
  309. endif
  310. call delete('Xverbosefile')
  311. endfunc
  312. " Test the -m, -M and -R arguments:
  313. " -m resets 'write'
  314. " -M resets 'modifiable' and 'write'
  315. " -R sets 'readonly'
  316. func Test_m_M_R()
  317. let after =<< trim [CODE]
  318. call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")
  319. qall
  320. [CODE]
  321. if RunVim([], after, '')
  322. let lines = readfile('Xtestout')
  323. call assert_equal(['1', '1', '0', '200'], lines)
  324. endif
  325. if RunVim([], after, '-m')
  326. let lines = readfile('Xtestout')
  327. call assert_equal(['0', '1', '0', '200'], lines)
  328. endif
  329. if RunVim([], after, '-M')
  330. let lines = readfile('Xtestout')
  331. call assert_equal(['0', '0', '0', '200'], lines)
  332. endif
  333. if RunVim([], after, '-R')
  334. let lines = readfile('Xtestout')
  335. call assert_equal(['1', '1', '1', '10000'], lines)
  336. endif
  337. call delete('Xtestout')
  338. endfunc
  339. " Test the -A and -H arguments (Arabic and Hebrew modes).
  340. func Test_A_H_arg()
  341. let after =<< trim [CODE]
  342. call writefile([&rightleft, &arabic, 0, &hkmap, &keymap], "Xtestout")
  343. qall
  344. [CODE]
  345. " Use silent Ex mode to avoid the hit-Enter prompt for the warning that
  346. " 'encoding' is not utf-8.
  347. if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A')
  348. let lines = readfile('Xtestout')
  349. call assert_equal(['1', '1', '0', '0', 'arabic'], lines)
  350. endif
  351. if has('rightleft') && RunVim([], after, '-H')
  352. let lines = readfile('Xtestout')
  353. call assert_equal(['1', '0', '0', '0', 'hebrew'], lines)
  354. endif
  355. call delete('Xtestout')
  356. endfunc
  357. " Test the --echo-wid argument (for GTK GUI only).
  358. func Test_echo_wid()
  359. CheckCanRunGui
  360. CheckFeature gui_gtk
  361. if RunVim([], [], '-g --echo-wid -cq >Xtest_echo_wid')
  362. let lines = readfile('Xtest_echo_wid')
  363. call assert_equal(1, len(lines))
  364. call assert_match('^WID: \d\+$', lines[0])
  365. endif
  366. call delete('Xtest_echo_wid')
  367. endfunction
  368. " Test the -reverse and +reverse arguments (for GUI only).
  369. func Test_reverse()
  370. CheckCanRunGui
  371. CheckAnyOf Feature:gui_gtk Feature:gui_motif
  372. let after =<< trim [CODE]
  373. call writefile([&background], "Xtest_reverse")
  374. qall
  375. [CODE]
  376. if RunVim([], after, '-f -g -reverse')
  377. let lines = readfile('Xtest_reverse')
  378. call assert_equal(['dark'], lines)
  379. endif
  380. if RunVim([], after, '-f -g +reverse')
  381. let lines = readfile('Xtest_reverse')
  382. call assert_equal(['light'], lines)
  383. endif
  384. call delete('Xtest_reverse')
  385. endfunc
  386. " Test the -background and -foreground arguments (for GUI only).
  387. func Test_background_foreground()
  388. CheckCanRunGui
  389. CheckAnyOf Feature:gui_gtk Feature:gui_motif
  390. " Is there a better way to check the effect of -background & -foreground
  391. " other than merely looking at &background (dark or light)?
  392. let after =<< trim [CODE]
  393. call writefile([&background], "Xtest_fg_bg")
  394. qall
  395. [CODE]
  396. if RunVim([], after, '-f -g -background darkred -foreground yellow')
  397. let lines = readfile('Xtest_fg_bg')
  398. call assert_equal(['dark'], lines)
  399. endif
  400. if RunVim([], after, '-f -g -background ivory -foreground darkgreen')
  401. let lines = readfile('Xtest_fg_bg')
  402. call assert_equal(['light'], lines)
  403. endif
  404. call delete('Xtest_fg_bg')
  405. endfunc
  406. " Test the -font argument (for GUI only).
  407. func Test_font()
  408. CheckCanRunGui
  409. CheckNotMSWindows
  410. if has('gui_gtk')
  411. let font = 'Courier 14'
  412. elseif has('gui_motif')
  413. let font = '-misc-fixed-bold-*'
  414. else
  415. throw 'Skipped: test does not set a valid font for this GUI'
  416. endif
  417. let after =<< trim [CODE]
  418. call writefile([&guifont], "Xtest_font")
  419. qall
  420. [CODE]
  421. if RunVim([], after, '--nofork -g -font "' .. font .. '"')
  422. let lines = readfile('Xtest_font')
  423. call assert_equal([font], lines)
  424. endif
  425. call delete('Xtest_font')
  426. endfunc
  427. " Test the -geometry argument (for GUI only).
  428. func Test_geometry()
  429. CheckCanRunGui
  430. CheckAnyOf Feature:gui_gtk Feature:gui_motif
  431. if has('gui_motif')
  432. " FIXME: With GUI Motif the value of getwinposx(),
  433. " getwinposy() and getwinpos() do not match exactly the
  434. " value given in -geometry. Why?
  435. " So only check &columns and &lines for those GUIs.
  436. let after =<< trim [CODE]
  437. call writefile([&columns, &lines], "Xtest_geometry")
  438. qall
  439. [CODE]
  440. if RunVim([], after, '-f -g -geometry 31x13+41+43')
  441. let lines = readfile('Xtest_geometry')
  442. call assert_equal(['31', '13'], lines)
  443. endif
  444. else
  445. let after =<< trim [CODE]
  446. call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
  447. qall
  448. [CODE]
  449. " Some window managers have a bar at the top that pushes windows down,
  450. " need to use at least 130, let's do 150
  451. if RunVim([], after, '-f -g -geometry 31x13+41+150')
  452. let lines = readfile('Xtest_geometry')
  453. " Depending on the GUI library and the windowing system the final size
  454. " might be a bit different, allow for some tolerance. Tuned based on
  455. " actual failures.
  456. call assert_inrange(31, 35, str2nr(lines[0]))
  457. call assert_equal('13', lines[1])
  458. call assert_equal('41', lines[2])
  459. call assert_equal('150', lines[3])
  460. call assert_equal('[41, 150]', lines[4])
  461. endif
  462. endif
  463. call delete('Xtest_geometry')
  464. endfunc
  465. " Test the -iconic argument (for GUI only).
  466. func Test_iconic()
  467. CheckCanRunGui
  468. CheckAnyOf Feature:gui_gtk Feature:gui_motif
  469. call RunVim([], [], '-f -g -iconic -cq')
  470. " TODO: currently only start vim iconified, but does not
  471. " check that vim is iconified. How could this be checked?
  472. endfunc
  473. func Test_invalid_args()
  474. " must be able to get the output of Vim.
  475. CheckUnix
  476. CheckNotGui
  477. for opt in ['-Y', '--does-not-exist']
  478. let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
  479. call assert_equal(1, v:shell_error)
  480. call assert_equal('nvim: Unknown option argument: "' .. opt .. '"', out[0])
  481. call assert_equal('More info with "nvim -h"', out[1])
  482. endfor
  483. for opt in ['-c', '-i', '-s', '-t', '-u', '-U', '-w', '-W', '--cmd', '--startuptime']
  484. let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
  485. call assert_equal(1, v:shell_error)
  486. call assert_equal('nvim: Argument missing after: "' .. opt .. '"', out[0])
  487. call assert_equal('More info with "nvim -h"', out[1])
  488. endfor
  489. if has('clientserver')
  490. for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr',
  491. \ '--remote-tab', '--remote-tab-wait',
  492. \ '--remote-tab-wait-silent', '--remote-tab-silent',
  493. \ '--remote-wait', '--remote-wait-silent',
  494. \ '--servername',
  495. \ ]
  496. let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
  497. call assert_equal(1, v:shell_error)
  498. call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
  499. call assert_equal('Argument missing after: "' .. opt .. '"', out[1])
  500. call assert_equal('More info with: "vim -h"', out[2])
  501. endfor
  502. endif
  503. if has('gui_gtk')
  504. let out = split(system(GetVimCommand() .. ' --display'), "\n")
  505. call assert_equal(1, v:shell_error)
  506. call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
  507. call assert_equal('Argument missing after: "--display"', out[1])
  508. call assert_equal('More info with: "vim -h"', out[2])
  509. endif
  510. if has('xterm_clipboard')
  511. let out = split(system(GetVimCommand() .. ' -display'), "\n")
  512. call assert_equal(1, v:shell_error)
  513. call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
  514. call assert_equal('Argument missing after: "-display"', out[1])
  515. call assert_equal('More info with: "vim -h"', out[2])
  516. endif
  517. let out = split(system(GetVimCommand() .. ' -ix'), "\n")
  518. call assert_equal(1, v:shell_error)
  519. call assert_equal('nvim: Garbage after option argument: "-ix"', out[0])
  520. call assert_equal('More info with "nvim -h"', out[1])
  521. " Not an error in Nvim. The "-" file is allowed with -t, -q, or [file].
  522. let out = split(system(GetVimCommand() .. ' - xxx -cq'), "\n")
  523. call assert_equal(0, v:shell_error)
  524. if has('quickfix')
  525. " Detect invalid repeated arguments '-t foo -t foo', '-q foo -q foo'.
  526. for opt in ['-t', '-q']
  527. let out = split(system(GetVimCommand() .. repeat(' ' .. opt .. ' foo', 2)), "\n")
  528. call assert_equal(1, v:shell_error)
  529. call assert_equal('nvim: Too many edit arguments: "' .. opt .. '"', out[0])
  530. call assert_equal('More info with "nvim -h"', out[1])
  531. endfor
  532. endif
  533. for opt in [' -cq', ' --cmd q', ' +', ' -S foo']
  534. let out = split(system(GetVimCommand() .. repeat(opt, 11)), "\n")
  535. call assert_equal(1, v:shell_error)
  536. " FIXME: The error message given by Vim is not ideal in case of repeated
  537. " -S foo since it does not mention -S.
  538. call assert_equal('nvim: Too many "+command", "-c command" or "--cmd command" arguments', out[0])
  539. call assert_equal('More info with "nvim -h"', out[1])
  540. endfor
  541. if has('gui_gtk')
  542. let out = split(system(GetVimCommand() .. ' --socketid'), "\n")
  543. call assert_equal(1, v:shell_error)
  544. call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
  545. call assert_equal('Argument missing after: "--socketid"', out[1])
  546. call assert_equal('More info with: "vim -h"', out[2])
  547. for opt in ['--socketid x', '--socketid 0xg']
  548. let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
  549. call assert_equal(1, v:shell_error)
  550. call assert_match('^VIM - Vi IMproved .* (.*)$', out[0])
  551. call assert_equal('Invalid argument for: "--socketid"', out[1])
  552. call assert_equal('More info with: "vim -h"', out[2])
  553. endfor
  554. endif
  555. endfunc
  556. func Test_file_args()
  557. let after =<< trim [CODE]
  558. call writefile(argv(), "Xtestout")
  559. qall
  560. [CODE]
  561. if RunVim([], after, '')
  562. let lines = readfile('Xtestout')
  563. call assert_equal(0, len(lines))
  564. endif
  565. if RunVim([], after, 'one')
  566. let lines = readfile('Xtestout')
  567. call assert_equal(1, len(lines))
  568. call assert_equal('one', lines[0])
  569. endif
  570. if RunVim([], after, 'one two three')
  571. let lines = readfile('Xtestout')
  572. call assert_equal(3, len(lines))
  573. call assert_equal('one', lines[0])
  574. call assert_equal('two', lines[1])
  575. call assert_equal('three', lines[2])
  576. endif
  577. if RunVim([], after, 'one -c echo two')
  578. let lines = readfile('Xtestout')
  579. call assert_equal(2, len(lines))
  580. call assert_equal('one', lines[0])
  581. call assert_equal('two', lines[1])
  582. endif
  583. if RunVim([], after, 'one -- -c echo two')
  584. let lines = readfile('Xtestout')
  585. call assert_equal(4, len(lines))
  586. call assert_equal('one', lines[0])
  587. call assert_equal('-c', lines[1])
  588. call assert_equal('echo', lines[2])
  589. call assert_equal('two', lines[3])
  590. endif
  591. call delete('Xtestout')
  592. endfunc
  593. func Test_startuptime()
  594. if !has('startuptime')
  595. return
  596. endif
  597. let after = ['qall']
  598. if RunVim([], after, '--startuptime Xtestout one')
  599. let lines = readfile('Xtestout')
  600. let expected = ['parsing arguments', 'inits 3', 'opening buffers']
  601. let found = []
  602. for line in lines
  603. for exp in expected
  604. if line =~ exp
  605. call add(found, exp)
  606. endif
  607. endfor
  608. endfor
  609. call assert_equal(expected, found)
  610. endif
  611. call delete('Xtestout')
  612. endfunc
  613. func Test_read_stdin()
  614. let after =<< trim [CODE]
  615. write Xtestout
  616. quit!
  617. [CODE]
  618. if RunVimPiped([], after, '-', 'echo something | ')
  619. let lines = readfile('Xtestout')
  620. " MS-Windows adds a space after the word
  621. call assert_equal(['something'], split(lines[0]))
  622. endif
  623. call delete('Xtestout')
  624. endfunc
  625. func Test_progpath()
  626. " Tests normally run with "./vim" or "../vim", these must have been expanded
  627. " to a full path.
  628. if has('unix')
  629. call assert_equal('/', v:progpath[0])
  630. elseif has('win32')
  631. call assert_equal(':', v:progpath[1])
  632. call assert_match('[/\\]', v:progpath[2])
  633. endif
  634. " Only expect "vim" to appear in v:progname.
  635. call assert_match('vim\c', v:progname)
  636. endfunc
  637. func Test_silent_ex_mode()
  638. " must be able to get the output of Vim.
  639. CheckUnix
  640. CheckNotGui
  641. " This caused an ml_get error.
  642. let out = system(GetVimCommand() . ' -u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
  643. call assert_notmatch('E315:', out)
  644. endfunc
  645. func Test_default_term()
  646. " must be able to get the output of Vim.
  647. CheckUnix
  648. CheckNotGui
  649. let save_term = $TERM
  650. let $TERM = 'unknownxxx'
  651. let out = system(GetVimCommand() . ' -c ''echo &term'' -c cq')
  652. call assert_match('nvim', out)
  653. let $TERM = save_term
  654. endfunc
  655. func Test_zzz_startinsert()
  656. " Test :startinsert
  657. call writefile(['123456'], 'Xtestout')
  658. let after =<< trim [CODE]
  659. :startinsert
  660. call feedkeys("foobar\<c-o>:wq\<cr>","t")
  661. [CODE]
  662. if RunVim([], after, 'Xtestout')
  663. let lines = readfile('Xtestout')
  664. call assert_equal(['foobar123456'], lines)
  665. endif
  666. " Test :startinsert!
  667. call writefile(['123456'], 'Xtestout')
  668. let after =<< trim [CODE]
  669. :startinsert!
  670. call feedkeys("foobar\<c-o>:wq\<cr>","t")
  671. [CODE]
  672. if RunVim([], after, 'Xtestout')
  673. let lines = readfile('Xtestout')
  674. call assert_equal(['123456foobar'], lines)
  675. endif
  676. call delete('Xtestout')
  677. endfunc
  678. func Test_issue_3969()
  679. " Can't catch the output of gvim.
  680. CheckNotGui
  681. " Check that message is not truncated.
  682. let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
  683. call assert_equal('hello', out)
  684. endfunc
  685. func Test_start_with_tabs()
  686. CheckRunVimInTerminal
  687. let buf = RunVimInTerminal('-p a b c', {})
  688. call VerifyScreenDump(buf, 'Test_start_with_tabs', {})
  689. " clean up
  690. call StopVimInTerminal(buf)
  691. endfunc
  692. func Test_v_argv()
  693. let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
  694. let list = split(out, "', '")
  695. call assert_match('vim', list[0])
  696. let idx = index(list, 'arg1')
  697. call assert_true(idx > 2)
  698. call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
  699. endfunc
  700. " Test for the "-r" recovery mode option
  701. func Test_r_arg()
  702. throw 'Skipped: Nvim has different directories'
  703. " Can't catch the output of gvim.
  704. CheckNotGui
  705. CheckUnix
  706. CheckEnglish
  707. let cmd = GetVimCommand()
  708. " There can be swap files anywhere, only check for the headers.
  709. let expected =<< trim END
  710. Swap files found:.*
  711. In current directory:.*
  712. In directory \~/tmp:.*
  713. In directory /var/tmp:.*
  714. In directory /tmp:.*
  715. END
  716. call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', ''))
  717. endfunc
  718. " Test for the '-t' option to jump to a tag
  719. func Test_t_arg()
  720. let before =<< trim [CODE]
  721. set tags=Xtags
  722. [CODE]
  723. let after =<< trim [CODE]
  724. let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
  725. call writefile([s], "Xtestout")
  726. qall
  727. [CODE]
  728. call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
  729. \ "first\tXfile1\t/^ \\zsfirst$/",
  730. \ "second\tXfile1\t/^ \\zssecond$/",
  731. \ "third\tXfile1\t/^ \\zsthird$/"],
  732. \ 'Xtags')
  733. call writefile([' first', ' second', ' third'], 'Xfile1')
  734. for t_arg in ['-t second', '-tsecond']
  735. if RunVim(before, after, t_arg)
  736. call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
  737. call delete('Xtestout')
  738. endif
  739. endfor
  740. call delete('Xtags')
  741. call delete('Xfile1')
  742. endfunc
  743. " Test the '-T' argument which sets the 'term' option.
  744. func Test_T_arg()
  745. throw 'skipped: Nvim does not support "-T" argument'
  746. CheckNotGui
  747. let after =<< trim [CODE]
  748. call writefile([&term], "Xtest_T_arg")
  749. qall
  750. [CODE]
  751. for t in ['builtin_dumb', 'builtin_ansi']
  752. if RunVim([], after, '-T ' .. t)
  753. let lines = readfile('Xtest_T_arg')
  754. call assert_equal([t], lines)
  755. endif
  756. endfor
  757. call delete('Xtest_T_arg')
  758. endfunc
  759. " Test the '-x' argument to read/write encrypted files.
  760. func Test_x_arg()
  761. CheckRunVimInTerminal
  762. CheckFeature cryptv
  763. " Create an encrypted file Xtest_x_arg.
  764. let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
  765. call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
  766. call term_sendkeys(buf, "foo\n")
  767. call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
  768. call term_sendkeys(buf, "foo\n")
  769. call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
  770. call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
  771. call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
  772. \ term_getline(buf, 10))})
  773. call StopVimInTerminal(buf)
  774. " Read the encrypted file and check that it contains the expected content "test"
  775. let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
  776. call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
  777. call term_sendkeys(buf, "foo\n")
  778. call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
  779. call term_sendkeys(buf, "foo\n")
  780. call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
  781. call StopVimInTerminal(buf)
  782. call delete('Xtest_x_arg')
  783. endfunc
  784. " Test for entering the insert mode on startup
  785. func Test_start_insertmode()
  786. throw "Skipped: Nvim does not support setting 'insertmode'"
  787. let before =<< trim [CODE]
  788. set insertmode
  789. [CODE]
  790. let after =<< trim [CODE]
  791. call writefile(['insertmode=' .. &insertmode], 'Xtestout')
  792. qall
  793. [CODE]
  794. if RunVim(before, after, '')
  795. call assert_equal(['insertmode=1'], readfile('Xtestout'))
  796. call delete('Xtestout')
  797. endif
  798. endfunc
  799. " Test for enabling the binary mode on startup
  800. func Test_b_arg()
  801. let after =<< trim [CODE]
  802. call writefile(['binary=' .. &binary], 'Xtestout')
  803. qall
  804. [CODE]
  805. if RunVim([], after, '-b')
  806. call assert_equal(['binary=1'], readfile('Xtestout'))
  807. call delete('Xtestout')
  808. endif
  809. endfunc
  810. " Test for enabling the lisp mode on startup
  811. func Test_l_arg()
  812. throw 'Skipped: Nvim -l arg differs from Vim'
  813. let after =<< trim [CODE]
  814. let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch
  815. call writefile([s], 'Xtestout')
  816. qall
  817. [CODE]
  818. if RunVim([], after, '-l')
  819. call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout'))
  820. call delete('Xtestout')
  821. endif
  822. endfunc
  823. " Test for specifying a non-existing vimrc file using "-u"
  824. func Test_missing_vimrc()
  825. CheckRunVimInTerminal
  826. let after =<< trim [CODE]
  827. call assert_match('^E282:', v:errmsg)
  828. call writefile(v:errors, 'Xtestout')
  829. [CODE]
  830. call writefile(after, 'Xafter')
  831. let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter'
  832. let buf = term_start(cmd, {'term_rows' : 10})
  833. call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
  834. call TermWait(buf)
  835. call term_sendkeys(buf, "\n:")
  836. call TermWait(buf)
  837. call WaitForAssert({-> assert_match(':', term_getline(buf, 10))})
  838. call StopVimInTerminal(buf)
  839. call assert_equal([], readfile('Xtestout'))
  840. call delete('Xafter')
  841. call delete('Xtestout')
  842. endfunc
  843. " Test for using the $VIMINIT environment variable
  844. func Test_VIMINIT()
  845. let after =<< trim [CODE]
  846. call assert_equal(1, exists('viminit_found'))
  847. call assert_equal('yes', viminit_found)
  848. call writefile(v:errors, 'Xtestout')
  849. qall
  850. [CODE]
  851. call writefile(after, 'Xafter')
  852. " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
  853. let cmd = GetVimProg() . ' -S Xafter --cmd "set enc=utf8"'
  854. call setenv('VIMINIT', 'let viminit_found="yes"')
  855. exe "silent !" . cmd
  856. call assert_equal([], readfile('Xtestout'))
  857. call delete('Xtestout')
  858. call delete('Xafter')
  859. endfunc
  860. " Test for using the $EXINIT environment variable
  861. func Test_EXINIT()
  862. let after =<< trim [CODE]
  863. call assert_equal(1, exists('exinit_found'))
  864. call assert_equal('yes', exinit_found)
  865. call writefile(v:errors, 'Xtestout')
  866. qall
  867. [CODE]
  868. call writefile(after, 'Xafter')
  869. " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
  870. let cmd = GetVimProg() . ' -S Xafter --cmd "set enc=utf8"'
  871. call setenv('EXINIT', 'let exinit_found="yes"')
  872. exe "silent !" . cmd
  873. call assert_equal([], readfile('Xtestout'))
  874. call delete('Xtestout')
  875. call delete('Xafter')
  876. endfunc
  877. " Test for using the 'exrc' option
  878. func Test_exrc()
  879. throw 'Skipped: Nvim requires user input for the exrc option'
  880. let after =<< trim [CODE]
  881. call assert_equal(1, &exrc)
  882. call assert_equal(1, &secure)
  883. call assert_equal(37, exrc_found)
  884. call writefile(v:errors, 'Xtestout')
  885. qall
  886. [CODE]
  887. call mkdir('Xdir')
  888. call writefile(['let exrc_found=37'], 'Xdir/.exrc')
  889. call writefile(after, 'Xdir/Xafter')
  890. " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
  891. let cmd = GetVimProg() . ' -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"'
  892. exe "silent !" . cmd
  893. call assert_equal([], readfile('Xdir/Xtestout'))
  894. call delete('Xdir', 'rf')
  895. endfunc
  896. " Test for starting Vim with a non-terminal as input/output
  897. func Test_io_not_a_terminal()
  898. throw 'Skipped: Nvim does not support --ttyfail'
  899. " Can't catch the output of gvim.
  900. CheckNotGui
  901. CheckUnix
  902. CheckEnglish
  903. let l = systemlist(GetVimProg() .. ' --ttyfail')
  904. call assert_equal(['Vim: Warning: Output is not to a terminal',
  905. \ 'Vim: Warning: Input is not from a terminal'], l)
  906. endfunc
  907. " Test for not being a term avoiding escape codes.
  908. func Test_not_a_term()
  909. CheckUnix
  910. CheckNotGui
  911. if &shellredir =~ '%s'
  912. let redir = printf(&shellredir, 'Xvimout')
  913. else
  914. let redir = &shellredir .. ' Xvimout'
  915. endif
  916. " As nvim checks the environment by itself there will be no escape sequences
  917. " This will also happen to take two (2) seconds.
  918. let cmd = GetVimProg() .. ' --cmd quit ' .. redir
  919. exe "silent !" . cmd
  920. call assert_notmatch("\e", readfile('Xvimout')->join())
  921. call delete('Xvimout')
  922. " --not-a-term flag has thus been deleted
  923. endfunc
  924. " Test for the "-w scriptout" argument
  925. func Test_w_arg()
  926. " Can't catch the output of gvim.
  927. CheckNotGui
  928. call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
  929. if RunVim([], [], '-s Xscriptin -w Xscriptout')
  930. call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
  931. call delete('Xscriptout')
  932. endif
  933. call delete('Xscriptin')
  934. " Test for failing to open the script output file. This test works only when
  935. " the language is English.
  936. if !has('win32') && (v:lang == "C" || v:lang =~ '^[Ee]n')
  937. call mkdir("Xdir")
  938. let m = system(GetVimCommand() .. " -w Xdir")
  939. call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
  940. call delete("Xdir", 'rf')
  941. endif
  942. " A number argument sets the 'window' option
  943. call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
  944. for w_arg in ['-w 17', '-w17']
  945. if RunVim([], [], '-s Xscriptin ' .. w_arg)
  946. call assert_equal(["window 17"], readfile('Xresult'), w_arg)
  947. call delete('Xresult')
  948. endif
  949. endfor
  950. call delete('Xscriptin')
  951. endfunc
  952. " Test for the "-s scriptin" argument
  953. func Test_s_arg()
  954. " Can't catch the output of gvim.
  955. CheckNotGui
  956. CheckEnglish
  957. " Test for failing to open the script input file.
  958. let m = system(GetVimCommand() .. " -s abcxyz")
  959. " call assert_equal("Cannot open for reading: \"abcxyz\"\n", m)
  960. call assert_equal("Cannot open for reading: \"abcxyz\": no such file or directory\n", m)
  961. call writefile([], 'Xinput')
  962. let m = system(GetVimCommand() .. " -s Xinput -s Xinput")
  963. call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m)
  964. call delete('Xinput')
  965. endfunc
  966. " Test for the "-n" (no swap file) argument
  967. func Test_n_arg()
  968. let after =<< trim [CODE]
  969. call assert_equal(0, &updatecount)
  970. call writefile(v:errors, 'Xtestout')
  971. qall
  972. [CODE]
  973. if RunVim([], after, '-n')
  974. call assert_equal([], readfile('Xtestout'))
  975. call delete('Xtestout')
  976. endif
  977. endfunc
  978. " Test for the "-h" (help) argument
  979. func Test_h_arg()
  980. throw 'Skipped: Nvim has different output for "-h" argument'
  981. " Can't catch the output of gvim.
  982. CheckNotGui
  983. let l = systemlist(GetVimProg() .. ' -h')
  984. call assert_match('^VIM - Vi IMproved', l[0])
  985. let l = systemlist(GetVimProg() .. ' -?')
  986. call assert_match('^VIM - Vi IMproved', l[0])
  987. endfunc
  988. " Test for the "-F" (farsi) argument
  989. func Test_F_arg()
  990. throw 'Skipped: Nvim does not recognize "-F" argument'
  991. " Can't catch the output of gvim.
  992. CheckNotGui
  993. let l = systemlist(GetVimProg() .. ' -F')
  994. call assert_match('^E27:', l[0])
  995. endfunc
  996. " Test for the "-E" (improved Ex mode) argument
  997. func Test_E_arg()
  998. let after =<< trim [CODE]
  999. call assert_equal('cv', mode(1))
  1000. call writefile(v:errors, 'Xtestout')
  1001. qall
  1002. [CODE]
  1003. if RunVim([], after, '-E')
  1004. call assert_equal([], readfile('Xtestout'))
  1005. call delete('Xtestout')
  1006. endif
  1007. endfunc
  1008. " Test for the "-D" (debugger) argument
  1009. func Test_D_arg()
  1010. CheckRunVimInTerminal
  1011. let cmd = GetVimCommandCleanTerm() .. ' -D'
  1012. let buf = term_start(cmd, {'term_rows' : 10})
  1013. call WaitForAssert({-> assert_equal("running", term_getstatus(buf))})
  1014. call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.',
  1015. \ term_getline(buf, 7))})
  1016. call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))})
  1017. call StopVimInTerminal(buf)
  1018. endfunc
  1019. " Test for too many edit argument errors
  1020. func Test_too_many_edit_args()
  1021. throw 'Skipped: N/A'
  1022. " Can't catch the output of gvim.
  1023. CheckNotGui
  1024. CheckEnglish
  1025. let l = systemlist(GetVimProg() .. ' - -')
  1026. call assert_match('^Too many edit arguments: "-"', l[1])
  1027. endfunc
  1028. " Test starting vim with various names: vim, ex, view, evim, etc.
  1029. func Test_progname()
  1030. CheckUnix
  1031. call mkdir('Xprogname', 'p')
  1032. call writefile(['silent !date',
  1033. \ 'call writefile([mode(1), '
  1034. \ .. '&insertmode, &diff, &readonly, &updatecount, '
  1035. \ .. 'join(split(execute("message"), "\n")[1:])], "Xprogname_out")',
  1036. \ 'qall'], 'Xprogname_after')
  1037. " +---------------------------------------------- progname
  1038. " | +--------------------------------- mode(1)
  1039. " | | +--------------------------- &insertmode
  1040. " | | | +---------------------- &diff
  1041. " | | | | +----------------- &readonly
  1042. " | | | | | +-------- &updatecount
  1043. " | | | | | | +--- :messages
  1044. " | | | | | | |
  1045. " let expectations = {
  1046. " \ 'vim': ['n', '0', '0', '0', '200', ''],
  1047. " \ 'gvim': ['n', '0', '0', '0', '200', ''],
  1048. " \ 'ex': ['ce', '0', '0', '0', '200', ''],
  1049. " \ 'exim': ['cv', '0', '0', '0', '200', ''],
  1050. " \ 'view': ['n', '0', '0', '1', '10000', ''],
  1051. " \ 'gview': ['n', '0', '0', '1', '10000', ''],
  1052. " \ 'evim': ['n', '1', '0', '0', '200', ''],
  1053. " \ 'eview': ['n', '1', '0', '1', '10000', ''],
  1054. " \ 'rvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
  1055. " \ 'rgvim': ['n', '0', '0', '0', '200', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
  1056. " \ 'rview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
  1057. " \ 'rgview': ['n', '0', '0', '1', '10000', 'line 1: E145: Shell commands and some functionality not allowed in rvim'],
  1058. " \ 'vimdiff': ['n', '0', '1', '0', '200', ''],
  1059. " \ 'gvimdiff': ['n', '0', '1', '0', '200', '']}
  1060. let expectations = {'nvim': ['n', '0', '0', '0', '200', '']}
  1061. " let prognames = ['vim', 'gvim', 'ex', 'exim', 'view', 'gview',
  1062. " \ 'evim', 'eview', 'rvim', 'rgvim', 'rview', 'rgview',
  1063. " \ 'vimdiff', 'gvimdiff']
  1064. let prognames = ['nvim']
  1065. for progname in prognames
  1066. let run_with_gui = (progname =~# 'g') || (has('gui') && (progname ==# 'evim' || progname ==# 'eview'))
  1067. if empty($DISPLAY) && run_with_gui
  1068. " Can't run gvim, gview (etc.) if $DISPLAY is not setup.
  1069. continue
  1070. endif
  1071. exe 'silent !ln -s -f ' ..exepath(GetVimProg()) .. ' Xprogname/' .. progname
  1072. let stdout_stderr = ''
  1073. if progname =~# 'g'
  1074. let stdout_stderr = system('Xprogname/'..progname..' -f --clean --not-a-term -S Xprogname_after')
  1075. else
  1076. exe 'sil !Xprogname/'..progname..' -f --clean -S Xprogname_after'
  1077. endif
  1078. if progname =~# 'g' && !has('gui')
  1079. call assert_equal("E25: GUI cannot be used: Not enabled at compile time\n", stdout_stderr, progname)
  1080. else
  1081. " GUI motif can output some warnings like this:
  1082. " Warning:
  1083. " Name: subMenu
  1084. " Class: XmCascadeButton
  1085. " Illegal mnemonic character; Could not convert X KEYSYM to a keycode
  1086. " So don't check that stderr is empty with GUI Motif.
  1087. if run_with_gui && !has('gui_motif')
  1088. call assert_equal('', stdout_stderr, progname)
  1089. endif
  1090. call assert_equal(expectations[progname], readfile('Xprogname_out'), progname)
  1091. endif
  1092. call delete('Xprogname/' .. progname)
  1093. call delete('Xprogname_out')
  1094. endfor
  1095. call delete('Xprogname_after')
  1096. call delete('Xprogname', 'd')
  1097. endfunc
  1098. " Test for doing a write from .vimrc
  1099. func Test_write_in_vimrc()
  1100. call writefile(['silent! write'], 'Xvimrc')
  1101. let after =<< trim [CODE]
  1102. call assert_match('E32: ', v:errmsg)
  1103. call writefile(v:errors, 'Xtestout')
  1104. qall
  1105. [CODE]
  1106. if RunVim([], after, '-u Xvimrc')
  1107. call assert_equal([], readfile('Xtestout'))
  1108. call delete('Xtestout')
  1109. endif
  1110. call delete('Xvimrc')
  1111. endfunc
  1112. func Test_echo_true_in_cmd()
  1113. CheckNotGui
  1114. let lines =<< trim END
  1115. echo v:true
  1116. call writefile(['done'], 'Xresult')
  1117. quit
  1118. END
  1119. call writefile(lines, 'Xscript')
  1120. if RunVim([], [], '--cmd "source Xscript"')
  1121. call assert_equal(['done'], readfile('Xresult'))
  1122. endif
  1123. call delete('Xscript')
  1124. call delete('Xresult')
  1125. endfunc
  1126. func Test_rename_buffer_on_startup()
  1127. CheckUnix
  1128. let lines =<< trim END
  1129. call writefile(['done'], 'Xresult')
  1130. qa!
  1131. END
  1132. call writefile(lines, 'Xscript')
  1133. if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'")
  1134. call assert_equal(['done'], readfile('Xresult'))
  1135. endif
  1136. call delete('Xscript')
  1137. call delete('Xresult')
  1138. endfunc
  1139. " vim: shiftwidth=2 sts=2 expandtab