From 3df8f4bd03cc2d087c1abfb340e9d2949e2f91ad Mon Sep 17 00:00:00 2001 From: merakor Date: Tue, 5 Jan 2021 11:40:43 +0000 Subject: shellspec: add unit tests FossilOrigin-Name: cc6f029081294c10be43ba51dedecb1997cc653215b587a566c0a527705162ab --- spec/03_contrib_spec.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 spec/03_contrib_spec.sh (limited to 'spec/03_contrib_spec.sh') diff --git a/spec/03_contrib_spec.sh b/spec/03_contrib_spec.sh new file mode 100644 index 0000000..c817b2f --- /dev/null +++ b/spec/03_contrib_spec.sh @@ -0,0 +1,67 @@ +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 ] + } + Skip if "there are no installed packages" no_db_dir + + for firstpkg in "$CPT_ROOT/var/db/cpt/installed/"*; do + firstpkg=${firstpkg##*/}; break + done + + Describe 'cpt-cat' + 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 + The stdout should not eq "" + The line 1 of stderr should eq "$(printf '\033[1mbuild:\033[m\n')" + End + It "exits with error if the package isn't installed" + When run script ./contrib/cpt-cat somerandompackage + The stderr should eq "-> somerandompackage not installed" + The status should be failure + End + It "prints usage information when called with --help" + When run script ./contrib/cpt-cat --help + The word 1 of stdout should eq "usage:" + The status should be success + End + Parameters + build + checksums + manifest + version + End + It "outputs the given file contents in the given package directory ($1)" + When run script ./contrib/cpt-cat "$firstpkg" "$1" + 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" + 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' + It "outputs the dependencies of the given package" + When run script ./contrib/cpt-depends "$firstpkg" + 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 ||:)" + The status should be success + End + It "prints usage information when called with --help" + When run script ./contrib/cpt-depends --help + The word 1 of stdout should eq usage: + End + End +End -- cgit v1.2.3 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 ++++++++++++++++++---------- tests/repository/contrib-dummy-pkg/build | 1 + tests/repository/contrib-dummy-pkg/checksums | 0 tests/repository/contrib-dummy-pkg/depends | 1 + tests/repository/contrib-dummy-pkg/sources | 0 tests/repository/contrib-dummy-pkg/version | 1 + 7 files changed, 36 insertions(+), 18 deletions(-) create mode 100755 tests/repository/contrib-dummy-pkg/build create mode 100644 tests/repository/contrib-dummy-pkg/checksums create mode 100644 tests/repository/contrib-dummy-pkg/depends create mode 100644 tests/repository/contrib-dummy-pkg/sources create mode 100644 tests/repository/contrib-dummy-pkg/version (limited to 'spec/03_contrib_spec.sh') 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 diff --git a/tests/repository/contrib-dummy-pkg/build b/tests/repository/contrib-dummy-pkg/build new file mode 100755 index 0000000..270ae64 --- /dev/null +++ b/tests/repository/contrib-dummy-pkg/build @@ -0,0 +1 @@ +#!/bin/sh -e diff --git a/tests/repository/contrib-dummy-pkg/checksums b/tests/repository/contrib-dummy-pkg/checksums new file mode 100644 index 0000000..e69de29 diff --git a/tests/repository/contrib-dummy-pkg/depends b/tests/repository/contrib-dummy-pkg/depends new file mode 100644 index 0000000..153ede1 --- /dev/null +++ b/tests/repository/contrib-dummy-pkg/depends @@ -0,0 +1 @@ +dummy-pkg diff --git a/tests/repository/contrib-dummy-pkg/sources b/tests/repository/contrib-dummy-pkg/sources new file mode 100644 index 0000000..e69de29 diff --git a/tests/repository/contrib-dummy-pkg/version b/tests/repository/contrib-dummy-pkg/version new file mode 100644 index 0000000..2fb73a0 --- /dev/null +++ b/tests/repository/contrib-dummy-pkg/version @@ -0,0 +1 @@ +1 1 -- cgit v1.2.3 From 1080f6b06c16f21bd3f47923fb26f36a55b44899 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 4 Feb 2021 09:09:01 +0000 Subject: specs: update FossilOrigin-Name: c8b7e2be6108720ed5ec3944dda624d0c28cda5ed5fb5b20908a86f76da33da8 --- spec/02_src_spec.sh | 34 ++++++++++++++++++++++++++++++++++ spec/03_contrib_spec.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) (limited to 'spec/03_contrib_spec.sh') diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh index 561bfe5..c5584ec 100644 --- a/spec/02_src_spec.sh +++ b/spec/02_src_spec.sh @@ -93,4 +93,38 @@ Describe 'Main toolchain' The output should eq "$2" End End + Describe 'cpt-search' + It "searches packages inside the \$CPT_PATH and the system database" + When run script src/cpt-search dummy-pkg + The line 1 of output should eq "$CPT_PATH/dummy-pkg" + The line 2 of output should eq "$CPT_ROOT/var/db/cpt/installed/dummy-pkg" + End + It "only shows the first instance of a package with the '-s' flag" + When run script src/cpt-search -s dummy-pkg + The output should eq "$CPT_PATH/dummy-pkg" + End + It "only shows the first instance of a package with the '--single' flag" + When run script src/cpt-search --single dummy-pkg + The output should eq "$CPT_PATH/dummy-pkg" + End + It "shows other locations of the package inside a package directory with the '-o' flag" + cd "$CPT_PATH/dummy-pkg" || return 1 + When run script "$(command -v cpt-search)" -o + The output should eq "$CPT_ROOT/var/db/cpt/installed/dummy-pkg" + End + It "shows other locations of the package inside a package directory with the '--others' flag" + cd "$CPT_PATH/dummy-pkg" || return 1 + When run script "$(command -v cpt-search)" --others + The output should eq "$CPT_ROOT/var/db/cpt/installed/dummy-pkg" + End + Parameters + 'd*' + 'd???y-?kg' + '[Dd][uU]*-?*g*' + End + It "accepts regular expressions" + When run script src/cpt-search -s "$1" + The output should eq "$CPT_PATH/dummy-pkg" + End + End End diff --git a/spec/03_contrib_spec.sh b/spec/03_contrib_spec.sh index a3fce8e..9c7589b 100644 --- a/spec/03_contrib_spec.sh +++ b/spec/03_contrib_spec.sh @@ -72,11 +72,51 @@ Describe 'contrib scripts' End End Describe 'cpt-export' + chtmp() { cd "$CPT_ROOT/tmp" || return 1 ;} + cleanpkg() { rm -f "$CPT_PATH/contrib-dummy-pkg/contrib-dummy-pkg#1-1.tar.gz" ;} + Before chtmp + AfterAll cleanpkg 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 + It "exports the package of the current directory when called without arguments" + cd "$CPT_PATH/contrib-dummy-pkg" || return 1 + When run script "$(command -v cpt-export)" + The stdout should eq "tarball created in $CPT_PATH/contrib-dummy-pkg/contrib-dummy-pkg#1-1.tar.gz" + End + It "prints usage information when called with --help" + When run script "$(command -v cpt-export)" --help + The word 1 of stdout should eq usage: + End + It "fallbacks to gz when CPT_COMPRESS has a typo" + export CPT_COMPRESS=typo + 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 + Parameters + bz2 bzip2 + gz gzip + xz xz + zst zstd + End + Mock bzip2 + cat + End + Mock gzip + cat + End + Mock xz + cat + End + Mock zstd + cat + End + It "uses the given CPT_COMPRESS value ($1)" + export "CPT_COMPRESS=$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.$1" + End End End -- cgit v1.2.3