From f018f576993c86a73f0a730ffa56e67e328c7aaf Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 1 Jun 2019 22:00:29 +0300 Subject: Add: a second scenario --- echo.md | 12 ++++++++++++ echo.py | 14 ++++++++++++-- echo.yaml | 8 +++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/echo.md b/echo.md index f9bd88d..fef520e 100644 --- a/echo.md +++ b/echo.md @@ -23,3 +23,15 @@ then exit code is 0 and standard output contains a newline and standard error is empty ``` + +Hello, world +============================================================================= + +This scenario runs `/bin/echo` to produce the output "hello, world". + +```fable +when user runs echo with arguments hello, world +then exit code is 0 +and standard output contains "hello, world" +and standard error is empty +``` diff --git a/echo.py b/echo.py index 9ec8437..abc0e52 100644 --- a/echo.py +++ b/echo.py @@ -13,15 +13,22 @@ def assertEqual(a, b): raise Exception( 'expected {!r} == {!r}, but was disappointed'.format(a, b)) -def run_echo_without_args(): +def _run_echo(args): cmd = '/bin/echo' p = subprocess.Popen( - [cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + [cmd] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True) out, err = p.communicate() context["stdout"] = out context["stderr"] = err context["exit_code"] = p.returncode +def run_echo_without_args(): + _run_echo([]) + +def run_echo_with_args(args=None): + _run_echo(args.split()) + def exit_code_is_zero(exit_code=None): exit_code = int(exit_code) assertEqual(_get("exit_code"), exit_code) @@ -29,5 +36,8 @@ def exit_code_is_zero(exit_code=None): def stdout_is_a_newline(): assertEqual(_get('stdout'), '\n') +def stdout_is_text(text=None): + assertEqual(_get('stdout'), text + '\n') + def stderr_is_empty(): assertEqual(_get('stderr'), '') diff --git a/echo.yaml b/echo.yaml index 521ca25..6937d3d 100644 --- a/echo.yaml +++ b/echo.yaml @@ -1,11 +1,17 @@ - when: user runs echo without arguments function: run_echo_without_args - - then: exit code is (?P\d+) +- when: user runs echo with arguments (?P.+) + function: run_echo_with_args + +- then: exit code is (?P\d+) function: exit_code_is_zero - then: standard output contains a newline function: stdout_is_a_newline +- then: standard output contains "(?P.*)" + function: stdout_is_text + - then: standard error is empty function: stderr_is_empty -- cgit v1.2.1