From 51013c49c59e202bcd15959a9fcef9ad0cdbd577 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 14 Jun 2018 18:50:53 +1000 Subject: [PATCH] Added tests --- test.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..fbc01ce --- /dev/null +++ b/test.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# Tests for the Pure Bash Bible. + +assert_equals() { + # Test equality. + local status + [[ "$1" == "$2" ]] && status="✔" + printf '%s\n' " ${status:-✖} : ${FUNCNAME[1]}" + [[ "$1" == "$2" ]] || { :>/tmp/err; return 1; } && return 0 +} + +test_trim() { + result="$(trim " Hello, World ")" + assert_equals "$result" "Hello, World" +} + +main() { + source <(awk '/```sh/{f=1;next}/```/{f=0}f' README.md) 2>/dev/null + + test_trim + + [[ -f /tmp/err ]] || exit 0 && { rm /tmp/err; exit 1; } +} + +main "$@" +