runtest.vim 3.3 KB

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