Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromneovim/neovim

Commit71e2c49

Browse files
justinmkclason
authored andcommitted
refactor(tests): introduce testprg()
Also:- Add a describe('shell :!') section to system_spec.- Make the test forneovim#16271 work on systems without powershell.
1 parent175892f commit71e2c49

22 files changed

+116
-104
lines changed

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ if(BUSTED_PRG)
655655
list(APPEND TEST_TARGET_ARGS"USES_TERMINAL")
656656

657657
set(UNITTEST_PREREQS nvim-test unittest-headers)
658-
set(FUNCTIONALTEST_PREREQS nvim printenv-test printargs-test shell-test streams-test tty-test${GENERATED_HELP_TAGS})
658+
set(FUNCTIONALTEST_PREREQS nvim printenv-test printargs-test shell-testpwsh-teststreams-test tty-test${GENERATED_HELP_TAGS})
659659
set(BENCHMARK_PREREQS nvim tty-test)
660660

661661
# Useful for automated build systems, if they want to manually run the tests.

‎src/nvim/ex_cmds.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,11 +1577,11 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
15771577
size_tlen=STRLEN(cmd)+1;// At least enough space for cmd + NULL.
15781578

15791579
len+=is_fish_shell ?sizeof("begin; ""; end")-1
1580-
:is_pwsh ?STRLEN("Start-Process ")
1580+
:is_pwsh ?sizeof("Start-Process ")
15811581
:sizeof("("")")-1;
15821582

