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