summaryrefslogtreecommitdiffstats
path: root/scripts/test
blob: f726d2266cfec50b012e13177080c461c24b9ad5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby

def run_script(src)
  if system("bash", "-eo", "pipefail", "-c", src) != true
    exit(1)
  end
end

def run_vimscript(src)
  wrapper = <<~EOF
    vim --clean --not-a-term -u <(cat <<- "EOM"
    set nocompatible
    let &rtp='#{Dir.pwd},' . &rtp
    set t_ti= t_te=
    set shortmess+=F
    set noswapfile
    set nocp
    set nomore
    func! Log(msg)
      if $DEV != '1'
        echo a:msg
      endif
    endfunc
    EOM
  EOF

  wrapper += <<~'EOF'
    ) -S <(cat <<- "EOM"
      #{src}

      redir @q
      silent function /^NewTest_
      redir END
      let s:tests = split(substitute(@q, '\(function\|def\) \(\k*()\)', '\2', 'g'))
      for test in s:tests
        echo test
        %bwipe!
        exe 'call ' . test
        set noinsertmode
        if len(v:errors) > 0
          for err in v:errors
            echo err
          endfor
          cq!
        endif
      endfor

      qa!
    EOM
    ) | perl -pe 's/\e\[[0-9;]*[a-zA-Z]//g'
  EOF

  wrapper.gsub!('#{src}') { src }

  run_script(wrapper)
end

test_helptags = <<~EOF
  if ! expect -c 'set timeout 1' -c 'spawn vim -N --clean -c "set nomore | :helptags ./doc | q"' -c 'expect "ENTER" { exit 1 }' > /dev/null; then
    echo "Please ensure ':helptags ./doc' works properly"
    exit 1
  fi
EOF

run_vimscript('source tests/filetypes.vim')
run_vimscript('source tests/extensions.vim')

if !ENV['DEV']
  run_vimscript('source tests/native.vim')
end

run_script(test_helptags)

# run_vimscript("
#   func! TestIndent(file)
#     :e a:file
#     echo 'ok'
#     echo &filetype
#   endfunc
#
#   #{Dir['tests/indent/**/test.*'].map { |f| "call TestIndent(\"#{f}\")"}.join("\n")}
# ")