diff options
Diffstat (limited to 'examples/echo')
-rw-r--r-- | examples/echo/echo.bib | 7 | ||||
-rw-r--r-- | examples/echo/echo.md | 52 | ||||
-rw-r--r-- | examples/echo/echo.sh | 50 | ||||
-rw-r--r-- | examples/echo/echo.yaml | 20 |
4 files changed, 129 insertions, 0 deletions
diff --git a/examples/echo/echo.bib b/examples/echo/echo.bib new file mode 100644 index 0000000..05083fb --- /dev/null +++ b/examples/echo/echo.bib @@ -0,0 +1,7 @@ +@book{foo2020, + author = "James Random", + title = "The Foo book", + publisher = "The Internet", + year = 2020, + address = "World Wide Web", +}
\ No newline at end of file diff --git a/examples/echo/echo.md b/examples/echo/echo.md new file mode 100644 index 0000000..c335f53 --- /dev/null +++ b/examples/echo/echo.md @@ -0,0 +1,52 @@ +--- +title: "**echo**(1) acceptance tests" +author: The Subplot project +template: bash +bindings: echo.yaml +functions: echo.sh +bibliography: echo.bib +... + +Introduction +============================================================================= + +**echo**(1) is a Unix command line tool, which writes its command line +arguments to the standard output. This is a simple acceptance test +suite for the `/bin/echo` implementation. + +For more information, see [@foo2020]. + +No arguments +============================================================================= + +Run `/bin/echo` without arguments. + +```scenario +when user runs echo without arguments +then exit code is 0 +then standard output contains a newline +then standard error is empty +``` + +Hello, world +============================================================================= + +This scenario runs `/bin/echo` to produce the output "hello, world". + +```scenario +when user runs echo with arguments hello, world +then exit code is 0 +then standard output contains "hello, world" +then standard error is empty +``` + + +Test file + +~~~~{.file #foo.dat} +This is a test file. +Two lines. +~~~~ + + +# References diff --git a/examples/echo/echo.sh b/examples/echo/echo.sh new file mode 100644 index 0000000..0564d42 --- /dev/null +++ b/examples/echo/echo.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +_run() +{ + if "$@" < /dev/null > stdout 2> stderr + then + ctx_set exit 0 + else + ctx_set exit "$?" + fi + ctx_set stdout "$(cat stdout)" + ctx_set stderr "$(cat stderr)" +} + +run_echo_without_args() +{ + _run echo +} + +run_echo_with_args() +{ + args="$(cap_get args)" + _run echo "$args" +} + +exit_code_is() +{ + actual_exit="$(ctx_get exit)" + wanted_exit="$(cap_get exit_code)" + assert_eq "$actual_exit" "$wanted_exit" +} + +stdout_is_a_newline() +{ + stdout="$(ctx_get stdout)" + assert_eq "$stdout" "$(printf '\n')" +} + +stdout_is_text() +{ + stdout="$(ctx_get stdout)" + text="$(cap_get text)" + assert_contains "$stdout" "$text" +} + +stderr_is_empty() +{ + stderr="$(ctx_get stderr)" + assert_eq "$stderr" "" +} diff --git a/examples/echo/echo.yaml b/examples/echo/echo.yaml new file mode 100644 index 0000000..7be6e96 --- /dev/null +++ b/examples/echo/echo.yaml @@ -0,0 +1,20 @@ +- when: user runs echo without arguments + function: run_echo_without_args + +- when: user runs echo with arguments (?P<args>.+) + function: run_echo_with_args + regex: true + +- then: exit code is (?P<exit_code>\d+) + function: exit_code_is + regex: true + +- then: standard output contains a newline + function: stdout_is_a_newline + +- then: standard output contains "(?P<text>.*)" + function: stdout_is_text + regex: true + +- then: standard error is empty + function: stderr_is_empty |