Skip to content

Commit

Permalink
[spec/stateful] Failing test cases for bind -x (#2229)
Browse files Browse the repository at this point in the history
  • Loading branch information
KingMob authored Jan 26, 2025
1 parent 41e5742 commit be2ee72
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
77 changes: 74 additions & 3 deletions spec/stateful/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from __future__ import print_function

import sys
import tempfile
import time

import harness
Expand Down Expand Up @@ -53,8 +52,11 @@ def bind_plain(sh):


@register(not_impl_shells=['dash', 'mksh'])
def bind_r(sh):
"test bind -r for removing bindings"
def bind_r_for_bind_x_osh_fn(sh):
"""
test bind -r for removing bindings to arbitrary cmds made with bind -x
(regular readline fn bind removal is tested in noninteractive builtin-bind.test.sh)
"""
expect_prompt(sh)

add_foo_fn(sh)
Expand Down Expand Up @@ -95,6 +97,75 @@ def bind_x(sh):
sh.expect("FOO")


@register(not_impl_shells=['dash', 'mksh'])
def bind_x_runtime_envvar_vals(sh):
"test bind -x for using env var runtime values (e.g., 'echo $PWD' should change with dir)"
expect_prompt(sh)

sh.sendline("export BIND_X_VAR=foo")

send_bind(sh, """-x '"\C-x\C-f": echo $BIND_X_VAR' """)
expect_prompt(sh)

sh.sendline("export BIND_X_VAR=bar")
expect_prompt(sh)

sh.sendcontrol('x')
sh.sendcontrol('f')
time.sleep(0.1)

sh.expect("bar")


@register(not_impl_shells=['dash', 'mksh'])
def bind_x_readline_line(sh):
"test bind -x for correctly setting $READLINE_LINE for the cmd"
expect_prompt(sh)

send_bind(sh, """-x '"\C-x\C-f": echo Current line is: $READLINE_LINE' """)
expect_prompt(sh)

sh.send('abcdefghijklmnopqrstuvwxyz')

sh.sendcontrol('x')
sh.sendcontrol('f')
time.sleep(0.1)

# must not match any other output (like debug output or shell names)
sh.expect("Current line is: abcdefghijklmnopqrstuvwxyz")

sh.sendline(
'[[ -v READLINE_LINE ]] && echo "READLINE_LINE is set" || echo "READLINE_LINE is unset"'
)
sh.expect("READLINE_LINE is unset")


@register(not_impl_shells=['dash', 'mksh'])
def bind_x_readline_point(sh):
"test bind -x for correctly setting $READLINE_POINT for the cmd"
cmd_str = 'abcdefghijklmnop'
expected_rl_point = len(cmd_str)

expect_prompt(sh)

send_bind(sh,
"""-x '"\C-x\C-f": echo Cursor point at: $READLINE_POINT' """)
expect_prompt(sh)

sh.send(cmd_str)

sh.sendcontrol('x')
sh.sendcontrol('f')
time.sleep(0.1)

sh.expect("Cursor point at: " + str(expected_rl_point))

sh.sendline(
'[[ -v READLINE_POINT ]] && echo "READLINE_POINT is set" || echo "READLINE_POINT is unset"'
)
sh.expect("READLINE_POINT is unset")


@register(not_impl_shells=['dash', 'mksh'])
def bind_u(sh):
"test bind -u for unsetting all bindings to a fn"
Expand Down
2 changes: 1 addition & 1 deletion test/stateful.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ job-control() {
}

bind() {
spec/stateful/bind.py $FIRST --oils-failures-allowed 2 "$@"
spec/stateful/bind.py $FIRST --oils-failures-allowed 5 "$@"
}

# Run on just 2 shells
Expand Down

0 comments on commit be2ee72

Please sign in to comment.