🐛 Fix: shell command 词法解析错误未捕获 (#3290)

This commit is contained in:
Ju4tCode
2025-02-01 11:38:01 +08:00
committed by GitHub
parent cf30dc6264
commit 950461b556
3 changed files with 79 additions and 11 deletions

View File

@ -371,9 +371,31 @@ async def test_shell_command():
assert state[SHELL_ARGV] == []
assert SHELL_ARGS not in state
test_lexical_error = shell_command(CMD)
dependent = next(iter(test_lexical_error.checkers))
checker = dependent.call
assert isinstance(checker, ShellCommandRule)
message = Message("-a '1")
event = make_fake_event(_message=message)()
state = {PREFIX_KEY: {CMD_KEY: CMD, CMD_ARG_KEY: message}}
assert await dependent(event=event, state=state)
assert state[SHELL_ARGV] is None
parser = ArgumentParser("test")
parser.add_argument("-a", required=True)
test_lexical_error_with_parser = shell_command(CMD, parser=ArgumentParser("test"))
dependent = next(iter(test_lexical_error_with_parser.checkers))
checker = dependent.call
assert isinstance(checker, ShellCommandRule)
message = Message("-a '1")
event = make_fake_event(_message=message)()
state = {PREFIX_KEY: {CMD_KEY: CMD, CMD_ARG_KEY: message}}
assert await dependent(event=event, state=state)
assert state[SHELL_ARGV] is None
assert isinstance(state[SHELL_ARGS], ParserExit)
assert state[SHELL_ARGS].status != 0
test_simple_parser = shell_command(CMD, parser=parser)
dependent = next(iter(test_simple_parser.checkers))
checker = dependent.call