Skip to content

Commit 1c1d684

Browse files
committed
prompt: Update, test select_option validation err
1 parent 45816c7 commit 1c1d684

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/prompt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# Returns:
3131
# zero if `result_var` contains the user's selection, nonzero otherwise
3232
@go.select_option() {
33-
@go.validate_identifier_or_die 'Result variable name' "$1"
33+
@go.validate_identifier_or_die 'Input selection variable name' "$1"
3434

3535
local __go_selected_option
3636
select __go_selected_option in "${@:2}"; do

tests/prompt/select-option.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ teardown() {
1818
@go.remove_test_go_rootdir
1919
}
2020

21+
@test "$SUITE: error if selection variable not a valid identifier" {
22+
@go.create_test_go_script '. "$_GO_USE_MODULES" "prompt"' \
23+
'@go.select_option "invalid;"'
24+
25+
run "$TEST_GO_SCRIPT"
26+
assert_failure
27+
28+
local err_msg='Input selection variable name "invalid;" for '
29+
err_msg+='@go.select_option contains invalid identifier characters at:'
30+
31+
assert_lines_match "^${err_msg}\$" \
32+
"^ $TEST_GO_SCRIPT:[0-9] main$"
33+
}
34+
2135
@test "$SUITE: no options exits instantly" {
2236
run "$TEST_GO_SCRIPT"
2337
assert_failure ''

0 commit comments

Comments
 (0)