Bram Moolenaar | c0fe497 | 2018-10-25 16:53:19 +0200 | [diff] [blame] | 1 | " Runs all the indent tests for which there is no .out file |
| 2 | |
| 3 | set nocp |
| 4 | filetype indent on |
| 5 | set nowrapscan |
| 6 | |
| 7 | au! SwapExists * call HandleSwapExists() |
| 8 | func HandleSwapExists() |
| 9 | " Ignore finding a swap file for the test input and output, the user might be |
| 10 | " editing them and that's OK. |
| 11 | if expand('<afile>') =~ '.*\.\(in\|out\|fail\|ok\)' |
| 12 | let v:swapchoice = 'e' |
| 13 | endif |
| 14 | endfunc |
| 15 | |
| 16 | for fname in glob('testdir/*.in', 1, 1) |
| 17 | let root = substitute(fname, '\.in', '', '') |
| 18 | |
| 19 | " Execute the test if the .out file does not exist of when the .in file is |
| 20 | " newer. |
| 21 | let in_time = getftime(fname) |
| 22 | let out_time = getftime(root . '.out') |
| 23 | if out_time < 0 || in_time > out_time |
| 24 | call delete(root . '.fail') |
| 25 | call delete(root . '.out') |
| 26 | |
| 27 | set sw& ts& filetype= |
| 28 | exe 'split ' . fname |
| 29 | |
| 30 | let did_some = 0 |
| 31 | let failed = 0 |
| 32 | let end = 1 |
| 33 | while 1 |
| 34 | " Indent all the lines between "START_INDENT" and "END_INDENT" |
| 35 | exe end |
| 36 | let start = search('\<START_INDENT\>') |
| 37 | let end = search('\<END_INDENT\>') |
| 38 | if start <= 0 || end <= 0 || end <= start |
| 39 | if did_some == 0 |
| 40 | call append(0, 'ERROR: START_INDENT and/or END_INDENT not found') |
| 41 | let failed = 1 |
| 42 | endif |
| 43 | break |
| 44 | else |
| 45 | let did_some = 1 |
| 46 | |
| 47 | " Execute all commands marked with INDENT_EXE and find any pattern. |
| 48 | let lnum = start |
| 49 | let pattern = '' |
| 50 | let at = '' |
| 51 | while 1 |
| 52 | exe lnum + 1 |
| 53 | let lnum_exe = search('\<INDENT_EXE\>') |
| 54 | exe lnum + 1 |
| 55 | let indent_at = search('\<INDENT_\(AT\|NEXT\|PREV\)\>') |
| 56 | if lnum_exe > 0 && lnum_exe < end && (indent_at <= 0 || lnum_exe < indent_at) |
| 57 | exe substitute(getline(lnum_exe), '.*INDENT_EXE', '', '') |
| 58 | let lnum = lnum_exe |
| 59 | let start = lnum |
| 60 | elseif indent_at > 0 && indent_at < end |
| 61 | if pattern != '' |
| 62 | call append(indent_at, 'ERROR: duplicate pattern') |
| 63 | let failed = 1 |
| 64 | break |
| 65 | endif |
| 66 | let text = getline(indent_at) |
| 67 | let pattern = substitute(text, '.*INDENT_\S*\s*', '', '') |
| 68 | let at = substitute(text, '.*INDENT_\(\S*\).*', '\1', '') |
| 69 | let lnum = indent_at |
| 70 | let start = lnum |
| 71 | else |
| 72 | break |
| 73 | endif |
| 74 | endwhile |
| 75 | |
| 76 | exe start + 1 |
| 77 | if pattern == '' |
| 78 | exe 'normal =' . (end - 1) . 'G' |
| 79 | else |
| 80 | let lnum = search(pattern) |
| 81 | if lnum <= 0 |
| 82 | call append(indent_at, 'ERROR: pattern not found: ' . pattern) |
| 83 | let failed = 1 |
| 84 | break |
| 85 | endif |
| 86 | if at == 'AT' |
| 87 | exe lnum |
| 88 | elseif at == 'NEXT' |
| 89 | exe lnum + 1 |
| 90 | else |
| 91 | exe lnum - 1 |
| 92 | endif |
| 93 | normal == |
| 94 | endif |
| 95 | endif |
| 96 | endwhile |
| 97 | |
| 98 | if !failed |
| 99 | " Check the resulting text equals the .ok file. |
| 100 | if getline(1, '$') != readfile(root . '.ok') |
| 101 | let failed = 1 |
| 102 | endif |
| 103 | endif |
| 104 | |
| 105 | if failed |
| 106 | exe 'write ' . root . '.fail' |
| 107 | echoerr 'Test ' . fname . ' FAILED!' |
| 108 | sleep 2 |
| 109 | else |
| 110 | exe 'write ' . root . '.out' |
| 111 | endif |
| 112 | |
| 113 | quit! " close the indented file |
| 114 | endif |
| 115 | endfor |
| 116 | |
| 117 | qall! |