From d49469e1e562b8b2fdbac5348cab3a568ab4a4b5 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 11 Jan 2021 16:18:08 +0000 Subject: shellspec: update specfiles and add new dummy package FossilOrigin-Name: 9f5fecd16504a19d69468b4d07cf70361ec9c5ff424bdb1705f16dfddc9b2c48 --- spec/02_src_spec.sh | 2 +- spec/03_contrib_spec.sh | 49 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 18 deletions(-) (limited to 'spec') diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh index b4a5c48..561bfe5 100644 --- a/spec/02_src_spec.sh +++ b/spec/02_src_spec.sh @@ -1,6 +1,6 @@ Describe 'Main toolchain' export PATH=$PWD/src:$PATH - export CPT_ROOT=$PWD/tests + export CPT_ROOT=$PWD/tests/02 export CPT_PATH=$PWD/tests/repository install_dummy() { CPT_HOOK='' ./src/cpt bi dummy-pkg >/dev/null 2>&1 ;} remove_dummy() { rm -rf "${CPT_ROOT:?}/var" ;} diff --git a/spec/03_contrib_spec.sh b/spec/03_contrib_spec.sh index c817b2f..a3fce8e 100644 --- a/spec/03_contrib_spec.sh +++ b/spec/03_contrib_spec.sh @@ -1,24 +1,27 @@ Describe 'contrib scripts' - 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 ] + export PATH=$PWD/src:$PWD/contrib:$PATH + export CPT_ROOT=$PWD/tests/03 + export CPT_PATH=$PWD/tests/repository + export CPT_COMPRESS='' + install_tmp() { + CPT_HOOK='' ./src/cpt b -y contrib-dummy-pkg >/dev/null 2>&1 + CPT_HOOK='' ./src/cpt-install -y contrib-dummy-pkg >/dev/null 2>&1 + mkdir -p "$CPT_ROOT/tmp" } - Skip if "there are no installed packages" no_db_dir - - for firstpkg in "$CPT_ROOT/var/db/cpt/installed/"*; do - firstpkg=${firstpkg##*/}; break - done + remove_tmp() { rm -rf "${CPT_ROOT:?}/var" "$CPT_ROOT/tmp" ;} + BeforeAll install_tmp + AfterAll remove_tmp Describe 'cpt-cat' + firstpkg=$(getfirstpkg) It 'outputs the file contents in the given package directory' When run script ./contrib/cpt-cat "$firstpkg" The stdout should not eq "" The line 1 of stderr should eq "$(printf '\033[1mbuild:\033[m\n')" End - It "uses the current directory for the package name if none is supplied (${PWD##*/})" - When run script ./contrib/cpt-cat + It "uses the current directory for the package name if none is supplied (contrib-dummy-pkg)" + cd "$CPT_PATH/contrib-dummy-pkg" || return 1 + When run script "$(command -v cpt-cat)" The stdout should not eq "" The line 1 of stderr should eq "$(printf '\033[1mbuild:\033[m\n')" End @@ -43,20 +46,24 @@ Describe 'contrib scripts' The stdout should eq "$(cat "$CPT_ROOT/var/db/cpt/installed/$firstpkg/$1")" The stderr should eq "$(printf '\033[1m%s:\033[m\n' "$1")" End - It "outputs the given file contents for the name of the current directory (${PWD##*/} - $1)" - When run script ./contrib/cpt-cat "" "$1" + It "outputs the given file contents for the name of the current directory (contrib-dummy-pkg - $1)" + cd "$CPT_PATH/contrib-dummy-pkg" || return 1 + When run script "$(command -v cpt-cat)" "" "$1" The stdout should eq "$(cat "$CPT_ROOT/var/db/cpt/installed/${PWD##*/}/$1")" The stderr should eq "$(printf '\033[1m%s:\033[m\n' "$1")" End End Describe 'cpt-depends' + firstpkg=$(getfirstpkg) It "outputs the dependencies of the given package" When run script ./contrib/cpt-depends "$firstpkg" + The stdout should eq "$(cat "$CPT_ROOT/var/db/cpt/installed/$firstpkg/depends" 2>/dev/null ||:)" The status should be success End - It "uses the current directory for the package name if none is supplied (${PWD##*/})" - When run script ./contrib/cpt-depends - The stdout should eq "$(cat "$CPT_ROOT/var/db/cpt/installed/${PWD##*/}/depends" 2>/dev/null ||:)" + It "uses the current directory for the package name if none is supplied (contrib-dummy-pkg)" + cd "$CPT_PATH/contrib-dummy-pkg" || return 1 + When run script "$(command -v cpt-depends)" + The stdout should eq "$(cat "$CPT_ROOT/var/db/cpt/installed/contrib-dummy-pkg/depends" 2>/dev/null ||:)" The status should be success End It "prints usage information when called with --help" @@ -64,4 +71,12 @@ Describe 'contrib scripts' The word 1 of stdout should eq usage: End End + Describe 'cpt-export' + firstpkg=$(getfirstpkg) + It "exports a tarball of the given package" + cd "$CPT_ROOT/tmp" || return 1 + When run script "$(command -v cpt-export)" contrib-dummy-pkg + The stdout should eq "tarball created in $CPT_ROOT/tmp/contrib-dummy-pkg#1-1.tar.gz" + End + End End -- cgit v1.2.3