diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-06-01 22:00:29 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-06-01 22:00:29 +0300 |
commit | f018f576993c86a73f0a730ffa56e67e328c7aaf (patch) | |
tree | 4e1f40faf8bc1e8efed27925382521f01977b10c | |
parent | 8d603a5d369178a04e099acd93de450ff351022d (diff) | |
download | fable-poc-f018f576993c86a73f0a730ffa56e67e328c7aaf.tar.gz |
Add: a second scenario
-rw-r--r-- | echo.md | 12 | ||||
-rw-r--r-- | echo.py | 14 | ||||
-rw-r--r-- | echo.yaml | 8 |
3 files changed, 31 insertions, 3 deletions
@@ -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 +``` @@ -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'), '') @@ -1,11 +1,17 @@ - when: user runs echo without arguments function: run_echo_without_args - - then: exit code is (?P<exit_code>\d+) +- when: user runs echo with arguments (?P<args>.+) + function: run_echo_with_args + +- then: exit code is (?P<exit_code>\d+) function: exit_code_is_zero - then: standard output contains a newline function: stdout_is_a_newline +- then: standard output contains "(?P<text>.*)" + function: stdout_is_text + - then: standard error is empty function: stderr_is_empty |