From d8e86e2e94d0de4e29eaff32a6e5b3d9e98d85d4 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Thu, 2 Jun 2022 21:15:46 +0300 Subject: [PATCH] testcases --- testing/Bakefile | 48 +++++++++++++++++++++++++++---------- testing/completion/Bakefile | 20 ++++++++++++++++ testing/internals/Bakefile | 17 +++++++++++++ 3 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 testing/completion/Bakefile create mode 100644 testing/internals/Bakefile diff --git a/testing/Bakefile b/testing/Bakefile index a2bcdf1..fe347af 100644 --- a/testing/Bakefile +++ b/testing/Bakefile @@ -1,20 +1,42 @@ -completion1() { - echo Args: "$@" +BAKE=$( readlink -f ../bake ) +internals() { + _yecho "flines function" + _assert_eq "$( cd internals; $BAKE flines | wc -l )" "4" + _yecho "commands function" + _assert_eq "$( cd internals; $BAKE commands )" "^target1$|^target2$|^flines$|^commands$" + _yecho "Not a target should fail" + ( cd internals; $BAKE non-existent ) && { _fail; } || { _pass; } + + _yecho "Item help" + _assert_eq "$( cd internals; $BAKE -h target2 | tail -n1 )" $'\e[36mSub help\e[0m' + + _yecho "Multiple targets" + _assert_eq "$( cd internals; $BAKE target1,target2 )" $'1\n2' } -_complete_completion1() { - compgen -o plusdirs -f -- "$1" + + + + + +_assert_eq() { + if [[ "$1" = "$2" ]]; then + _pass + else + echo Expect: "$2" + echo Received: "$1" + _fail + fi } -completion2() { - echo Hard coded choices: "$@" +_fail() { + _recho "Test failed" + exit 1 } - -_complete_completion2() { - echo "choice1 alternative2" -} - -nocompletion() { - echo Args: "$@" +_pass() { + _gecho "Test Passed" } +_gecho() { printf '\e[1;32m%s\e[0m\n' "$1"; } +_recho() { printf '\e[1;31m%s\e[0m\n' "$1"; } +_yecho() { printf '\e[1;33m%s\e[0m\n' "$1"; } diff --git a/testing/completion/Bakefile b/testing/completion/Bakefile new file mode 100644 index 0000000..a2bcdf1 --- /dev/null +++ b/testing/completion/Bakefile @@ -0,0 +1,20 @@ + +completion1() { + echo Args: "$@" +} + +_complete_completion1() { + compgen -o plusdirs -f -- "$1" +} + +completion2() { + echo Hard coded choices: "$@" +} + +_complete_completion2() { + echo "choice1 alternative2" +} + +nocompletion() { + echo Args: "$@" +} diff --git a/testing/internals/Bakefile b/testing/internals/Bakefile new file mode 100644 index 0000000..5a0e6c0 --- /dev/null +++ b/testing/internals/Bakefile @@ -0,0 +1,17 @@ + +target1() { + echo 1 +} +target2() { # Target description +# Sub help + echo 2 +} + + +flines() { + _flines +} + +commands() { + _commands +}