1
1
mirror of https://github.com/wader/fq.git synced 2024-12-29 16:42:06 +03:00

Merge pull request #198 from wader/interp-handle-cancel

interp,cli: Handle ctrl-c properly
This commit is contained in:
Mattias Wadman 2022-03-15 22:43:41 +01:00 committed by GitHub
commit b20ae90744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 16 deletions

View File

@ -23,7 +23,9 @@ testjq: fq
.PHONY: testcli
testcli: fq
@pkg/cli/test.sh ./fq pkg/cli/test.exp
@pkg/cli/test_exp.sh ./fq pkg/cli/test_repl.exp
@pkg/cli/test_exp.sh ./fq pkg/cli/test_cli_ctrlc.exp
@pkg/cli/test_exp.sh ./fq pkg/cli/test_cli_ctrld.exp
.PHONY: cover
cover: COVER=-cover -coverpkg=./... -coverprofile=cover.out

View File

@ -0,0 +1,19 @@
#!/usr/bin/env expect
log_user 1
set timeout 3
expect_after {
timeout {exit 1}
}
spawn sh -c "cat | fq 2>&1"
sleep 1
# ctrl-c
send "\x03"
expect eof
# should not have outputted anything except maybe "^C", seems flakey
if { $expect_out(buffer) != "" && $expect_out(buffer) != "^C" } {
exit 1
}

View File

@ -0,0 +1,15 @@
#!/usr/bin/env expect
log_user 1
set timeout 3
expect_after {
timeout {exit 1}
}
spawn sh -c "cat | fq 2>&1"
sleep 1
# ctrl-d
send "\x04"
expect "failed to decode"
expect eof

View File

@ -9,48 +9,49 @@ expect_after {
timeout {exit 1}
}
proc expect_prompt {} {
global spawn_id
sleep 0.2
expect *
send "\n"
expect "> "
}
spawn sh -c "NO_DECODE_PROGRESS=1 fq -o color=false -i . pkg/interp/testdata/test.mp3 2>&1"
expect "mp3> "
expect_prompt
send ".\n"
expect "footers"
expect "mp3> "
# test completion
send ".frames | mp3_fr\t"
expect "mp3_frame"
send "\n"
expect "side_info"
expect "mp3> "
expect_prompt
# test interrupt multiple outputs
send "range(100000) | d\n"
expect "123"
# ctrl-c
send "\x03"
expect "mp3> "
expect_prompt
# test interrupt multiple outputs implicit display
send "range(100000)\n"
expect "123"
# ctrl-c
send "\x03"
expect "mp3> "
expect_prompt
# test interrupt big json output
send "\[range(100000)\] | d\n"
expect "123"
# ctrl-c
send "\x03"
expect "mp3> "
expect_prompt
# test interrupt big json output implicit display
send "\[range(100000)\]\n"
expect "123"
# ctrl-c
send "\x03"
expect "mp3> "
expect_prompt
# test exit
# ctrl-d

View File

@ -130,9 +130,11 @@ def _cli_eval_on_expr_error:
| _cli_last_expr_error($err) as $_
| (_error_str([input_filename // empty]) | printerrln)
);
# other expr error, should not happen, report and halt
# other expr error, other errors then cancel should not happen, report and halt
def _cli_eval_on_error:
halt_error(_exit_code_expr_error);
if .error | _is_context_canceled_error then (null | halt_error(_exit_code_expr_error))
else halt_error(_exit_code_expr_error)
end;
# could not compile expr, report and halt
def _cli_eval_on_compile_error:
( .error