annotate src/testdir/test_terminal.vim @ 11872:ff8122091ec6 v8.0.0816

patch 8.0.0816: crash when using invalid buffer number commit https://github.com/vim/vim/commit/f144a3fb73340fe22e08bd1fa77e27c9f55bb0af Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 30 18:02:12 2017 +0200 patch 8.0.0816: crash when using invalid buffer number Problem: Crash when using invalid buffer number. Solution: Check for NULL buffer. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/1899)
author Christian Brabandt <cb@256bit.org>
date Sun, 30 Jul 2017 18:15:04 +0200
parents 1c65cad8b967
children 7df4afab67c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for the terminal window.
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !exists('*term_start')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 source shared.vim
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 func Test_terminal_basic()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let buf = term_start(&shell)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let termlist = term_list()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_equal(1, len(termlist))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_equal(buf, termlist[0])
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let g:job = term_getjob(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_equal(v:t_job, type(g:job))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call term_sendkeys(buf, "exit\r")
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call WaitFor('job_status(g:job) == "dead"')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal('dead', job_status(g:job))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 exe buf . 'bwipe'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 unlet g:job
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 endfunc
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 func Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let l = term_scrape(a:buf, 0)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call assert_true(len(l) > 0)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_equal('1', l[0].chars)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_equal('2', l[1].chars)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 call assert_equal('3', l[2].chars)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal('#00e000', l[0].fg)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 if &background == 'light'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_equal('#ffffff', l[0].bg)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 call assert_equal('#000000', l[0].bg)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let l = term_getline(a:buf, 0)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 call assert_equal('123', l)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 endfunc
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 func Test_terminal_scrape()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 if has('win32')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let cmd = 'cmd /c "cls && color 2 && echo 123"'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 call writefile(["\<Esc>[32m123"], 'Xtext')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let cmd = "cat Xtext"
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let buf = term_start(cmd)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 let termlist = term_list()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call assert_equal(1, len(termlist))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call assert_equal(buf, termlist[0])
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
11872
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
57 " Nothing happens with invalid buffer number
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
58 call term_wait(1234)
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
59
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 call term_wait(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 " Must still work after the job ended.
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 let g:job = term_getjob(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 call WaitFor('job_status(g:job) == "dead"')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call term_wait(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 exe buf . 'bwipe'
11872
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
70 call delete('Xtext')
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 endfunc