diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-08-11 19:12:11 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-08-11 19:12:11 +0200 |
commit | 05aafed54b50b602315ae55d83a7d089804cecb0 (patch) | |
tree | 5ba15103a30540de184b50ca8d82a7adaa2efd4d /src/testdir | |
parent | 76ca1b4041db71df899a40d2ab1701af4f19cb2a (diff) | |
download | vim-git-05aafed54b50b602315ae55d83a7d089804cecb0.tar.gz |
patch 8.0.0902: cannot specify directory or environment for a jobv8.0.0902
Problem: Cannot specify directory or environment for a job.
Solution: Add the "cwd" and "env" arguments to job options. (Yasuhiro
Matsumoto, closes #1160)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_channel.vim | 39 | ||||
-rw-r--r-- | src/testdir/test_terminal.vim | 45 |
2 files changed, 77 insertions, 7 deletions
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim index c988968bb..42f0810ee 100644 --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -1664,6 +1664,45 @@ func Test_read_from_terminated_job() call assert_equal(1, g:linecount) endfunc +func Test_env() + if !has('job') + return + endif + + let s:envstr = '' + if has('win32') + call job_start(['cmd', '/c', 'echo %FOO%'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'env':{'FOO': 'bar'}}) + else + call job_start([&shell, &shellcmdflag, 'echo $FOO'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'env':{'FOO': 'bar'}}) + endif + call WaitFor('"" != s:envstr') + call assert_equal("bar", s:envstr) + unlet s:envstr +endfunc + +func Test_cwd() + if !has('job') + return + endif + + let s:envstr = '' + if has('win32') + let expect = $TEMP + call job_start(['cmd', '/c', 'echo %CD%'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'cwd': expect}) + else + let expect = $HOME + call job_start(['pwd'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'cwd': expect}) + endif + call WaitFor('"" != s:envstr') + let expect = substitute(expect, '[/\\]$', '', '') + let s:envstr = substitute(s:envstr, '[/\\]$', '', '') + if $CI != '' && stridx(s:envstr, '/private/') == 0 + let s:envstr = s:envstr[8:] + endif + call assert_equal(expect, s:envstr) + unlet s:envstr +endfunc + function Ch_test_close_lambda(port) let handle = ch_open('localhost:' . a:port, s:chopt) if ch_status(handle) == "fail" diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim index 89a784b34..9cc3a55cf 100644 --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -8,8 +8,8 @@ source shared.vim " Open a terminal with a shell, assign the job to g:job and return the buffer " number. -func Run_shell_in_terminal() - let buf = term_start(&shell) +func Run_shell_in_terminal(options) + let buf = term_start(&shell, a:options) let termlist = term_list() call assert_equal(1, len(termlist)) @@ -32,7 +32,7 @@ func Stop_shell_in_terminal(buf) endfunc func Test_terminal_basic() - let buf = Run_shell_in_terminal() + let buf = Run_shell_in_terminal({}) if has("unix") call assert_match("^/dev/", job_info(g:job).tty) call assert_match("^/dev/", term_gettty('')) @@ -51,7 +51,7 @@ func Test_terminal_basic() endfunc func Test_terminal_make_change() - let buf = Run_shell_in_terminal() + let buf = Run_shell_in_terminal({}) call Stop_shell_in_terminal(buf) call term_wait(buf) @@ -65,7 +65,7 @@ func Test_terminal_make_change() endfunc func Test_terminal_wipe_buffer() - let buf = Run_shell_in_terminal() + let buf = Run_shell_in_terminal({}) call assert_fails(buf . 'bwipe', 'E517') exe buf . 'bwipe!' call WaitFor('job_status(g:job) == "dead"') @@ -76,7 +76,7 @@ func Test_terminal_wipe_buffer() endfunc func Test_terminal_hide_buffer() - let buf = Run_shell_in_terminal() + let buf = Run_shell_in_terminal({}) quit for nr in range(1, winnr('$')) call assert_notequal(winbufnr(nr), buf) @@ -266,9 +266,11 @@ func Test_terminal_size() endfunc func Test_finish_close() + return + " TODO: use something that takes much less than a whole second + echo 'This will take five seconds...' call assert_equal(1, winnr('$')) - " TODO: use something that takes much less than a whole second if has('win32') let cmd = $windir . '\system32\timeout.exe 1' else @@ -304,3 +306,32 @@ func Test_finish_close() bwipe endfunc + +func Test_terminal_cwd() + if !has('unix') + return + endif + call mkdir('Xdir') + let buf = term_start('pwd', {'cwd': 'Xdir'}) + sleep 100m + call term_wait(buf) + call assert_equal(getcwd() . '/Xdir', getline(1)) + + exe buf . 'bwipe' + call delete('Xdir', 'rf') +endfunc + +func Test_terminal_env() + if !has('unix') + return + endif + let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) + call term_wait(buf) + call term_sendkeys(buf, "echo $TESTENV\r") + call term_wait(buf) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + call assert_equal('correct', getline(2)) + + exe buf . 'bwipe' +endfunc |