blob: 96c31453af31ca0d3a0d335dfd9946ce0e24053d [file] [log] [blame]
Bram Moolenaardc2f73a2018-11-25 04:03:09 +01001" Runs all the indent tests for which there is no .out file.
2"
3" Current directory must be runtime/indent.
Bram Moolenaarc0fe4972018-10-25 16:53:19 +02004
Bram Moolenaareeed6652018-12-15 17:43:42 +01005" Only do this with the +eval feature
6if 1
7
Bram Moolenaarc0fe4972018-10-25 16:53:19 +02008set nocp
9filetype indent on
10set nowrapscan
11
12au! SwapExists * call HandleSwapExists()
13func HandleSwapExists()
14 " Ignore finding a swap file for the test input and output, the user might be
15 " editing them and that's OK.
16 if expand('<afile>') =~ '.*\.\(in\|out\|fail\|ok\)'
17 let v:swapchoice = 'e'
18 endif
19endfunc
20
21for fname in glob('testdir/*.in', 1, 1)
22 let root = substitute(fname, '\.in', '', '')
23
24 " Execute the test if the .out file does not exist of when the .in file is
25 " newer.
26 let in_time = getftime(fname)
27 let out_time = getftime(root . '.out')
28 if out_time < 0 || in_time > out_time
29 call delete(root . '.fail')
30 call delete(root . '.out')
31
32 set sw& ts& filetype=
33 exe 'split ' . fname
34
35 let did_some = 0
36 let failed = 0
37 let end = 1
38 while 1
39 " Indent all the lines between "START_INDENT" and "END_INDENT"
40 exe end
41 let start = search('\<START_INDENT\>')
42 let end = search('\<END_INDENT\>')
43 if start <= 0 || end <= 0 || end <= start
44 if did_some == 0
45 call append(0, 'ERROR: START_INDENT and/or END_INDENT not found')
46 let failed = 1
47 endif
48 break
49 else
50 let did_some = 1
51
52 " Execute all commands marked with INDENT_EXE and find any pattern.
53 let lnum = start
54 let pattern = ''
55 let at = ''
56 while 1
57 exe lnum + 1
58 let lnum_exe = search('\<INDENT_EXE\>')
59 exe lnum + 1
60 let indent_at = search('\<INDENT_\(AT\|NEXT\|PREV\)\>')
61 if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at)
62 exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '')
63 let lnum = lnum_exe
64 let start = lnum
65 elseif indent_at > 0 && indent_at < end
66 if pattern != ''
67 call append(indent_at, 'ERROR: duplicate pattern')
68 let failed = 1
69 break
70 endif
71 let text = getline(indent_at)
72 let pattern = substitute(text, '.*INDENT_\S*\s*', '', '')
73 let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '')
74 let lnum = indent_at
75 let start = lnum
76 else
77 break
78 endif
79 endwhile
80
81 exe start + 1
82 if pattern == ''
83 exe 'normal =' . (end - 1) . 'G'
84 else
85 let lnum = search(pattern)
86 if lnum <= 0
87 call append(indent_at, 'ERROR: pattern not found: ' . pattern)
88 let failed = 1
89 break
90 endif
91 if at == 'AT'
92 exe lnum
93 elseif at == 'NEXT'
94 exe lnum + 1
95 else
96 exe lnum - 1
97 endif
98 normal ==
99 endif
100 endif
101 endwhile
102
103 if !failed
104 " Check the resulting text equals the .ok file.
105 if getline(1, '$') != readfile(root . '.ok')
106 let failed = 1
107 endif
108 endif
109
110 if failed
111 exe 'write ' . root . '.fail'
112 echoerr 'Test ' . fname . ' FAILED!'
113 sleep 2
114 else
115 exe 'write ' . root . '.out'
116 endif
117
118 quit! " close the indented file
119 endif
120endfor
121
Bram Moolenaareeed6652018-12-15 17:43:42 +0100122" Matching "if 1" at the start.
123endif
124
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200125qall!