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 6if 1 7 8set nocp 9filetype indent on 10syn on 11set nowrapscan 12set report=9999 13 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 23let failed_count = 0 24for 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 114 let failed_count += 1 115 exe 'write ' . root . '.fail' 116 echoerr 'Test ' . fname . ' FAILED!' 117 else 118 exe 'write ' . root . '.out' 119 endif 120 121 quit! " close the indented file 122 endif 123endfor 124 125" Matching "if 1" at the start. 126endif 127 128if failed_count > 0 129 " have make report an error 130 cquit 131endif 132qall! 133