Skip to content

Commit e9f6fd2

Browse files
committed
patch 8.0.1087: Test_terminal_cwd is flaky
Problem: Test_terminal_cwd is flaky. MS-Windows: term_start() "cwd" argument does not work. Solution: Wait for the condition to be true instead of using a sleep. Pass the directory to winpty.
1 parent 8696bba commit e9f6fd2

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/terminal.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
* in tl_scrollback are no longer used.
3939
*
4040
* TODO:
41-
* - check for memory leaks
4241
* - patch to use GUI or cterm colors for vterm. Yasuhiro, #2067
42+
* - when Normal background is not white or black, going to Terminal-Normal
43+
* mode does not clear correctly. Use the terminal background color to erase
44+
* the background.
45+
* - patch to add tmap, jakalope (Jacob Askeland) #2073
4346
* - Redirecting output does not work on MS-Windows.
4447
* - implement term_setsize()
4548
* - add test for giving error for invalid 'termsize' value.
@@ -3099,6 +3102,7 @@ term_and_job_init(
30993102
jobopt_T *opt)
31003103
{
31013104
WCHAR *cmd_wchar = NULL;
3105+
WCHAR *cwd_wchar = NULL;
31023106
channel_T *channel = NULL;
31033107
job_T *job = NULL;
31043108
DWORD error;
@@ -3126,6 +3130,8 @@ term_and_job_init(
31263130
cmd_wchar = enc_to_utf16(cmd, NULL);
31273131
if (cmd_wchar == NULL)
31283132
return FAIL;
3133+
if (opt->jo_cwd != NULL)
3134+
cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
31293135

31303136
job = job_alloc();
31313137
if (job == NULL)
@@ -3152,7 +3158,7 @@ term_and_job_init(
31523158
WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
31533159
NULL,
31543160
cmd_wchar,
3155-
NULL,
3161+
cwd_wchar,
31563162
NULL,
31573163
&winpty_err);
31583164
if (spawn_config == NULL)
@@ -3203,6 +3209,7 @@ term_and_job_init(
32033209

32043210
winpty_spawn_config_free(spawn_config);
32053211
vim_free(cmd_wchar);
3212+
vim_free(cwd_wchar);
32063213

32073214
create_vterm(term, term->tl_rows, term->tl_cols);
32083215

@@ -3226,8 +3233,8 @@ term_and_job_init(
32263233
failed:
32273234
if (argvar->v_type == VAR_LIST)
32283235
vim_free(ga.ga_data);
3229-
if (cmd_wchar != NULL)
3230-
vim_free(cmd_wchar);
3236+
vim_free(cmd_wchar);
3237+
vim_free(cwd_wchar);
32313238
if (spawn_config != NULL)
32323239
winpty_spawn_config_free(spawn_config);
32333240
if (channel != NULL)

src/testdir/test_terminal.vim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,13 @@ func Test_finish_open_close()
396396
endfunc
397397

398398
func Test_terminal_cwd()
399-
if !has('unix')
399+
if !executable('pwd')
400400
return
401401
endif
402402
call mkdir('Xdir')
403403
let buf = term_start('pwd', {'cwd': 'Xdir'})
404-
sleep 100m
405-
call term_wait(buf)
406-
call assert_equal(getcwd() . '/Xdir', getline(1))
404+
call WaitFor('"Xdir" == fnamemodify(getline(1), ":t")')
405+
call assert_equal('Xdir', fnamemodify(getline(1), ":t"))
407406

408407
exe buf . 'bwipe'
409408
call delete('Xdir', 'rf')
@@ -603,6 +602,8 @@ func Test_terminal_redir_file()
603602
call term_wait(buf)
604603
call WaitFor('len(readfile("Xfile")) > 0')
605604
call assert_match('123', readfile('Xfile')[0])
605+
let g:job = term_getjob(buf)
606+
call WaitFor('job_status(g:job) == "dead"')
606607
call delete('Xfile')
607608
bwipe
608609
endif

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1087,
772774
/**/
773775
1086,
774776
/**/

0 commit comments

Comments
 (0)