summaryrefslogtreecommitdiff
path: root/echo.sh
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-04-22 10:25:58 +0300
committerLars Wirzenius <liw@liw.fi>2020-04-22 10:50:01 +0300
commit18d2dd3b0094d373a4632c9c444d7a2267cc9164 (patch)
tree09487a98c0c7a8afacc053fec63fb3e627e26019 /echo.sh
parente50ca0c984173ce8d84d6a4092096753512ccf26 (diff)
downloadsubplot-18d2dd3b0094d373a4632c9c444d7a2267cc9164.tar.gz
Add: a bash template and change echo.md to use it
Diffstat (limited to 'echo.sh')
-rw-r--r--echo.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/echo.sh b/echo.sh
new file mode 100644
index 0000000..44f272a
--- /dev/null
+++ b/echo.sh
@@ -0,0 +1,48 @@
+_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" ""
+}