diff --git a/commands/ask b/commands/ask index 632ad41e5..1afa60516 100755 --- a/commands/ask +++ b/commands/ask @@ -7,6 +7,8 @@ function ask_test() ( eval-tester --name='receive default response by timeout and no input' --stdout='a default response' \ -- ask --skip-default --question='What is your response?' --default='a default response' + local down=$'\e[B' + { sleep 3 __print_line @@ -51,7 +53,7 @@ function ask_test() ( # move down and change to custom response sleep 3 - printf $'\eOB' + __print_string "$down" sleep 3 __print_line @@ -289,7 +291,7 @@ function ask_() ( # treat empty string and newline as default : elif [[ $__input_result =~ ^[[:cntrl:][:space:]]*$ ]]; then - # if it is only control characters, e.g. escape, and whitespace characters, then treat as empty + # if it is only control characters (e.g. escape) and whitespace characters, then treat as empty RESULT='' else # treat everything else as manual __input_result diff --git a/commands/choose b/commands/choose index 8a8d5adf6..896fda431 100755 --- a/commands/choose +++ b/commands/choose @@ -12,6 +12,11 @@ function choose_test() ( local up=$'\e[A' down=$'\e[B' right=$'\e[C' left=$'\e[D' home=$'\e[H' end=$'\e[F' insert=$'\e[2~' delete=$'\e[3~' page_up=$'\e[5~' page_down=$'\e[6~' backspace=$'\177' escape=$'\e' tab=$'\t' backtab=$'\e[Z' all=$'\x01' # enter=$'\x0a' space=' ' + local \ + timeout_optional='[ timed out: not required ]' \ + timeout_required='[ input failure: timed out: required ]' \ + timeout_defaults='[ timed out: used default ]' + # TESTS WITHOUT INTERACTION # as we are checking stderr, do not use color for these tests, as gets too complicated @@ -29,66 +34,66 @@ function choose_test() ( -- env COLOR=no choose 'q' 'd' --multi --index --skip-default --default=b --default=c -- a b c # timeout optional - eval-tester --name='receive no response by timeout with no input and optional' --stderr='q [timed out: not required]' \ + eval-tester --name='receive no response by timeout with no input and optional' --stderr="q $timeout_optional" \ -- env COLOR=no choose 'q' 'd' --timeout=5 -- a b c - eval-tester --name='receive no --index response by timeout with no input and optional' --stderr='q [timed out: not required]' \ + eval-tester --name='receive no --index response by timeout with no input and optional' --stderr="q $timeout_optional" \ -- env COLOR=no choose 'q' 'd' --index --timeout=5 -- a b c # timeout required - eval-tester --name='receive timeout response by timeout with no input and reqyured' --status='60' --stderr='q [input failure: timed out: required]' \ + eval-tester --name='receive timeout response by timeout with no input and reqyured' --status='60' --stderr="q $timeout_required" \ -- env COLOR=no choose 'q' 'd' --required --timeout=5 -- a b c - eval-tester --name='receive timeout --index response by timeout with no input and reqyured' --status='60' --stderr='q [input failure: timed out: required]' \ + eval-tester --name='receive timeout --index response by timeout with no input and reqyured' --status='60' --stderr="q $timeout_required" \ -- env COLOR=no choose 'q' 'd' --index --required --timeout=5 -- a b c # single mode, single defalut - eval-tester --name='receive default response by timeout with no input and optional' --stdout=b --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default response by timeout with no input and optional' --stdout=b --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --timeout=5 --default=b -- a b c - eval-tester --name='receive default --index response by timeout with no input and optional' --stdout=1 --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default --index response by timeout with no input and optional' --stdout=1 --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --index --timeout=5 --default=b -- a b c - eval-tester --name='receive default response by timeout with no input and required' --stdout=b --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default response by timeout with no input and required' --stdout=b --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --timeout=5 --default=b --required -- a b c - eval-tester --name='receive default --index response by timeout with no input and required' --stdout=1 --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default --index response by timeout with no input and required' --stdout=1 --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --index --timeout=5 --default=b --required -- a b c # single mode, so only the first match is selected - eval-tester --name='receive default first response by timeout with no input and optional' --stdout=b --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default first response by timeout with no input and optional' --stdout=b --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --timeout=5 --default-fuzzy=b -- a b bb c - eval-tester --name='receive default first --index response by timeout with no input and optional' --stdout=1 --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default first --index response by timeout with no input and optional' --stdout=1 --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --index --timeout=5 --default-fuzzy=b -- a b bb c - eval-tester --name='receive default first response by timeout with no input and required' --stdout=b --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default first response by timeout with no input and required' --stdout=b --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --timeout=5 --default-fuzzy=b --required -- a b bb c - eval-tester --name='receive default first --index response by timeout with no input and required' --stdout=1 --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default first --index response by timeout with no input and required' --stdout=1 --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --index --timeout=5 --default-fuzzy=b --required -- a b bb c # multi mode - eval-tester --name='receive default responses by timeout with no input and multi and optional' --stdout=$'b\nbb' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default responses by timeout with no input and multi and optional' --stdout=$'b\nbb' --stderr="q $timeout_defaults" \ -- env COLOR=no choose --multi 'q' 'd' --timeout=5 --default-fuzzy=b -- a b bb c - eval-tester --name='receive default --index responses by timeout with no input and multi and optional' --stdout=$'1\n2' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default --index responses by timeout with no input and multi and optional' --stdout=$'1\n2' --stderr="q $timeout_defaults" \ -- env COLOR=no choose --multi 'q' 'd' --index --timeout=5 --default-fuzzy=b -- a b bb c - eval-tester --name='receive default responses by timeout with no input and multi and required' --stdout=$'b\nbb' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default responses by timeout with no input and multi and required' --stdout=$'b\nbb' --stderr="q $timeout_defaults" \ -- env COLOR=no choose --multi 'q' 'd' --timeout=5 --default-fuzzy=b --required -- a b bb c - eval-tester --name='receive default --index responses by timeout with no input and multi and required' --stdout=$'1\n2' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive default --index responses by timeout with no input and multi and required' --stdout=$'1\n2' --stderr="q $timeout_defaults" \ -- env COLOR=no choose --multi 'q' 'd' --index --timeout=5 --default-fuzzy=b --required -- a b bb c # multiline defaults - eval-tester --name='receive multi-line default first response by timeout with no input' --stdout=$'b\nB' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive multi-line default first response by timeout with no input' --stdout=$'b\nB' --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --timeout=2 --default=$'b\nB' --defaults=$'c\nd' -- a $'b\nB' c d - eval-tester --name='receive multi-line default first --index response by timeout with no input' --stdout=1 --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive multi-line default first --index response by timeout with no input' --stdout=1 --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --index --timeout=2 --default=$'b\nB' --defaults=$'c\nd' -- a $'b\nB' c d - eval-tester --name='receive multi-line default responses by timeout with no input' --stdout=$'b\nB\nc\nd' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive multi-line default responses by timeout with no input' --stdout=$'b\nB\nc\nd' --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --multi --timeout=2 --default=$'b\nB' --defaults=$'c\nd' -- a $'b\nB' c d - eval-tester --name='receive multi-line default responses by timeout with no input' --stdout=$'1\n2\n3' --stderr='q [timed out: using defaults]' \ + eval-tester --name='receive multi-line default responses by timeout with no input' --stdout=$'1\n2\n3' --stderr="q $timeout_defaults" \ -- env COLOR=no choose 'q' 'd' --multi --index --timeout=2 --default=$'b\nB' --defaults=$'c\nd' -- a $'b\nB' c d # TESTS WITH INTERACTION diff --git a/commands/confirm b/commands/confirm index a4e7a4457..f08e19109 100755 --- a/commands/confirm +++ b/commands/confirm @@ -11,6 +11,8 @@ function confirm_test() ( # --ignore-stderr otherwise only \n^[[68;1R is output + local escape=$'\e' + { sleep 3 __print_line @@ -53,7 +55,7 @@ function confirm_test() ( { # press escape key sleep 3 - printf $'\x1b' + __print_string "$escape" } | eval-tester --name='receive abort response by escape key' --status=125 --ignore-stderr \ -- confirm --ppid=-1 --bool --timeout=5 -- 'What is your response?' diff --git a/commands/get-terminal-tty-support b/commands/get-terminal-tty-support index 3fae34d38..864539a28 100755 --- a/commands/get-terminal-tty-support +++ b/commands/get-terminal-tty-support @@ -16,51 +16,58 @@ function get_terminal_tty_support_test() ( # https://stackoverflow.com/a/54668834/130638 if ls /proc/$$/fdinfo/* >/dev/null 2>&1 || grep -q 'flags: 00$' /proc/$$/fdinfo/0; then - echo proc_pass + __print_lines proc_pass else - echo proc_fail + __print_lines proc_fail fi - ( (tty -s && echo tty_s_pass) || echo tty_s_fail) || : + # attempts at detection - ( (test -t 0 && echo test_t_stdin_pass) || echo test_t_stdin_fail) || : - ( (test -t 1 && echo test_t_stdout_pass) || echo test_t_stdout_fail) || : - ( (test -t 2 && echo test_t_stderr_pass) || echo test_t_stderr_fail) || : + # -c /dev/stdin to handle background in ssh -T + # note that if everything is captured, such as eval_capture with stdin modification, then this appears true + ( ([[ (-p /dev/stdin || -c /dev/stdin) && -p /dev/stdout && -p /dev/stderr ]] && ! (: >/dev/stdin) && __print_lines is_ssh_T_or_all_custom) || __print_lines is_neither_ssh_T_or_all_custom) || : + ( (! [[ -c /dev/stdin ]] && (: >/dev/stdin) && __print_lines is_CI) || __print_lines is_not_CI) || : - ( (test -p /dev/stdin && echo test_p_stdin_pass) || echo test_p_stdin_fail) || : - ( (test -p /dev/stdout && echo test_p_stdout_pass) || echo test_p_stdout_fail) || : - ( (test -p /dev/stderr && echo test_p_stderr_pass) || echo test_p_stderr_fail) || : - ( (test -p /dev/tty && echo test_p_tty_pass) || echo test_p_tty_fail) || : + ( (tty -s && __print_lines tty_s_pass) || __print_lines tty_s_fail) || : - ( (test -c /dev/stdin && echo test_c_stdin_pass) || echo test_c_stdin_fail) || : - ( (test -c /dev/stdout && echo test_c_stdout_pass) || echo test_c_stdout_fail) || : - ( (test -c /dev/stderr && echo test_c_stderr_pass) || echo test_c_stderr_fail) || : - ( (test -c /dev/tty && echo test_c_tty_pass) || echo test_c_tty_fail) || : + ( (test -t 0 && __print_lines test_t_stdin_pass) || __print_lines test_t_stdin_fail) || : + ( (test -t 1 && __print_lines test_t_stdout_pass) || __print_lines test_t_stdout_fail) || : + ( (test -t 2 && __print_lines test_t_stderr_pass) || __print_lines test_t_stderr_fail) || : + + ( (test -p /dev/stdin && __print_lines test_p_stdin_pass) || __print_lines test_p_stdin_fail) || : + ( (test -p /dev/stdout && __print_lines test_p_stdout_pass) || __print_lines test_p_stdout_fail) || : + ( (test -p /dev/stderr && __print_lines test_p_stderr_pass) || __print_lines test_p_stderr_fail) || : + ( (test -p /dev/tty && __print_lines test_p_tty_pass) || __print_lines test_p_tty_fail) || : + + ( (test -c /dev/stdin && __print_lines test_c_stdin_pass) || __print_lines test_c_stdin_fail) || : + ( (test -c /dev/stdout && __print_lines test_c_stdout_pass) || __print_lines test_c_stdout_fail) || : + ( (test -c /dev/stderr && __print_lines test_c_stderr_pass) || __print_lines test_c_stderr_fail) || : + ( (test -c /dev/tty && __print_lines test_c_tty_pass) || __print_lines test_c_tty_fail) || : # check if reading is even possible (If TIMEOUT is 0, read returns immediately, without trying to read any data, returning success only if input is available on the specified file descriptor.) - ( (read -t 0 && echo read_default_pass) || echo read_default_fail) || : - ( (read -t 0 /dev/stdin && echo noop_to_stdin_pass) || echo noop_to_stdin_fail) || : - ( (: >/dev/stdout && echo noop_to_stdout_pass) || echo noop_to_stdout_fail) || : - ( (: >/dev/stderr && echo noop_to_stderr_pass) || echo noop_to_stderr_fail) || : - ( (: >/dev/tty && echo noop_to_tty_pass) || echo noop_to_tty_fail) || : + ( (: >/dev/stdin && __print_lines noop_to_stdin_pass) || __print_lines noop_to_stdin_fail) || : + ( (: >/dev/stdout && __print_lines noop_to_stdout_pass) || __print_lines noop_to_stdout_fail) || : + ( (: >/dev/stderr && __print_lines noop_to_stderr_pass) || __print_lines noop_to_stderr_fail) || : + ( (: >/dev/tty && __print_lines noop_to_tty_pass) || __print_lines noop_to_tty_fail) || : - ( (: /dev/stdin && echo noop_bidirectonal_stdin_pass) || echo noop_bidirectonal_stdin_fail) || : - ( (: /dev/stdout && echo noop_bidirectonal_stdout_pass) || echo noop_bidirectonal_stdout_fail) || : - ( (: /dev/stderr && echo noop_bidirectonal_stderr_pass) || echo noop_bidirectonal_stderr_fail) || : - ( (: /dev/tty && echo noop_bidirectonal_tty_pass) || echo noop_bidirectonal_tty_fail) || : + ( (: /dev/stdin && __print_lines noop_bidirectonal_stdin_pass) || __print_lines noop_bidirectonal_stdin_fail) || : + ( (: /dev/stdout && __print_lines noop_bidirectonal_stdout_pass) || __print_lines noop_bidirectonal_stdout_fail) || : + ( (: /dev/stderr && __print_lines noop_bidirectonal_stderr_pass) || __print_lines noop_bidirectonal_stderr_fail) || : + ( (: /dev/tty && __print_lines noop_bidirectonal_tty_pass) || __print_lines noop_bidirectonal_tty_fail) || : } local stdout stderr @@ -113,6 +120,45 @@ function get_terminal_tty_support_test() ( __print_lines 'stderr =' echo-lines --indent=' ' --stdin <<<"$stderr" + __print_lines '' '### pipe to --stdoutvar --stderrvar ###' + stdout='' + stderr='' + __print_lines 'testing pipe' | eval_capture --stdoutvar=stdout --stderrvar=stderr -- __do_test + __print_lines 'stdout =' + echo-lines --indent=' ' --stdin <<<"$stdout" + __print_lines 'stderr =' + echo-lines --indent=' ' --stdin <<<"$stderr" + + __print_lines '' '### delayed pipe to --stdoutvar --stderrvar ###' + stdout='' + stderr='' + { + sleep 3 + __print_line + } | eval_capture --stdoutvar=stdout --stderrvar=stderr -- __do_test || : + __print_lines 'stdout =' + echo-lines --indent=' ' --stdin <<<"$stdout" + __print_lines 'stderr =' + echo-lines --indent=' ' --stdin <<<"$stderr" + + __print_lines '' '### <<< to --stdoutvar --stderrvar ###' + stdout='' + stderr='' + eval_capture --stdoutvar=stdout --stderrvar=stderr -- __do_test <<<'testing <<<' + __print_lines 'stdout =' + echo-lines --indent=' ' --stdin <<<"$stdout" + __print_lines 'stderr =' + echo-lines --indent=' ' --stdin <<<"$stderr" + + __print_lines '' '### < <(...) to --stdoutvar --stderrvar ###' + stdout='' + stderr='' + eval_capture --stdoutvar=stdout --stderrvar=stderr -- __do_test < <(__print_lines 'testing <<<') + __print_lines 'stdout =' + echo-lines --indent=' ' --stdin <<<"$stdout" + __print_lines 'stderr =' + echo-lines --indent=' ' --stdin <<<"$stderr" + echo-style --g1="TEST: $0" return 0 ) diff --git a/commands/is-interactive b/commands/is-interactive index 01ba941d3..431a5b07c 100755 --- a/commands/is-interactive +++ b/commands/is-interactive @@ -35,11 +35,8 @@ function is_interactive() ( # ===================================== # Action - if get-terminal-stdin-tty-support --quiet && ! is-ci; then - return 0 - else - return 1 - fi + get-terminal-stdin-tty-support --quiet && ! is-ci + return ) # fire if invoked standalone