aboutsummaryrefslogtreecommitdiff
path: root/scripts/run-api-tests.exp
blob: b9d37ca90303840234f344417a097e5c38180733 (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
83
84
85
86
87
#!/usr/bin/env expect

if {$argc < 2} {
  puts "Need commands for running the tests and for starting nvim"
  exit 1
}

set timeout 60
set run_tests [split [lindex $argv 0] " "]
set run_nvim [split [lindex $argv 1] " "]

# don't echo to stdout
log_user 0
# set NEOVIM_LISTEN_ADDRESS, so nvim will listen on a known socket
set env(NEOVIM_LISTEN_ADDRESS) "/tmp/nvim-[exec date +%s%N].sock"
# start nvim
spawn {*}$run_nvim
# save the job descriptor
set nvim_id $spawn_id
# Reset function that can be invoked by test runners to put nvim in a cleaner
# state
send {
:function BeforeEachTest()
  set all&
  let &initpython = 'python -c "import neovim; neovim.start_host()"'
  redir => groups
  silent augroup
  redir END
  for group in split(groups)
    exe 'augroup '.group
    autocmd!
    augroup END
  endfor
  autocmd!
  tabnew
  let curbufnum = eval(bufnr('%'))
  redir => buflist
  silent ls!
  redir END
  let bufnums = []
  for buf in split(buflist, '\n')
    let bufnum = eval(split(buf, '[ u]')[0])
    if bufnum != curbufnum
      call add(bufnums, bufnum)
    endif
  endfor
  if len(bufnums) > 0
    exe 'silent bwipeout! '.join(bufnums, ' ')
  endif
  silent tabonly
  for k in keys(g:)
    exe 'unlet g:'.k
  endfor
  filetype plugin indent off
  mapclear
  mapclear!
  abclear
  comclear
endfunction
:echo "read"."y"
}
# wait until nvim is ready
expect "ready"
# run tests
spawn {*}$run_tests
set tests_id $spawn_id
set status 1
# listen for test output in the background
expect_background {
  * {
    # show test output to the user
    send_user -- $expect_out(buffer)
  }
  eof {
    # collect the exit status code
    set spawn_id $tests_id
    catch wait result
    set status [lindex $result 3]
    set spawn_id $nvim_id
    # quit nvim
    send ":qa!\r"
  }
}
# switch back nvim and wait until it exits 
set spawn_id $nvim_id
expect eof
exit $status