runtest.vim 3.3 KB

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