Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 1 | " Tests for startup. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 2 | |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 3 | source shared.vim |
| 4 | |
| 5 | " Check that loading startup.vim works. |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 6 | func Test_startup_script() |
| 7 | set compatible |
| 8 | source $VIMRUNTIME/defaults.vim |
| 9 | |
| 10 | call assert_equal(0, &compatible) |
| 11 | endfunc |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 12 | |
| 13 | " Verify the order in which plugins are loaded: |
| 14 | " 1. plugins in non-after directories |
| 15 | " 2. packages |
| 16 | " 3. plugins in after directories |
| 17 | func Test_after_comes_later() |
Bram Moolenaar | 3286043 | 2016-08-06 19:24:23 +0200 | [diff] [blame] | 18 | if !has('packages') |
| 19 | return |
| 20 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 21 | let before = [ |
Bram Moolenaar | 446cce6 | 2016-08-06 21:37:27 +0200 | [diff] [blame] | 22 | \ 'set nocp viminfo+=nviminfo', |
| 23 | \ 'set guioptions+=M', |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 24 | \ 'let $HOME = "/does/not/exist"', |
| 25 | \ 'set loadplugins', |
| 26 | \ 'set rtp=Xhere,Xafter', |
| 27 | \ 'set packpath=Xhere,Xafter', |
| 28 | \ 'set nomore', |
| 29 | \ ] |
| 30 | let after = [ |
| 31 | \ 'redir! > Xtestout', |
| 32 | \ 'scriptnames', |
| 33 | \ 'redir END', |
| 34 | \ 'quit', |
| 35 | \ ] |
| 36 | call mkdir('Xhere/plugin', 'p') |
| 37 | call writefile(['let done = 1'], 'Xhere/plugin/here.vim') |
| 38 | call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') |
| 39 | call writefile(['let done = 1'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') |
| 40 | |
| 41 | call mkdir('Xafter/plugin', 'p') |
| 42 | call writefile(['let done = 1'], 'Xafter/plugin/later.vim') |
| 43 | |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 44 | if RunVim(before, after, '') |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 45 | |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 46 | let lines = readfile('Xtestout') |
| 47 | let expected = ['Xbefore.vim', 'here.vim', 'foo.vim', 'later.vim', 'Xafter.vim'] |
| 48 | let found = [] |
| 49 | for line in lines |
| 50 | for one in expected |
| 51 | if line =~ one |
| 52 | call add(found, one) |
| 53 | endif |
| 54 | endfor |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 55 | endfor |
Bram Moolenaar | 83b3c3d | 2016-08-06 19:16:43 +0200 | [diff] [blame] | 56 | call assert_equal(expected, found) |
| 57 | endif |
Bram Moolenaar | 66459b7 | 2016-08-06 19:01:55 +0200 | [diff] [blame] | 58 | |
| 59 | call delete('Xtestout') |
| 60 | call delete('Xhere', 'rf') |
| 61 | call delete('Xafter', 'rf') |
| 62 | endfunc |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 63 | |
| 64 | func Test_help_arg() |
Bram Moolenaar | 3321e9d | 2016-08-06 23:03:59 +0200 | [diff] [blame] | 65 | if !has('unix') && has('gui') |
| 66 | " this doesn't work with gvim on MS-Windows |
| 67 | return |
| 68 | endif |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 69 | if RunVim([], [], '--help >Xtestout') |
| 70 | let lines = readfile('Xtestout') |
| 71 | call assert_true(len(lines) > 20) |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame^] | 72 | call assert_match('Vi IMproved', lines[0]) |
Bram Moolenaar | 472a0a8 | 2016-08-06 22:31:42 +0200 | [diff] [blame] | 73 | |
| 74 | " check if couple of lines are there |
| 75 | let found = 0 |
| 76 | for line in lines |
| 77 | if line =~ '-R.*Readonly mode' |
| 78 | let found += 1 |
| 79 | endif |
| 80 | if line =~ '--version' |
| 81 | let found += 1 |
| 82 | endif |
| 83 | endfor |
| 84 | call assert_equal(2, found) |
| 85 | endif |
| 86 | call delete('Xtestout') |
| 87 | endfunc |
Bram Moolenaar | ba98bef | 2016-08-07 15:51:39 +0200 | [diff] [blame^] | 88 | |
| 89 | func Test_compatible_args() |
| 90 | let after = [ |
| 91 | \ 'call writefile([string(&compatible)], "Xtestout")', |
| 92 | \ 'set viminfo+=nviminfo', |
| 93 | \ 'quit', |
| 94 | \ ] |
| 95 | if RunVim([], after, '-C') |
| 96 | let lines = readfile('Xtestout') |
| 97 | call assert_equal('1', lines[0]) |
| 98 | endif |
| 99 | |
| 100 | if RunVim([], after, '-N') |
| 101 | let lines = readfile('Xtestout') |
| 102 | call assert_equal('0', lines[0]) |
| 103 | endif |
| 104 | |
| 105 | call delete('Xtestout') |
| 106 | endfunc |
| 107 | |
| 108 | func Test_file_args() |
| 109 | let after = [ |
| 110 | \ 'call writefile(argv(), "Xtestout")', |
| 111 | \ 'qall', |
| 112 | \ ] |
| 113 | if RunVim([], after, '') |
| 114 | let lines = readfile('Xtestout') |
| 115 | call assert_equal(0, len(lines)) |
| 116 | endif |
| 117 | |
| 118 | if RunVim([], after, 'one') |
| 119 | let lines = readfile('Xtestout') |
| 120 | call assert_equal(1, len(lines)) |
| 121 | call assert_equal('one', lines[0]) |
| 122 | endif |
| 123 | |
| 124 | if RunVim([], after, 'one two three') |
| 125 | let lines = readfile('Xtestout') |
| 126 | call assert_equal(3, len(lines)) |
| 127 | call assert_equal('one', lines[0]) |
| 128 | call assert_equal('two', lines[1]) |
| 129 | call assert_equal('three', lines[2]) |
| 130 | endif |
| 131 | |
| 132 | if RunVim([], after, 'one -c echo two') |
| 133 | let lines = readfile('Xtestout') |
| 134 | call assert_equal(2, len(lines)) |
| 135 | call assert_equal('one', lines[0]) |
| 136 | call assert_equal('two', lines[1]) |
| 137 | endif |
| 138 | |
| 139 | if RunVim([], after, 'one -- -c echo two') |
| 140 | let lines = readfile('Xtestout') |
| 141 | call assert_equal(4, len(lines)) |
| 142 | call assert_equal('one', lines[0]) |
| 143 | call assert_equal('-c', lines[1]) |
| 144 | call assert_equal('echo', lines[2]) |
| 145 | call assert_equal('two', lines[3]) |
| 146 | endif |
| 147 | |
| 148 | call delete('Xtestout') |
| 149 | endfunc |
| 150 | |
| 151 | func Test_startuptime() |
| 152 | if !has('startuptime') |
| 153 | return |
| 154 | endif |
| 155 | let after = ['qall'] |
| 156 | if RunVim([], after, '--startuptime Xtestout one') |
| 157 | let lines = readfile('Xtestout') |
| 158 | let expected = ['--- VIM STARTING ---', 'parsing arguments', |
| 159 | \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] |
| 160 | let found = [] |
| 161 | for line in lines |
| 162 | for exp in expected |
| 163 | if line =~ exp |
| 164 | call add(found, exp) |
| 165 | endif |
| 166 | endfor |
| 167 | endfor |
| 168 | call assert_equal(expected, found) |
| 169 | endif |
| 170 | call delete('Xtestout') |
| 171 | endfunc |