def test_cmd_call_error_bad_commadn(trace): cmd = Interpreter() cmd.trace = trace cmd.stdin = io.StringIO("fun 2 3 5\n") cmd.stdout = io.StringIO() cmd.stderr = io.StringIO() cmd.run() debug_cmd(cmd) assert cmd.stdout.getvalue() == "" assert cmd.stderr.getvalue() == """\
def test_cmd_shortcut(): cmd = Interpreter(content={"$": "fun"}) @cmd.command(has_arguments=False) def fun(interpreter, *args): interpreter.output("+".join(args)) cmd.stdin = io.StringIO("$a b cd e\n $ ab cd e") cmd.stdout = io.StringIO() cmd.stderr = io.StringIO() cmd.run() assert cmd.stdout.getvalue() == """\
def test_cmd_call_error_bad_arg(trace): cmd = Interpreter() cmd.trace = trace @argument("args", type=int, nargs='+') @cmd.command def fun(interpreter, args): interpreter.output(sum(args)) cmd.stdin = io.StringIO("fun 2 3 5\nfun 2 t 5") cmd.stdout = io.StringIO() cmd.stderr = io.StringIO() cmd.run() debug_cmd(cmd) assert cmd.stdout.getvalue() == """\ 10 """ assert cmd.stderr.getvalue() == """\