#! /usr/bin/env bash goodtestpass='goodtestpass' badtestpass='badtestpass' failed='' rm -f jsoncred_*.json *.jsonenc fail() { failed='true' echo "failed test $1" } which jsoncred > /dev/null if [ "$?" != "0" ]; then echo "precondition failed: jsoncred not found in \$PATH" exit 1 fi TTEST() { echo "TEST - $@" } TTEST "usage 0" output="$(jsoncred)" echo "$output" | grep 'print path a\.b\.c' > /dev/null if [ "$?" != "0" ]; then fail "usage 0" fi TTEST "usage -h" output="$(jsoncred -h)" echo "$output" | grep 'print path a\.b\.c' > /dev/null if [ "$?" != "0" ]; then fail "usage -h" fi TTEST "usage --help" output="$(jsoncred -h)" echo "$output" | grep 'print path a\.b\.c' > /dev/null if [ "$?" != "0" ]; then fail "usage --help" fi TTEST "full circle import and export" echo '{"a": "b"}' > jsoncred_fullcircle.json JSONCRED_PASSWORD="$goodtestpass" jsoncred jsoncred_fullcircle.json import jsoncred_fullcircle.jsonenc if [ "$?" != "0" ]; then fail "full circle import and export" fi output="$(JSONCRED_PASSWORD="$goodtestpass" jsoncred jsoncred_fullcircle.jsonenc e -)" if [ "$?" != "0" ]; then fail "full circle import and export, could not encode" fi echo "$output" | grep '\{"a": "b"\}' > /dev/null if [ "$?" != "0" ]; then fail "full circle import and export, got $output" fi # END TEST SUITE if [ "$failed" != "" ]; then echo 'one or more tests failed' exit 1 fi rm -f jsoncred_*.json *.jsonenc echo 'PASS'