blob: 9502c42f3e8287a60eb6b3a1ee8030cbbccb661a [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
Bram Moolenaar63b74a82019-03-24 15:09:13 +010010syn on
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020011set nowrapscan
Bram Moolenaar9d87a372018-12-18 21:41:50 +010012set report=9999
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020013
14au! SwapExists * call HandleSwapExists()
15func HandleSwapExists()
16 " Ignore finding a swap file for the test input and output, the user might be
17 " editing them and that's OK.
18 if expand('<afile>') =~ '.*\.\(in\|out\|fail\|ok\)'
19 let v:swapchoice = 'e'
20 endif
21endfunc
22
Bram Moolenaarcd670592019-09-18 22:14:43 +020023let failed_count = 0
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020024for fname in glob('testdir/*.in', 1, 1)
25 let root = substitute(fname, '\.in', '', '')
26
27 " Execute the test if the .out file does not exist of when the .in file is
28 " newer.
29 let in_time = getftime(fname)
30 let out_time = getftime(root . '.out')
31 if out_time < 0 || in_time > out_time
32 call delete(root . '.fail')
33 call delete(root . '.out')
34
35 set sw& ts& filetype=
36 exe 'split ' . fname
37
38 let did_some = 0
39 let failed = 0
40 let end = 1
41 while 1
42 " Indent all the lines between "START_INDENT" and "END_INDENT"
43 exe end
44 let start = search('\<START_INDENT\>')
45 let end = search('\<END_INDENT\>')
46 if start <= 0 || end <= 0 || end <= start
47 if did_some == 0
48 call append(0, 'ERROR: START_INDENT and/or END_INDENT not found')
49 let failed = 1
50 endif
51 break
52 else
53 let did_some = 1
54
55 " Execute all commands marked with INDENT_EXE and find any pattern.
56 let lnum = start
57 let pattern = ''
58 let at = ''
59 while 1
60 exe lnum + 1
61 let lnum_exe = search('\<INDENT_EXE\>')
62 exe lnum + 1
63 let indent_at = search('\<INDENT_\(AT\|NEXT\|PREV\)\>')
64 if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at)
65 exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '')
66 let lnum = lnum_exe
67 let start = lnum
68 elseif indent_at > 0 && indent_at < end
69 if pattern != ''
70 call append(indent_at, 'ERROR: duplicate pattern')
71 let failed = 1
72 break
73 endif
74 let text = getline(indent_at)
75 let pattern = substitute(text, '.*INDENT_\S*\s*', '', '')
76 let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '')
77 let lnum = indent_at
78 let start = lnum
79 else
80 break
81 endif
82 endwhile
83
84 exe start + 1
85 if pattern == ''
86 exe 'normal =' . (end - 1) . 'G'
87 else
88 let lnum = search(pattern)
89 if lnum <= 0
90 call append(indent_at, 'ERROR: pattern not found: ' . pattern)
91 let failed = 1
92 break
93 endif
94 if at == 'AT'
95 exe lnum
96 elseif at == 'NEXT'
97 exe lnum + 1
98 else
99 exe lnum - 1
100 endif
101 normal ==
102 endif
103 endif
104 endwhile
105
106 if !failed
107 " Check the resulting text equals the .ok file.
108 if getline(1, '$') != readfile(root . '.ok')
109 let failed = 1
110 endif
111 endif
112
113 if failed
Bram Moolenaarcd670592019-09-18 22:14:43 +0200114 let failed_count += 1
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200115 exe 'write ' . root . '.fail'
116 echoerr 'Test ' . fname . ' FAILED!'
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200117 else
118 exe 'write ' . root . '.out'
119 endif
120
121 quit! " close the indented file
122 endif
123endfor
124
Bram Moolenaareeed6652018-12-15 17:43:42 +0100125" Matching "if 1" at the start.
126endif
127
Bram Moolenaarcd670592019-09-18 22:14:43 +0200128if failed_count > 0
129 " have make report an error
130 cquit
131endif
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200132qall!