#!/usr/bin/env bash # Exit 0 only when shop prints the expected reports. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" fail=0 expect() { local want="$1" shift local got got="$("$ROOT/shop" "$@")" if [[ "$got" != "$want" ]]; then printf 'FAIL: shop %s\n--- want\n%s\n--- got\n%s\n' "$*" "$want" "$got" fail=1 else echo "ok: shop $*" fi } expect $'items: 2\nexpensive: 0\ntotal: 15.00' 500 1000 expect $'items: 4\nexpensive: 2\ntotal: 36.00' 500 1500 2000 0 expect $'items: 5\nexpensive: 0\ntotal: 45.00' 1000 1000 1000 1000 1000 if [[ "$fail" -ne 0 ]]; then echo "tests: FAILED" exit 1 fi echo "tests: PASSED"