diff --git a/mod/completion/function/analysis.zsh b/mod/completion/function/analysis.zsh index 973dcea..969ab6d 100644 --- a/mod/completion/function/analysis.zsh +++ b/mod/completion/function/analysis.zsh @@ -10,8 +10,6 @@ z.completion.function._candidates() { local prefix=$1 local function_names=("${z_completion_function_names[@]}") - z.int.is.zero ${#function_names[@]} && return 1 - local candidates=() for function_name in $function_names; do if z.str.start_with "$function_name" "z." && diff --git a/mod/completion/process.zsh b/mod/completion/process.zsh index f684214..1c34f49 100644 --- a/mod/completion/process.zsh +++ b/mod/completion/process.zsh @@ -15,10 +15,10 @@ z.completion.enable() { z.completion.is._interactive || return 0 z.completion.cache.build._names - z.completion.compdef._ignore_private || return 1 + z.completion.compdef._ignore_private z.completion.compdef._register || return 1 autoload -Uz add-zsh-hook - add-zsh-hook zshexit z.completion.cache._cancel || return 1 + add-zsh-hook zshexit z.completion.cache._cancel z.completion.cache._cancel z.job.run \ diff --git a/mod/job/analysis.zsh b/mod/job/analysis.zsh index b613c89..9276718 100644 --- a/mod/job/analysis.zsh +++ b/mod/job/analysis.zsh @@ -11,7 +11,7 @@ z.job.status() { z.arg.named id "$@" && local id=$REPLY z.is.null "$id" && return 1 - z.job.file._path id=$id name=status || return 1 + z.job.file._path id=$id name=status local status_file=$REPLY z.file.exists "$status_file" || return 1 diff --git a/mod/job/file/analysis.zsh b/mod/job/file/analysis.zsh index 61eaedb..03c9c83 100644 --- a/mod/job/file/analysis.zsh +++ b/mod/job/file/analysis.zsh @@ -53,6 +53,6 @@ z.job.file._path() { z.is.null "$id" && return 1 z.is.null "$name" && return 1 - z.job.file._dir id=$id || return 1 + z.job.file._dir id=$id z.return "$REPLY/$name" } diff --git a/mod/job/process.zsh b/mod/job/process.zsh index 3e9f4e2..98f0e30 100644 --- a/mod/job/process.zsh +++ b/mod/job/process.zsh @@ -25,7 +25,7 @@ z.job.run() { name="$name" \ command="$command" \ on_success="$on_success" \ - on_failure="$on_failure" || return 1 + on_failure="$on_failure" local -a prepared=("${REPLY[@]}") local id=$prepared[1] local dir=$prepared[2] diff --git a/mod/job/run/process.zsh b/mod/job/run/process.zsh index 2be558f..478d87e 100644 --- a/mod/job/run/process.zsh +++ b/mod/job/run/process.zsh @@ -1,11 +1,11 @@ -# prepare a job directory +# prepare a job directory after argument validation # # $name: job name # $command: child function name # $on_success?: parent success callback function name # $on_failure?: parent failure callback function name # REPLY: job id and job directory -# return: 0|1 +# return: null # # example: # z.job.run._prepare name=example command=z.example.build @@ -15,9 +15,6 @@ z.job.run._prepare() { z.arg.named on_success "$@" && local on_success=$REPLY z.arg.named on_failure "$@" && local on_failure=$REPLY - z.is.null "$name" && return 1 - z.is.null "$command" && return 1 - z.job.file._jobs && local jobs_dir=$REPLY z.dir.exists "$jobs_dir" || z.dir.make path="$jobs_dir" diff --git a/mod/wtproxy/config/analysis.zsh b/mod/wtproxy/config/analysis.zsh index 65f8048..f053545 100644 --- a/mod/wtproxy/config/analysis.zsh +++ b/mod/wtproxy/config/analysis.zsh @@ -6,7 +6,7 @@ # example: # z.wtproxy._config z.wtproxy._config() { - z.wtproxy._config.values || return 1 + z.wtproxy._config.values local -A config=("${(@)REPLY}") z.wtproxy._config.file.default_project || { diff --git a/mod/wtproxy/port/analysis.zsh b/mod/wtproxy/port/analysis.zsh index 69312f7..aafee38 100644 --- a/mod/wtproxy/port/analysis.zsh +++ b/mod/wtproxy/port/analysis.zsh @@ -26,7 +26,7 @@ z.wtproxy._port.proxies() { z.wtproxy._port.keys.from_config config for port_key in ${(@)REPLY}; do - z.wtproxy._port.worktree.index $port_key || return 1 + z.wtproxy._port.worktree.index $port_key local port_index=$REPLY z.wtproxy._port.proxy.key $port_index local config_key=$REPLY diff --git a/mod/wtproxy/proxy/is/operator.zsh b/mod/wtproxy/proxy/is/operator.zsh index 0490ea3..bb7da2f 100644 --- a/mod/wtproxy/proxy/is/operator.zsh +++ b/mod/wtproxy/proxy/is/operator.zsh @@ -31,7 +31,6 @@ z.wtproxy._proxy.is.pid() { z.is.null "$pid" && return 1 z.io.null kill -0 "$pid" || return 1 - local command_line - command_line=$(ps -p "$pid" -o command= 2>/dev/null) || return 1 + local command_line=$(ps -p "$pid" -o command= 2>/dev/null) z.str.includes "$command_line" "z.wtproxy.start._serve" } diff --git a/test/mod/completion/cache/process_test.zsh b/test/mod/completion/cache/process_test.zsh index 99759c9..36a6221 100644 --- a/test/mod/completion/cache/process_test.zsh +++ b/test/mod/completion/cache/process_test.zsh @@ -81,6 +81,21 @@ z.t.describe "z.completion.cache._cancel"; { } } + z.t.context "jobの取消に失敗した場合"; { + z.t.it "補完側のIDを破棄して成功する"; { + local z_completion_cache_job_id=cache-job + z.t.mock name="z.job.status" behavior="z.return running" + z.t.mock name="z.job.cancel" behavior="return 1" + + z.completion.cache._cancel + local result_code=$? + local remaining_id=$z_completion_cache_job_id + + z.t.expect "$result_code" 0 + z.t.expect.is.null "$remaining_id" + } + } + z.t.context "補完jobがない場合"; { z.t.it "他のjobに触れず成功する"; { local z_completion_cache_job_id="" diff --git a/test/mod/completion/process_test.zsh b/test/mod/completion/process_test.zsh index 1e65e8e..8d47b8c 100644 --- a/test/mod/completion/process_test.zsh +++ b/test/mod/completion/process_test.zsh @@ -58,17 +58,23 @@ z.t.describe "z.completion.enable"; { } z.t.context "private除外設定に失敗した場合"; { - z.t.it "jobを起動しない"; { + z.t.it "補完登録とcache jobの起動を続ける"; { + local z_completion_cache_job_id="" + local -a zshexit_functions=() + local -a completion_calls=() z.t.mock name="z.completion.is._interactive" behavior="return 0" z.t.mock name="z.completion.compdef._ignore_private" behavior="return 1" - z.t.mock name="z.completion.compdef._register" behavior="return 0" - z.t.mock name="z.job.run" behavior="z.return job-id" + z.t.mock name="z.completion.compdef._register" behavior='completion_calls+=(register); return 0' + z.t.mock name="z.job.run" behavior='completion_calls+=(job); z.return job-id' z.completion.enable + local result_code=$? + local result_reply=$REPLY - z.t.expect.status.is.false skip_unmock=true - z.t.mock.result name="z.job.run" - z.t.expect.reply "" + z.t.expect "$result_code" 0 skip_unmock=true + z.t.expect "$result_reply" job-id skip_unmock=true + z.t.expect "$completion_calls" "register job" skip_unmock=true + z.t.expect "$zshexit_functions" z.completion.cache._cancel } } diff --git a/test/mod/wtproxy/proxy/is/operator_test.zsh b/test/mod/wtproxy/proxy/is/operator_test.zsh index f43260e..8b0816a 100644 --- a/test/mod/wtproxy/proxy/is/operator_test.zsh +++ b/test/mod/wtproxy/proxy/is/operator_test.zsh @@ -38,4 +38,15 @@ z.t.describe "z.wtproxy._proxy.is.pid"; { z.t.expect.status.is.false } } + + z.t.context "pid確認後にprocessが終了した場合"; { + z.t.it "commandを取得できないためfalseを返す"; { + z.t.mock name="kill" behavior="return 0" + z.t.mock name="ps" behavior="return 1" + + z.wtproxy._proxy.is.pid 12345 + + z.t.expect.status.is.false + } + } }