summaryrefslogtreecommitdiff
path: root/examples/echo/echo.sh
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-17 08:49:38 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-18 10:42:40 +0200
commita85e7d15c57c11d8286656531c7394681fb855d9 (patch)
tree872ec655a99606e8fe2147a4b8d4fb3e1aeb186b /examples/echo/echo.sh
parent4b9edb354297353cbbe38575553ca1351f68d380 (diff)
downloadsubplot-a85e7d15c57c11d8286656531c7394681fb855d9.tar.gz
refactor: move echo and muck examples under new examples/ directory
Diffstat (limited to 'examples/echo/echo.sh')
-rw-r--r--examples/echo/echo.sh50
1 files changed, 50 insertions, 0 deletions
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" ""
+}