diff --git a/.travis.yml b/.travis.yml index d8b05f08..89211edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ script: } run_sh_test() { - echo "--- Running test script: $1" + echo "--- Running test script: '$1'" bash $1 || { echo "--- Test failed. Exiting"; exit 1; } echo "--- Test script $1 executed successfully" } diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh new file mode 100644 index 00000000..2caf8e99 --- /dev/null +++ b/imag-link/tests/link-test.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh +source $(dirname ${BASH_SOURCE[0]})/utils.sh + +default_entry() { + cat < ${STORE}/$1 +} + +test_link_modificates() { + mktestentry "test~0.1.0" + mktestentry "test2~0.1.0" + + imag-link internal add --from "test~0.1.0" --to "test2~0.1.0" + + if [[ "$(default_entry)" -eq "$(cat_entry 'test~0.1.0')" ]] || + [[ "$(default_entry)" -eq "$(cat_entry 'test2~0.1.0')" ]] + then + err "Entry was unmodified after linking" + return 1; + fi +} + +test_linking_links() { + mktestentry "test~0.1.0" + mktestentry "test2~0.1.0" + + imag-link internal add --from "test~0.1.0" --to "test2~0.1.0" + + if [[ "$(entry_linked_to '/test~0.1.0')" == "$(cat_entry 'test2~0.1.0')" ]]; + then + err "Linking to 'test~0.1.0' didn't succeed for 'test2~0.1.0'" + err $(cat_entry 'test2~0.1.0') + fi + + if [[ "$(entry_linked_to '/test2~0.1.0')" == "$(cat_entry 'test~0.1.0')" ]]; + then + err "Linking to 'test2~0.1.0' didn't succeed for 'test~0.1.0'" + err $(cat_entry 'test~0.1.0') + fi +} + +invoke_tests \ + test_link_modificates \ + test_linking_links + diff --git a/imag-link/tests/utils.sh b/imag-link/tests/utils.sh new file mode 100644 index 00000000..ff9e9975 --- /dev/null +++ b/imag-link/tests/utils.sh @@ -0,0 +1,6 @@ +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh + +imag-link() { + imag-call-binary "$(dirname ${BASH_SOURCE[0]})/../target/debug/" imag-link $* +} + diff --git a/imag-store/tests/001-create_test.sh b/imag-store/tests/001-create_test.sh index 91720c9f..823d8488 100644 --- a/imag-store/tests/001-create_test.sh +++ b/imag-store/tests/001-create_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh test_call() { diff --git a/imag-store/tests/002-retrieve_test.sh b/imag-store/tests/002-retrieve_test.sh index 33b96780..4e2c7d7c 100644 --- a/imag-store/tests/002-retrieve_test.sh +++ b/imag-store/tests/002-retrieve_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh std_header() { diff --git a/imag-store/tests/003-delete_test.sh b/imag-store/tests/003-delete_test.sh index 794f1ad8..9beaba82 100644 --- a/imag-store/tests/003-delete_test.sh +++ b/imag-store/tests/003-delete_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh create() { diff --git a/imag-store/tests/utils.sh b/imag-store/tests/utils.sh index 148eaf87..adf6cd88 100644 --- a/imag-store/tests/utils.sh +++ b/imag-store/tests/utils.sh @@ -1,65 +1,6 @@ -#!/usr/bin/env bash - -COLOR_OFF='\e[0m' # Text Reset -RED='\e[0;31m' # Red -YELLOW='\e[0;33m' # Yellow -GREEN='\e[0;32m' # Green - -RUNTIME="/tmp" -STORE="${RUNTIME}/store" - -out() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}" -} - -success() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}" -} - -err() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}" -} - -silent() { - DEBUG_OUTPUT_OFF=1 $* -} +source $(dirname ${BASH_SOURCE[0]})/../tests/utils.sh imag-store() { - local searchdir=$(dirname ${BASH_SOURCE[0]})/../target/debug/ - [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } - local bin=$(find $searchdir -iname imag-store -type f -executable) - local flags="--debug --rtp $RUNTIME" - out "Calling '$bin $flags $*'" - $bin $flags $* -} - -reset_store() { - rm -r "${STORE}" -} - -call_test() { - out "-- TESTING: '$1' --" - $1 - result=$? - if [[ -z "$DONT_RESET_STORE" ]]; then - out "Reseting store" - reset_store - out "Store reset done" - fi - [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } - success "-- SUCCESS: '$1' --" -} - -invoke_tests() { - out "Invoking tests." - if [[ ! -z "$INVOKE_TEST" ]]; then - out "Invoking only $INVOKE_TEST" - call_test "$INVOKE_TEST" - else - out "Invoking $*" - for t in $*; do - call_test "$t" - done - fi + imag-call-binary "$(dirname ${BASH_SOURCE[0]})/../target/debug/" imag-store $* } diff --git a/tests/utils.sh b/tests/utils.sh new file mode 100644 index 00000000..6fc23ad8 --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# +# +# This file contains test utility functions which are used by the test scripts +# for each binary. +# +# + + +COLOR_OFF='\e[0m' # Text Reset +RED='\e[0;31m' # Red +YELLOW='\e[0;33m' # Yellow +GREEN='\e[0;32m' # Green + +RUNTIME="/tmp" +STORE="${RUNTIME}/store" + +out() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}" +} + +success() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}" +} + +err() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}" +} + +silent() { + DEBUG_OUTPUT_OFF=1 $* +} + +imag-call-binary() { + local searchdir=$1; shift + local binary=$1; shift + [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } + local bin=$(find $searchdir -iname $binary -type f -executable) + local flags="--debug --rtp $RUNTIME" + out "Calling '$bin $flags $*'" + $bin $flags $* +} + +cat_entry() { + cat ${STORE}/$1 +} + +reset_store() { + rm -r "${STORE}" +} + +call_test() { + out "-- TESTING: '$1' --" + $1 + result=$? + if [[ -z "$DONT_RESET_STORE" ]]; then + out "Reseting store" + reset_store + out "Store reset done" + fi + [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } + success "-- SUCCESS: '$1' --" +} + +invoke_tests() { + out "Invoking tests." + if [[ ! -z "$INVOKE_TEST" ]]; then + out "Invoking only $INVOKE_TEST" + call_test "$INVOKE_TEST" + else + out "Invoking $*" + for t in $*; do + call_test "$t" + done + fi +} + +