summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--echo.md12
-rw-r--r--echo.py14
-rw-r--r--echo.yaml8
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<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