15831583
if (itmp!=NULL) {
1584-
len+=is_pwsh ?STRLEN(itmp)+STRLEN(" -RedirectStandardInput ")
1584+
len+=is_pwsh ?STRLEN(itmp)+sizeof(" -RedirectStandardInput ")
15851585
:STRLEN(itmp)+sizeof(" { "" < "" } ")-1;
15861586
}
15871587
if (otmp!=NULL) {
@@ -1609,16 +1609,16 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
16091609
}else {
16101610
xstrlcat(buf," < ",len-1);
16111611
}
1612-
xstrlcat(buf, (constchar*)itmp,len-1);
1612+
xstrlcat(buf, (char*)itmp,len-1);
16131613
}
16141614
#else
16151615
// For shells that don't understand braces around commands, at least allow
16161616
// the use of commands in a pipe.
16171617
if (is_pwsh) {
16181618
xstrlcpy(buf,"Start-Process ",len);
1619-
xstrlcat(buf,(char*)cmd,len);
1619+
xstrlcat(buf,cmd,len);
16201620
}else {
1621-
xstrlcpy(buf,(char*)cmd,len);
1621+
xstrlcpy(buf,cmd,len);
16221622
}
16231623
if (itmp!=NULL) {
16241624
// If there is a pipe, we have to put the '<' in front of it.
@@ -1635,9 +1635,9 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
16351635
}else {
16361636
xstrlcat(buf," < ",len);
16371637
}
1638-
xstrlcat(buf,(constchar*)itmp,len);
1638+
xstrlcat(buf,itmp,len);
16391639
if (*p_shq==NUL) {
1640-
constchar*constp=find_pipe((constchar*)cmd);
1640+
constchar*constp=find_pipe(cmd);
16411641
if (p!=NULL) {
16421642
xstrlcat(buf," ",len-1);// Insert a space before the '|' for DOS
16431643
xstrlcat(buf,p,len-1);

‎test/functional/autocmd/termxx_spec.lua‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
localluv=require('luv')
22
localhelpers=require('test.functional.helpers')(after_each)
33

4-
localclear,command,nvim,nvim_dir=
5-
helpers.clear,helpers.command,helpers.nvim,helpers.nvim_dir
4+
localclear,command,nvim,testprg=
5+
helpers.clear,helpers.command,helpers.nvim,helpers.testprg
66
localeval,eq,neq,retry=
77
helpers.eval,helpers.eq,helpers.neq,helpers.retry
88
localok=helpers.ok
@@ -12,7 +12,7 @@ local iswin = helpers.iswin
1212
describe('autocmd TermClose',function()
1313
before_each(function()
1414
clear()
15-
nvim('set_option','shell',nvim_dir..'/shell-test')
15+
nvim('set_option','shell',testprg('shell-test'))
1616
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
1717
end)
1818

‎test/functional/core/job_spec.lua‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
localhelpers=require('test.functional.helpers')(after_each)
22
localclear,eq,eval,exc_exec,feed_command,feed,insert,neq,next_msg,nvim,
3-
nvim_dir,ok,source,write_file,mkdir,rmdir=helpers.clear,
3+
testprg,ok,source,write_file,mkdir,rmdir=helpers.clear,
44
helpers.eq,helpers.eval,helpers.exc_exec,helpers.feed_command,helpers.feed,
55
helpers.insert,helpers.neq,helpers.next_msg,helpers.nvim,
6-
helpers.nvim_dir,helpers.ok,helpers.source,
6+
helpers.testprg,helpers.ok,helpers.source,
77
helpers.write_file,helpers.mkdir,helpers.rmdir
88
localassert_alive=helpers.assert_alive
99
localcommand=helpers.command
@@ -1042,8 +1042,7 @@ describe('jobs', function()
10421042
return a:data
10431043
endfunction
10441044
]])
1045-
localext=iswin()and'.exe'or''
1046-
insert(nvim_dir..'/tty-test'..ext)-- Full path to tty-test.
1045+
insert(testprg('tty-test'))
10471046
nvim('command','let g:job_opts.pty = 1')
10481047
nvim('command','let exec = [expand("<cfile>:p")]')
10491048
nvim('command',"let j = jobstart(exec, g:job_opts)")

‎test/functional/ex_cmds/ls_spec.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local eq = helpers.eq
55
localeval=helpers.eval
66
localfeed=helpers.feed
77
localnvim=helpers.nvim
8-
localnvim_dir=helpers.nvim_dir
8+
localtestprg=helpers.testprg
99
localretry=helpers.retry
1010

1111
describe(':ls',function()
@@ -14,7 +14,7 @@ describe(':ls', function()
1414
end)
1515

1616
it('R, F for :terminal buffers',function()
17-
nvim('set_option','shell',string.format('"%s" INTERACT',nvim_dir..'/shell-test'))
17+
nvim('set_option','shell',string.format('"%s" INTERACT',testprg('shell-test')))
1818

1919
command('edit foo')
2020
command('set hidden')

‎test/functional/ex_cmds/make_spec.lua‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local eval = helpers.eval
44
localhas_powershell=helpers.has_powershell
55
localmatches=helpers.matches
66
localnvim=helpers.nvim
7-
localnvim_dir=helpers.nvim_dir
7+
localtestprg=helpers.testprg
88

99
describe(':make',function()
1010
clear()
@@ -22,7 +22,7 @@ describe(':make', function()
2222
end)
2323

2424
it('captures stderr & non zero exit code #14349',function ()
25-
nvim('set_option','makeprg',nvim_dir..'/shell-test foo')
25+
nvim('set_option','makeprg',testprg('shell-test')..' foo')
2626
localout=eval('execute("make")')
2727
-- Make program exit code correctly captured
2828
matches('\nshell returned 3',out)
@@ -31,7 +31,7 @@ describe(':make', function()
3131
end)
3232

3333
it('captures stderr & zero exit code #14349',function ()
34-
nvim('set_option','makeprg',nvim_dir..'/shell-test')
34+
nvim('set_option','makeprg',testprg('shell-test'))
3535
localout=eval('execute("make")')
3636
-- Ensure there are no "shell returned X" messages between
3737
-- command and last line (indicating zero exit)

‎test/functional/fixtures/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ add_executable(tty-test EXCLUDE_FROM_ALL tty-test.c)
22
target_link_libraries(tty-test${LIBUV_LIBRARIES})
33

44
add_executable(shell-testEXCLUDE_FROM_ALL shell-test.c)
5+
# Fake pwsh (powershell) for testing make_filter_cmd(). #16271
6+
add_executable(pwsh-testEXCLUDE_FROM_ALL shell-test.c)
57
add_executable(printargs-testEXCLUDE_FROM_ALL printargs-test.c)
68
add_executable(printenv-testEXCLUDE_FROM_ALL printenv-test.c)
79
if(WIN32)

‎test/functional/helpers.lua‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,17 @@ function module.has_powershell()
501501
returnmodule.eval('executable("'..(iswin()and'powershell'or'pwsh')..'")')==1
502502
end
503503

504-
functionmodule.set_shell_powershell()
505-
localshell=iswin()and'powershell'or'pwsh'
506-
assert(module.has_powershell())
504+
--- Sets Nvim shell to powershell.
505+
---
506+
--- @paramfake (boolean)If true,a fake will be used if powershell is not
507+
--- found on the system.
508+
--- @returns true if powershell was found on the system,else false.
509+
functionmodule.set_shell_powershell(fake)
510+
localfound=module.has_powershell()
511+
ifnotfakethen
512+
assert(found)
513+
end
514+
localshell=foundand (iswin()and'powershell'or'pwsh')ormodule.testprg('pwsh-test')
507515
localset_encoding='[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
508516
localcmd=set_encoding..'Remove-Item -Force'..table.concat(iswin()
509517
and {'alias:cat','alias:echo','alias:sleep'}
@@ -515,6 +523,7 @@ function module.set_shell_powershell()
515523
let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
516524
let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait'
517525
]])
526+
returnfound
518527
end
519528

520529
functionmodule.nvim(method, ...)
@@ -774,11 +783,21 @@ function module.get_pathsep()
774783
returniswin()and'\\'or'/'
775784
end
776785

786+
--- Gets the filesystem root dir, namely "/" or "C:/".
777787
functionmodule.pathroot()
778788
localpathsep=package.config:sub(1,1)
779789
returniswin()and (module.nvim_dir:sub(1,2)..pathsep)or'/'
780790
end
781791

792+
--- Gets the full `…/build/bin/{name}` path of a test program produced by
793+
--- `test/functional/fixtures/CMakeLists.txt`.
794+
---
795+
--- @paramname (string)Name of the test program.
796+
functionmodule.testprg(name)
797+
localext=module.iswin()and'.exe'or''
798+
return ('%s/%s%s'):format(module.nvim_dir,name,ext)
799+
end
800+
782801
-- Returns a valid, platform-independent Nvim listen address.
783802
-- Useful for communicating with child instances.
784803
functionmodule.new_pipename()

‎test/functional/terminal/cursor_spec.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
22
localScreen=require('test.functional.ui.screen')
33
localthelpers=require('test.functional.terminal.helpers')
44
localfeed,clear,nvim=helpers.feed,helpers.clear,helpers.nvim
5-
localnvim_dir,command=helpers.nvim_dir,helpers.command
5+
localtestprg,command=helpers.testprg,helpers.command
66
localnvim_prog=helpers.nvim_prog
77
localeq,eval=helpers.eq,helpers.eval
88
localfeed_command=helpers.feed_command
@@ -149,7 +149,7 @@ describe('cursor with customized highlighting', function()
149149
[3]= {bold=true},
150150
})
151151
screen:attach({rgb=false})
152-
command('call termopen(["'..nvim_dir..'/tty-test"])')
152+
command('call termopen(["'..testprg('tty-test')..'"])')
153153
feed_command('startinsert')
154154
end)
155155

‎test/functional/terminal/edit_spec.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local screen = require('test.functional.ui.screen')
33

44
localcurbufmeths=helpers.curbufmeths
55
localcurwinmeths=helpers.curwinmeths
6-
localnvim_dir=helpers.nvim_dir
6+
localtestprg=helpers.testprg
77
localcommand=helpers.command
88
localfuncs=helpers.funcs
99
localmeths=helpers.meths
@@ -21,7 +21,7 @@ describe(':edit term://*', function()
2121

2222
before_each(function()
2323
clear()
24-
meths.set_option('shell',nvim_dir..'/shell-test')
24+
meths.set_option('shell',testprg('shell-test'))
2525
meths.set_option('shellcmdflag','EXE')
2626
end)
2727

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp