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