aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Su <g4691821@gmail.com>2020-01-20 20:06:38 +0800
committerBilly Su <g4691821@gmail.com>2020-01-22 17:30:43 +0800
commit041ec8997a7f613f2ca13bf339c652f117fcb809 (patch)
tree1cd16306bc82beee6dcbc0a9ca611c051deacac4
parent270cd623efd50a22fe77a7f868ee7569e95a9acc (diff)
downloadrneovim-041ec8997a7f613f2ca13bf339c652f117fcb809.tar.gz
rneovim-041ec8997a7f613f2ca13bf339c652f117fcb809.tar.bz2
rneovim-041ec8997a7f613f2ca13bf339c652f117fcb809.zip
Fix f_jobstop() failed loudly
The return value of jobstop() @return 1 for valid job id 0 for invalid id, including jobs have exited or stopped
-rw-r--r--runtime/doc/eval.txt3
-rw-r--r--src/nvim/eval.c2
-rw-r--r--test/functional/core/job_spec.lua17
3 files changed, 16 insertions, 6 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index cd02449475..69b8b3cf39 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -5502,6 +5502,9 @@ jobstop({id}) *jobstop()*
(if any) will be invoked.
See |job-control|.
+ Returns 1 for valid job id, 0 for invalid id, including jobs have
+ exited or stopped.
+
jobwait({jobs}[, {timeout}]) *jobwait()*
Waits for jobs and their |on_exit| handlers to complete.
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 797c61a482..5eec44a7b7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -12706,7 +12706,7 @@ static void f_jobstop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
- Channel *data = find_job(argvars[0].vval.v_number, true);
+ Channel *data = find_job(argvars[0].vval.v_number, false);
if (!data) {
return;
}
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index b63b868127..57e6f4fd63 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -306,16 +306,16 @@ describe('jobs', function()
end))
end)
- it('disallows jobsend/stop on a non-existent job', function()
+ it('disallows jobsend on a non-existent job', function()
eq(false, pcall(eval, "jobsend(-1, 'lol')"))
- eq(false, pcall(eval, "jobstop(-1)"))
+ eq(0, eval('jobstop(-1)'))
end)
- it('disallows jobstop twice on the same job', function()
+ it('jobstop twice on the stopped or exited job return 0', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
neq(0, eval('j'))
- eq(true, pcall(eval, "jobstop(j)"))
- eq(false, pcall(eval, "jobstop(j)"))
+ eq(1, eval("jobstop(j)"))
+ eq(0, eval("jobstop(j)"))
end)
it('will not leak memory if we leave a job running', function()
@@ -919,6 +919,13 @@ describe('jobs', function()
end)
end)
+ it('jobstop on same id before stopped', function()
+ nvim('command', 'let j = jobstart(["cat", "-"], g:job_opts)')
+ neq(0, eval('j'))
+
+ eq({1, 0}, eval('[jobstop(j), jobstop(j)]'))
+ end)
+
describe('running tty-test program', function()
if helpers.pending_win32(pending) then return end
local function next_chunk()