From 3c1f9fa15f745a8acecfef3f9f96211cdafb89ec Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 17:22:47 +0200 Subject: [PATCH 1/6] Move test utilities to top-level test directory --- imag-store/tests/001-create_test.sh | 1 + imag-store/tests/002-retrieve_test.sh | 1 + imag-store/tests/003-delete_test.sh | 1 + imag-store/tests/utils.sh | 63 +--------------------- tests/utils.sh | 75 +++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 tests/utils.sh 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..8babfd21 --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,75 @@ +#!/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 $* +} + +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 +} + + From 91be10cb9788c69451cad1bd1a9c9156aee87a26 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 17:38:58 +0200 Subject: [PATCH 2/6] Add link-test utilities --- imag-link/tests/utils.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 imag-link/tests/utils.sh 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 $* +} + From 8b7f6d2e8e26d8cc5875fcd84e75af8b62460012 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 14 Apr 2016 17:39:05 +0200 Subject: [PATCH 3/6] Add link-test testing --- imag-link/tests/link-test.sh | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 imag-link/tests/link-test.sh diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh new file mode 100644 index 00000000..362b0292 --- /dev/null +++ b/imag-link/tests/link-test.sh @@ -0,0 +1,38 @@ +#!/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 --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 +} + +invoke_tests \ + test_link_modificates + From 4cee962a0621095346a4db7cc9189dc7f59fd6e1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Apr 2016 16:24:38 +0200 Subject: [PATCH 4/6] Quote test script name for easier debugging --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" } From e117fdaa70f70b7d31de20b7de4b8bbf987a122f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Apr 2016 18:32:13 +0200 Subject: [PATCH 5/6] Add helper function to cat an entry from the store --- tests/utils.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/utils.sh b/tests/utils.sh index 8babfd21..6fc23ad8 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -42,6 +42,10 @@ imag-call-binary() { $bin $flags $* } +cat_entry() { + cat ${STORE}/$1 +} + reset_store() { rm -r "${STORE}" } From 15fde996588b536d22b3b0b19973a15fe743259c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Apr 2016 22:55:39 +0200 Subject: [PATCH 6/6] Add test whether linking actually links --- imag-link/tests/link-test.sh | 37 +++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index 362b0292..2caf8e99 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -14,6 +14,17 @@ version = "0.1.0" EOS } +entry_linked_to() { + cat < ${STORE}/$1 @@ -23,7 +34,7 @@ test_link_modificates() { mktestentry "test~0.1.0" mktestentry "test2~0.1.0" - imag-link --from "test~0.1.0" --to "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')" ]] @@ -33,6 +44,26 @@ test_link_modificates() { fi } -invoke_tests \ - test_link_modificates +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