Mercurial > vim
annotate src/testdir/runtest.vim @ 32669:448aef880252
normalize line endings
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 26 Jun 2023 09:54:34 +0200 |
parents | 36519954bf67 |
children | 695b50472e85 |
rev | line source |
---|---|
32669
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
1 " This script is sourced while editing the .vim file with the tests. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
2 " When the script is successful the .res file will be created. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
3 " Errors are appended to the test.log file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
4 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
5 " To execute only specific test functions, add a second argument. It will be |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
6 " matched against the names of the Test_ function. E.g.: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
7 " ../vim -u NONE -S runtest.vim test_channel.vim open_delay |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
8 " The output can be found in the "messages" file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
9 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
10 " If the environment variable $TEST_FILTER is set then only test functions |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
11 " matching this pattern are executed. E.g. for sh/bash: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
12 " export TEST_FILTER=Test_channel |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
13 " For csh: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
14 " setenv TEST_FILTER Test_channel |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
15 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
16 " If the environment variable $TEST_SKIP_PAT is set then test functions |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
17 " matching this pattern will be skipped. It's the opposite of $TEST_FILTER. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
18 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
19 " While working on a test you can make $TEST_NO_RETRY non-empty to not retry: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
20 " export TEST_NO_RETRY=yes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
21 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
22 " To ignore failure for tests that are known to fail in a certain environment, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
23 " set $TEST_MAY_FAIL to a comma separated list of function names. E.g. for |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
24 " sh/bash: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
25 " export TEST_MAY_FAIL=Test_channel_one,Test_channel_other |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
26 " The failure report will then not be included in the test.log file and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
27 " "make test" will not fail. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
28 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
29 " The test script may contain anything, only functions that start with |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
30 " "Test_" are special. These will be invoked and should contain assert |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
31 " functions. See test_assert.vim for an example. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
32 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
33 " It is possible to source other files that contain "Test_" functions. This |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
34 " can speed up testing, since Vim does not need to restart. But be careful |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
35 " that the tests do not interfere with each other. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
36 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
37 " If an error cannot be detected properly with an assert function add the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
38 " error to the v:errors list: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
39 " call add(v:errors, 'test foo failed: Cannot find xyz') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
40 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
41 " If preparation for each Test_ function is needed, define a SetUp function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
42 " It will be called before each Test_ function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
43 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
44 " If cleanup after each Test_ function is needed, define a TearDown function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
45 " It will be called after each Test_ function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
46 " |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
47 " When debugging a test it can be useful to add messages to v:errors: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
48 " call add(v:errors, "this happened") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
49 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
50 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
51 " Without the +eval feature we can't run these tests, bail out. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
52 silent! while 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
53 qa! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
54 silent! endwhile |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
55 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
56 " In the GUI we can always change the screen size. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
57 if has('gui_running') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
58 set columns=80 lines=25 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
59 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
60 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
61 " Check that the screen size is at least 24 x 80 characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
62 if &lines < 24 || &columns < 80 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
63 let error = 'Screen size too small! Tests require at least 24 lines with 80 characters, got ' .. &lines .. ' lines with ' .. &columns .. ' characters' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
64 echoerr error |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
65 split test.log |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
66 $put =error |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
67 write |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
68 split messages |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
69 call append(line('$'), '') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
70 call append(line('$'), 'From ' . expand('%') . ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
71 call append(line('$'), error) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
72 write |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
73 qa! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
74 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
75 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
76 if has('reltime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
77 let s:run_start_time = reltime() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
78 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
79 if !filereadable('starttime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
80 " first test, store the overall test starting time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
81 let s:test_start_time = localtime() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
82 call writefile([string(s:test_start_time)], 'starttime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
83 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
84 " second or later test, read the overall test starting time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
85 let s:test_start_time = readfile('starttime')[0]->str2nr() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
86 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
87 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
88 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
89 " Always use forward slashes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
90 set shellslash |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
91 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
92 " Common with all tests on all systems. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
93 source setup.vim |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
94 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
95 " For consistency run all tests with 'nocompatible' set. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
96 " This also enables use of line continuation. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
97 set nocp viminfo+=nviminfo |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
98 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
99 " Use utf-8 by default, instead of whatever the system default happens to be. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
100 " Individual tests can overrule this at the top of the file and use |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
101 " g:orig_encoding if needed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
102 let g:orig_encoding = &encoding |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
103 set encoding=utf-8 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
104 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
105 " REDIR_TEST_TO_NULL has a very permissive SwapExists autocommand which is for |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
106 " the test_name.vim file itself. Replace it here with a more restrictive one, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
107 " so we still catch mistakes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
108 if has("win32") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
109 " replace any '/' directory separators by '\\' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
110 let s:test_script_fname = substitute(expand('%'), '/', '\\', 'g') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
111 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
112 let s:test_script_fname = expand('%') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
113 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
114 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
115 au! SwapExists * call HandleSwapExists() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
116 func HandleSwapExists() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
117 if exists('g:ignoreSwapExists') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
118 if type(g:ignoreSwapExists) == v:t_string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
119 let v:swapchoice = g:ignoreSwapExists |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
120 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
121 return |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
122 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
123 " Ignore finding a swap file for the test script (the user might be |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
124 " editing it and do ":make test_name") and the output file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
125 " Report finding another swap file and chose 'q' to avoid getting stuck. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
126 if expand('<afile>') == 'messages' || expand('<afile>') =~ s:test_script_fname |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
127 let v:swapchoice = 'e' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
128 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
129 call assert_report('Unexpected swap file: ' .. v:swapname) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
130 let v:swapchoice = 'q' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
131 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
132 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
133 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
134 " Avoid stopping at the "hit enter" prompt |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
135 set nomore |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
136 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
137 " Output all messages in English. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
138 lang mess C |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
139 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
140 " suppress menu translation |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
141 if has('gui_running') && exists('did_install_default_menus') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
142 source $VIMRUNTIME/delmenu.vim |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
143 set langmenu=none |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
144 source $VIMRUNTIME/menu.vim |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
145 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
146 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
147 let s:srcdir = expand('%:p:h:h') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
148 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
149 if has('win32') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
150 " avoid prompt that is long or contains a line break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
151 let $PROMPT = '$P$G' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
152 " On MS-Windows t_md and t_me are Vim specific escape sequences. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
153 let s:t_bold = "\x1b[1m" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
154 let s:t_normal = "\x1b[m" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
155 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
156 let s:t_bold = &t_md |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
157 let s:t_normal = &t_me |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
158 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
159 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
160 if has('mac') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
161 " In macOS, when starting a shell in a terminal, a bash deprecation warning |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
162 " message is displayed. This breaks the terminal test. Disable the warning |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
163 " message. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
164 let $BASH_SILENCE_DEPRECATION_WARNING = 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
165 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
166 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
167 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
168 " Prepare for calling test_garbagecollect_now(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
169 let v:testing = 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
170 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
171 " By default, copy each buffer line into allocated memory, so that valgrind can |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
172 " detect accessing memory before and after it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
173 call test_override('alloc_lines', 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
174 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
175 " Support function: get the alloc ID by name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
176 function GetAllocId(name) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
177 exe 'split ' . s:srcdir . '/alloc.h' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
178 let top = search('typedef enum') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
179 if top == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
180 call add(v:errors, 'typedef not found in alloc.h') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
181 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
182 let lnum = search('aid_' . a:name . ',') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
183 if lnum == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
184 call add(v:errors, 'Alloc ID ' . a:name . ' not defined') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
185 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
186 close |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
187 return lnum - top - 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
188 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
189 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
190 if has('reltime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
191 let g:func_start = reltime() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
192 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
193 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
194 " Get the list of swap files in the current directory. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
195 func s:GetSwapFileList() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
196 let save_dir = &directory |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
197 let &directory = '.' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
198 let files = swapfilelist() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
199 let &directory = save_dir |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
200 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
201 " remove a match with runtest.vim |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
202 let idx = indexof(files, 'v:val =~ "runtest.vim."') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
203 if idx >= 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
204 call remove(files, idx) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
205 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
206 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
207 return files |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
208 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
209 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
210 " A previous (failed) test run may have left swap files behind. Delete them |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
211 " before running tests again, they might interfere. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
212 for name in s:GetSwapFileList() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
213 call delete(name) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
214 endfor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
215 unlet name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
216 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
217 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
218 " Invoked when a test takes too much time. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
219 func TestTimeout(id) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
220 split test.log |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
221 call append(line('$'), '') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
222 call append(line('$'), 'Test timed out: ' .. g:testfunc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
223 write |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
224 call add(v:errors, 'Test timed out: ' . g:testfunc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
225 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
226 cquit! 42 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
227 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
228 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
229 func RunTheTest(test) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
230 let prefix = '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
231 if has('reltime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
232 let prefix = strftime('%M:%S', localtime() - s:test_start_time) .. ' ' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
233 let g:func_start = reltime() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
234 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
235 echoconsole prefix .. 'Executing ' .. a:test |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
236 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
237 if has('timers') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
238 " No test should take longer than 30 seconds. If it takes longer we |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
239 " assume we are stuck and need to break out. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
240 let test_timeout_timer = timer_start(30000, 'TestTimeout') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
241 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
242 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
243 " Avoid stopping at the "hit enter" prompt |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
244 set nomore |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
245 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
246 " Avoid a three second wait when a message is about to be overwritten by the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
247 " mode message. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
248 set noshowmode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
249 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
250 " Clear any overrides, except "alloc_lines". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
251 call test_override('ALL', 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
252 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
253 " Some tests wipe out buffers. To be consistent, always wipe out all |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
254 " buffers. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
255 %bwipe! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
256 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
257 " The test may change the current directory. Save and restore the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
258 " directory after executing the test. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
259 let save_cwd = getcwd() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
260 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
261 if exists("*SetUp") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
262 try |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
263 call SetUp() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
264 catch |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
265 call add(v:errors, 'Caught exception in SetUp() before ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
266 endtry |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
267 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
268 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
269 au VimLeavePre * call EarlyExit(g:testfunc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
270 if a:test =~ 'Test_nocatch_' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
271 " Function handles errors itself. This avoids skipping commands after the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
272 " error. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
273 let g:skipped_reason = '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
274 exe 'call ' . a:test |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
275 if g:skipped_reason != '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
276 call add(s:messages, ' Skipped') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
277 call add(s:skipped, 'SKIPPED ' . a:test . ': ' . g:skipped_reason) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
278 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
279 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
280 try |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
281 exe 'call ' . a:test |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
282 catch /^\cskipped/ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
283 call add(s:messages, ' Skipped') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
284 call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
285 catch |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
286 call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
287 endtry |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
288 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
289 au! VimLeavePre |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
290 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
291 if a:test =~ '_terminal_' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
292 " Terminal tests sometimes hang, give extra information |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
293 echoconsole 'After executing ' .. a:test |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
294 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
295 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
296 " In case 'insertmode' was set and something went wrong, make sure it is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
297 " reset to avoid trouble with anything else. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
298 set noinsertmode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
299 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
300 if exists("*TearDown") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
301 try |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
302 call TearDown() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
303 catch |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
304 call add(v:errors, 'Caught exception in TearDown() after ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
305 endtry |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
306 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
307 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
308 if has('timers') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
309 call timer_stop(test_timeout_timer) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
310 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
311 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
312 " Clear any autocommands and put back the catch-all for SwapExists. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
313 au! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
314 au SwapExists * call HandleSwapExists() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
315 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
316 " Check for and close any stray popup windows. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
317 if has('popupwin') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
318 call assert_equal([], popup_list(), 'Popup is still present') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
319 call popup_clear(1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
320 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
321 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
322 if filereadable('guidialogfile') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
323 call add(v:errors, "Unexpected dialog: " .. readfile('guidialogfile')->join('<NL>')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
324 call delete('guidialogfile') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
325 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
326 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
327 " Close any extra tab pages and windows and make the current one not modified. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
328 while tabpagenr('$') > 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
329 let winid = win_getid() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
330 quit! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
331 if winid == win_getid() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
332 echoerr 'Could not quit window' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
333 break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
334 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
335 endwhile |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
336 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
337 while 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
338 let wincount = winnr('$') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
339 if wincount == 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
340 break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
341 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
342 bwipe! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
343 if wincount == winnr('$') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
344 " Did not manage to close a window. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
345 only! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
346 break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
347 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
348 endwhile |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
349 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
350 exe 'cd ' . save_cwd |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
351 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
352 if a:test =~ '_terminal_' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
353 " Terminal tests sometimes hang, give extra information |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
354 echoconsole 'Finished ' . a:test |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
355 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
356 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
357 let message = 'Executed ' . a:test |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
358 if has('reltime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
359 let message ..= repeat(' ', 50 - len(message)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
360 let time = reltime(g:func_start) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
361 if reltimefloat(time) > 0.1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
362 let message = s:t_bold .. message |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
363 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
364 let message ..= ' in ' .. reltimestr(time) .. ' seconds' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
365 if reltimefloat(time) > 0.1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
366 let message ..= s:t_normal |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
367 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
368 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
369 call add(s:messages, message) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
370 let s:done += 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
371 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
372 " close any split windows |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
373 while winnr('$') > 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
374 bwipe! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
375 endwhile |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
376 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
377 " May be editing some buffer, wipe it out. Then we may end up in another |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
378 " buffer, continue until we end up in an empty no-name buffer without a swap |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
379 " file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
380 while bufname() != '' || execute('swapname') !~ 'No swap file' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
381 let bn = bufnr() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
382 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
383 noswapfile bwipe! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
384 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
385 if bn == bufnr() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
386 " avoid getting stuck in the same buffer |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
387 break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
388 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
389 endwhile |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
390 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
391 " Check if the test has left any swap files behind. Delete them before |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
392 " running tests again, they might interfere. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
393 let swapfiles = s:GetSwapFileList() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
394 if len(swapfiles) > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
395 call add(s:messages, "Found swap files: " .. string(swapfiles)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
396 for name in swapfiles |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
397 call delete(name) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
398 endfor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
399 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
400 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
401 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
402 func AfterTheTest(func_name) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
403 if len(v:errors) > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
404 if match(s:may_fail_list, '^' .. a:func_name) >= 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
405 let s:fail_expected += 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
406 call add(s:errors_expected, 'Found errors in ' . g:testfunc . ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
407 call extend(s:errors_expected, v:errors) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
408 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
409 let s:fail += 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
410 call add(s:errors, 'Found errors in ' . g:testfunc . ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
411 call extend(s:errors, v:errors) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
412 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
413 let v:errors = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
414 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
415 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
416 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
417 func EarlyExit(test) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
418 " It's OK for the test we use to test the quit detection. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
419 if a:test != 'Test_zz_quit_detected()' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
420 call add(v:errors, v:errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
421 call add(v:errors, 'Test caused Vim to exit: ' . a:test) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
422 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
423 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
424 call FinishTesting() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
425 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
426 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
427 " This function can be called by a test if it wants to abort testing. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
428 func FinishTesting() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
429 call AfterTheTest('') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
430 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
431 " Don't write viminfo on exit. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
432 set viminfo= |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
433 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
434 " Clean up files created by setup.vim |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
435 call delete('XfakeHOME', 'rf') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
436 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
437 if s:fail == 0 && s:fail_expected == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
438 " Success, create the .res file so that make knows it's done. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
439 exe 'split ' . fnamemodify(g:testname, ':r') . '.res' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
440 write |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
441 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
442 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
443 if len(s:errors) > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
444 " Append errors to test.log |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
445 split test.log |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
446 call append(line('$'), '') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
447 call append(line('$'), 'From ' . g:testname . ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
448 call append(line('$'), s:errors) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
449 write |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
450 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
451 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
452 if s:done == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
453 if s:filtered > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
454 if $TEST_FILTER != '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
455 let message = "NO tests match $TEST_FILTER: '" .. $TEST_FILTER .. "'" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
456 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
457 let message = "ALL tests match $TEST_SKIP_PAT: '" .. $TEST_SKIP_PAT .. "'" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
458 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
459 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
460 let message = 'NO tests executed' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
461 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
462 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
463 if s:filtered > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
464 call add(s:messages, "Filtered " .. s:filtered .. " tests with $TEST_FILTER and $TEST_SKIP_PAT") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
465 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
466 let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
467 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
468 if s:done > 0 && has('reltime') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
469 let message = s:t_bold .. message .. repeat(' ', 40 - len(message)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
470 let message ..= ' in ' .. reltimestr(reltime(s:run_start_time)) .. ' seconds' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
471 let message ..= s:t_normal |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
472 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
473 echo message |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
474 call add(s:messages, message) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
475 if s:fail > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
476 let message = s:fail . ' FAILED:' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
477 echo message |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
478 call add(s:messages, message) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
479 call extend(s:messages, s:errors) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
480 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
481 if s:fail_expected > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
482 let message = s:fail_expected . ' FAILED (matching $TEST_MAY_FAIL):' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
483 echo message |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
484 call add(s:messages, message) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
485 call extend(s:messages, s:errors_expected) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
486 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
487 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
488 " Add SKIPPED messages |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
489 call extend(s:messages, s:skipped) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
490 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
491 " Append messages to the file "messages" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
492 split messages |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
493 call append(line('$'), '') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
494 call append(line('$'), 'From ' . g:testname . ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
495 call append(line('$'), s:messages) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
496 write |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
497 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
498 qall! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
499 endfunc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
500 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
501 " Source the test script. First grab the file name, in case the script |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
502 " navigates away. g:testname can be used by the tests. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
503 let g:testname = expand('%') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
504 let s:done = 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
505 let s:fail = 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
506 let s:fail_expected = 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
507 let s:errors = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
508 let s:errors_expected = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
509 let s:messages = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
510 let s:skipped = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
511 if expand('%') =~ 'test_vimscript.vim' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
512 " this test has intentional errors, don't use try/catch. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
513 source % |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
514 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
515 try |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
516 source % |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
517 catch /^\cskipped/ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
518 call add(s:messages, ' Skipped') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
519 call add(s:skipped, 'SKIPPED ' . expand('%') . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
520 catch |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
521 let s:fail += 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
522 call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
523 endtry |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
524 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
525 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
526 " Delete the .res file, it may change behavior for completion |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
527 call delete(fnamemodify(g:testname, ':r') .. '.res') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
528 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
529 " Locate Test_ functions and execute them. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
530 redir @q |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
531 silent function /^Test_ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
532 redir END |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
533 let s:tests = split(substitute(@q, '\(function\|def\) \(\k*()\)', '\2', 'g')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
534 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
535 " If there is an extra argument filter the function names against it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
536 if argc() > 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
537 let s:tests = filter(s:tests, 'v:val =~ argv(1)') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
538 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
539 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
540 " If the environment variable $TEST_FILTER is set then filter the function |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
541 " names against it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
542 let s:filtered = 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
543 if $TEST_FILTER != '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
544 let s:filtered = len(s:tests) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
545 let s:tests = filter(s:tests, 'v:val =~ $TEST_FILTER') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
546 let s:filtered -= len(s:tests) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
547 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
548 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
549 let s:may_fail_list = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
550 if $TEST_MAY_FAIL != '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
551 " Split the list at commas and add () to make it match g:testfunc. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
552 let s:may_fail_list = split($TEST_MAY_FAIL, ',')->map({i, v -> v .. '()'}) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
553 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
554 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
555 " Execute the tests in alphabetical order. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
556 for g:testfunc in sort(s:tests) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
557 if $TEST_SKIP_PAT != '' && g:testfunc =~ $TEST_SKIP_PAT |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
558 call add(s:messages, g:testfunc .. ' matches $TEST_SKIP_PAT') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
559 let s:filtered += 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
560 continue |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
561 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
562 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
563 " Silence, please! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
564 set belloff=all |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
565 let prev_error = '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
566 let total_errors = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
567 let g:run_nr = 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
568 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
569 " A test can set g:test_is_flaky to retry running the test. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
570 let g:test_is_flaky = 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
571 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
572 let starttime = strftime("%H:%M:%S") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
573 call RunTheTest(g:testfunc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
574 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
575 " Repeat a flaky test. Give up when: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
576 " - $TEST_NO_RETRY is not empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
577 " - it fails again with the same message |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
578 " - it fails five times (with a different message) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
579 if len(v:errors) > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
580 \ && $TEST_NO_RETRY == '' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
581 \ && g:test_is_flaky |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
582 while 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
583 call add(s:messages, 'Found errors in ' .. g:testfunc .. ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
584 call extend(s:messages, v:errors) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
585 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
586 let endtime = strftime("%H:%M:%S") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
587 call add(total_errors, $'Run {g:run_nr}, {starttime} - {endtime}:') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
588 call extend(total_errors, v:errors) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
589 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
590 if g:run_nr >= 5 || prev_error == v:errors[0] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
591 call add(total_errors, 'Flaky test failed too often, giving up') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
592 let v:errors = total_errors |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
593 break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
594 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
595 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
596 call add(s:messages, 'Flaky test failed, running it again') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
597 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
598 " Flakiness is often caused by the system being very busy. Sleep a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
599 " couple of seconds to have a higher chance of succeeding the second |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
600 " time. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
601 sleep 2 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
602 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
603 let prev_error = v:errors[0] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
604 let v:errors = [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
605 let g:run_nr += 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
606 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
607 let starttime = strftime("%H:%M:%S") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
608 call RunTheTest(g:testfunc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
609 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
610 if len(v:errors) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
611 " Test passed on rerun. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
612 break |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
613 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
614 endwhile |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
615 endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
616 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
617 call AfterTheTest(g:testfunc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
618 endfor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
619 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
620 call FinishTesting() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
621 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32545
diff
changeset
|
622 " vim: shiftwidth=2 sts=2 expandtab |