From 9aa75c1170aa020b18fba9e3779733110c5149f5 Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 20 Dec 2021 18:42:18 -0800 Subject: [PATCH] w00t tests --- .gitignore | 1 + test/runner | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-run | 17 +++++++++++++++++ ⚡️ | 7 +++++++ 4 files changed, 76 insertions(+) create mode 100644 .gitignore create mode 100644 test/runner create mode 100644 test/test-run create mode 100644 ⚡️ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f1e4d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.generated diff --git a/test/runner b/test/runner new file mode 100644 index 0000000..4a0ddda --- /dev/null +++ b/test/runner @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +try() { + output=$(mktemp -d) + "$@" > "$output/stdout" 2> "$output/stderr" + EXIT_CODE=$? + STDOUT=$(<"$output/stdout") + STDERR=$(<"$output/stderr") + export EXIT_CODE STDOUT STDERR + rm -rf "$output" +} + +setUp() { + export TMPDIR="$PWD/.generated" +} + +tearDown() { + [ "${_shunit_test_:=}" = '' ] && return 0 + if [ "${__shunit_testSuccess:?}" != 0 ]; then + output-outputs + fi +} + +output-outputs() { + ( + bold '*******Test failed********' + echo "$(bold EXIT_CODE =) $EXIT_CODE" + bold STDOUT : + echo "$STDOUT" + bold STDERR : + echo "$STDERR" + ) >&2 +} + +bold() { + echo -ne "\033[1m" + echo -ne "$@" + echo -e "\033[0m" +} + +SHUNIT_PATH=./.generated/shunit2-2.1.8/shunit2 +if [ ! -f $SHUNIT_PATH ]; then ( + mkdir -p .generated + cd .generated + curl -LO https://github.com/kward/shunit2/archive/v2.1.8.zip + unzip v2.1.8.zip +) +fi + + +source $SHUNIT_PATH diff --git a/test/test-run b/test/test-run new file mode 100644 index 0000000..509a5ea --- /dev/null +++ b/test/test-run @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +testDefiningALightningFunctionWorks() { + echo ' + #!/usr/bin/env bash + + ⚡️hello() { echo "Hello, World!" ; } + ' > go + + echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go + chmod +x go + + try ./go hello + assertEquals "Hello, World!" "$STDOUT" +} + +source $(dirname $0)/runner diff --git a/⚡️ b/⚡️ new file mode 100644 index 0000000..0b3885e --- /dev/null +++ b/⚡️ @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +main() { + ⚡️$1 +} + +main "$@"