blob: fa4e16e3810c668d5e4f6375e8200c61b61fb4be [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 Moolenaar36576862020-05-06 22:25:05 +020013set modeline
Bram Moolenaar0daafaa2022-09-04 17:45:43 +010014set debug=throw
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020015
16au! SwapExists * call HandleSwapExists()
17func HandleSwapExists()
18 " Ignore finding a swap file for the test input and output, the user might be
19 " editing them and that's OK.
20 if expand('<afile>') =~ '.*\.\(in\|out\|fail\|ok\)'
21 let v:swapchoice = 'e'
22 endif
23endfunc
24
Bram Moolenaarcd670592019-09-18 22:14:43 +020025let failed_count = 0
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020026for fname in glob('testdir/*.in', 1, 1)
27 let root = substitute(fname, '\.in', '', '')
28
29 " Execute the test if the .out file does not exist of when the .in file is
30 " newer.
31 let in_time = getftime(fname)
32 let out_time = getftime(root . '.out')
33 if out_time < 0 || in_time > out_time
34 call delete(root . '.fail')
35 call delete(root . '.out')
36
37 set sw& ts& filetype=
38 exe 'split ' . fname
39
40 let did_some = 0
41 let failed = 0
42 let end = 1
43 while 1
44 " Indent all the lines between "START_INDENT" and "END_INDENT"
45 exe end
46 let start = search('\<START_INDENT\>')
47 let end = search('\<END_INDENT\>')
48 if start <= 0 || end <= 0 || end <= start
49 if did_some == 0
50 call append(0, 'ERROR: START_INDENT and/or END_INDENT not found')
51 let failed = 1
52 endif
53 break
54 else
55 let did_some = 1
56
57 " Execute all commands marked with INDENT_EXE and find any pattern.
58 let lnum = start
59 let pattern = ''
60 let at = ''
61 while 1
62 exe lnum + 1
63 let lnum_exe = search('\<INDENT_EXE\>')
64 exe lnum + 1
65 let indent_at = search('\<INDENT_\(AT\|NEXT\|PREV\)\>')
66 if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at)
67 exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '')
68 let lnum = lnum_exe
69 let start = lnum
70 elseif indent_at > 0 && indent_at < end
71 if pattern != ''
72 call append(indent_at, 'ERROR: duplicate pattern')
73 let failed = 1
74 break
75 endif
76 let text = getline(indent_at)
77 let pattern = substitute(text, '.*INDENT_\S*\s*', '', '')
78 let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '')
79 let lnum = indent_at
80 let start = lnum
81 else
82 break
83 endif
84 endwhile
85
86 exe start + 1
87 if pattern == ''
Bram Moolenaar0daafaa2022-09-04 17:45:43 +010088 try
89 exe 'normal =' . (end - 1) . 'G'
90 catch
91 call append(indent_at, 'ERROR: ' . v:exception)
92 let failed = 1
93 endtry
Bram Moolenaarc0fe4972018-10-25 16:53:19 +020094 else
95 let lnum = search(pattern)
96 if lnum <= 0
97 call append(indent_at, 'ERROR: pattern not found: ' . pattern)
98 let failed = 1
99 break
100 endif
101 if at == 'AT'
102 exe lnum
103 elseif at == 'NEXT'
104 exe lnum + 1
105 else
106 exe lnum - 1
107 endif
Bram Moolenaar0daafaa2022-09-04 17:45:43 +0100108 try
109 normal ==
110 catch
111 call append(indent_at, 'ERROR: ' . v:exception)
112 let failed = 1
113 endtry
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200114 endif
115 endif
116 endwhile
117
118 if !failed
119 " Check the resulting text equals the .ok file.
120 if getline(1, '$') != readfile(root . '.ok')
121 let failed = 1
122 endif
123 endif
124
125 if failed
Bram Moolenaarcd670592019-09-18 22:14:43 +0200126 let failed_count += 1
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200127 exe 'write ' . root . '.fail'
128 echoerr 'Test ' . fname . ' FAILED!'
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200129 else
130 exe 'write ' . root . '.out'
Bram Moolenaar32b364f2019-12-08 15:07:48 +0100131 echo "Test " . fname . " OK\n"
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200132 endif
133
134 quit! " close the indented file
135 endif
136endfor
137
Bram Moolenaareeed6652018-12-15 17:43:42 +0100138" Matching "if 1" at the start.
139endif
140
Bram Moolenaarcd670592019-09-18 22:14:43 +0200141if failed_count > 0
142 " have make report an error
143 cquit
144endif
Bram Moolenaarc0fe4972018-10-25 16:53:19 +0200145qall!