File: test-backend.vim

package info (click to toggle)
vim-vimtex 2.16-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,660 kB
  • sloc: makefile: 367; python: 103
file content (108 lines) | stat: -rw-r--r-- 2,415 bytes parent folder | download
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
set nocompatible
let &rtp = '../..,' . &rtp
filetype plugin on

set nomore

let g:vimtex_view_automatic = 0
let g:vimtex_log_verbose = 0

function! RunTests(comp, list_opts)
  if !executable(a:comp)
    echo 'Warning! "' . a:comp . '" was not executable!'
    echo "Compiler tests could not run!\n\n"
    cquit
  endif

  let g:vimtex_compiler_method = a:comp

  for l:opts in a:list_opts
    let g:vimtex_compiler_{a:comp} = l:opts

    " Ensure there is no latexmk process before we start the test
    if a:comp ==# 'latexmk'
      call system('pkill -f latexmk')
    endif

    echo 'Testing compiler "' . a:comp . '"'
    if !empty(l:opts)
      echon ' with options:'
      for [l:key, l:val] in items(l:opts)
        echo '* ' . l:key . ' =' l:val . "\n"
      endfor
    endif

    for l:file in glob('minimal.*', 1, 1)
      call delete(l:file)
    endfor
    call writefile([
          \ '\documentclass{minimal}',
          \ '\begin{document}',
          \ 'Hello World!',
          \ '\end{document}',
          \], 'minimal.tex')

    silent edit minimal.tex

    " Check if the compiler was loaded
    if !has_key(b:vimtex, 'compiler')
      echo "Compiler failed to load!\n"
      cquit
    endif

    silent call vimtex#compiler#compile()
    sleep 650m

    " Check if continuous mode is active
    if get(b:vimtex.compiler, 'continuous')
      if !b:vimtex.compiler.get_pid()
        echo "Could not get PID for compiler\n"
        cquit
      endif

      silent call vimtex#compiler#stop()
    else
      sleep 450m
    endif

    " Check that the PDF has been built
    if empty(b:vimtex.compiler.get_file('pdf'))
      echo "PDF was not built properly\n"
      cquit
    endif

    silent call vimtex#compiler#clean(1)
    sleep 650m

    if !empty(b:vimtex.compiler.get_file('pdf'))
          \ || !empty(b:vimtex.compiler.get_file('aux'))
      echo "VimtexClean failed!\n"
      cquit
    endif

    if !empty(get(l:opts, 'out_dir', ''))
      call delete(l:opts.out_dir, 'rf')
    endif

    echo "\n"
    bwipeout
  endfor
endfunction

for [s:comp, s:opts] in items({
      \ 'latexmk' : [
      \   {},
      \   {'out_dir' : 'out'},
      \   {'callback' : 0},
      \   {'callback' : 0, 'continuous' : 0},
      \   {'continuous' : 0},
      \ ],
      \ 'latexrun' : [
      \   {},
      \   {'out_dir' : 'out'},
      \ ],
      \})
  call RunTests(s:comp, s:opts)
endfor

quitall!