runtest.vim (3419B)
1 " Runs all the indent tests for which there is no .out file. 2 " 3 " Current directory must be runtime/indent. 4 5 " Only do this with the +eval feature. 6 if 1 7 8 set nocp 9 filetype indent on 10 syn on 11 set nowrapscan 12 set report=9999 13 set modeline 14 set debug=throw 15 set nomore 16 17 au! SwapExists * call HandleSwapExists() 18 func 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 24 endfunc 25 26 let failed_count = 0 27 for 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 == '' 89 try 90 exe 'normal =' .. (end - 1) .. 'G' 91 catch 92 call append(indent_at, 'ERROR: ' .. v:exception) 93 let failed = 1 94 endtry 95 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 109 try 110 normal == 111 catch 112 call append(indent_at, 'ERROR: ' .. v:exception) 113 let failed = 1 114 endtry 115 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 127 let failed_count += 1 128 silent exe 'write ' .. root .. '.fail' 129 echoerr 'Test ' .. fname .. ' FAILED!' 130 else 131 silent exe 'write ' .. root .. '.out' 132 echo "Test " .. fname .. " OK\n" 133 endif 134 135 quit! " Close the indented file. 136 endif 137 endfor 138 139 " Matching "if 1" at the start. 140 endif 141 142 if failed_count > 0 143 " Have make report an error. 144 cquit 145 endif 146 qall!