From 12a4321bfdc98c3bf7b1440077c1a09c9f4e3eec Mon Sep 17 00:00:00 2001 From: merakor Date: Wed, 6 Jan 2021 11:55:50 +0000 Subject: shellspec: fix install_dummy function FossilOrigin-Name: 6ee23d2f9956dd0f3c13e45c281b754bf7e9c850f10c778def5d48cad26277a3 --- spec/02_src_spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh index b97fe3c..57c248f 100644 --- a/spec/02_src_spec.sh +++ b/spec/02_src_spec.sh @@ -2,7 +2,7 @@ Describe 'Main toolchain' export PATH=$PWD/src:$PATH export CPT_ROOT=$PWD/tests export CPT_PATH=$PWD/tests/repository - install_dummy() { CPT_HOOK='' ./src/cpt bi dummy-pkg ;} + install_dummy() { CPT_HOOK='' ./src/cpt bi dummy-pkg >/dev/null 2>&1 ;} remove_dummy() { rm -rf "${CPT_ROOT:?}/var" ;} BeforeAll install_dummy AfterAll remove_dummy -- cgit v1.2.3 From ae42d4a74240d452864cdf16ce2ac2cbbdb5fc68 Mon Sep 17 00:00:00 2001 From: merakor Date: Wed, 6 Jan 2021 11:56:09 +0000 Subject: shellspec: add spec_helper FossilOrigin-Name: df5c93b3f164a3826c97d1ca43924d44af1a5e156e2c4b2f0b8496c60b652868 --- .shellspec | 2 ++ spec/02_src_spec.sh | 9 +++------ spec/spec_helper.sh | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 spec/spec_helper.sh diff --git a/.shellspec b/.shellspec index 77d79cf..85e0590 100644 --- a/.shellspec +++ b/.shellspec @@ -1,3 +1,5 @@ +--require spec_helper + --kcov-options "--include-pattern=cpt-lib" --kcov-options "--include-pattern=/src/cpt,/contrib/cpt-" --kcov-options "--exclude-pattern=.in" diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh index 57c248f..b4a5c48 100644 --- a/spec/02_src_spec.sh +++ b/spec/02_src_spec.sh @@ -67,17 +67,14 @@ Describe 'Main toolchain' Describe 'cpt-list' no_db_dir() { - # Return 0 if database directory is empty (or doesn't exist) - # shellcheck disable=2012 - count=$(ls -1 "$CPT_ROOT/var/db/cpt/installed" 2>/dev/null | wc -l) - [ "$count" -eq 0 ] + [ "$(pkgnum)" -eq 0 ] } Skip if "there are no installed packages" no_db_dir It 'lists all packages when called without arguments' When run script src/cpt-list - The lines of output should eq "$(ls -1 "$CPT_ROOT/var/db/cpt/installed" 2>/dev/null | wc -l)" + The lines of output should eq "$(pkgnum)" End - for firstpkg in "$CPT_ROOT/var/db/cpt/installed/"*; do firstpkg=${firstpkg##*/}; break; done + firstpkg=$(getfirstpkg) It 'only lists the packages given in the arguments' When run script src/cpt-list "$firstpkg" The word 1 of stdout should eq "$firstpkg" diff --git a/spec/spec_helper.sh b/spec/spec_helper.sh new file mode 100644 index 0000000..f62d9f6 --- /dev/null +++ b/spec/spec_helper.sh @@ -0,0 +1,20 @@ +# shellcheck shell=sh + +pkgnum() { + i=0 + cd "$CPT_ROOT/var/db/cpt/installed" || { printf '%s\n' 0; return 1 ;} + for pkg in ./*; do + [ -d "$pkg" ] || break + i=$(( i + 1 )) + done + printf '%s\n' "$i" +} + +getfirstpkg() { + cd "$CPT_ROOT/var/db/cpt/installed" || return 1 + for pkg in ./*; do + [ -d "$pkg" ] || return 1 + printf '%s\n' "${pkg##*/}" + break + done +} -- cgit v1.2.3