diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/01_lib_spec.sh | 96 | ||||
-rw-r--r-- | spec/02_src_spec.sh | 11 | ||||
-rw-r--r-- | spec/03_contrib_spec.sh | 18 |
3 files changed, 91 insertions, 34 deletions
diff --git a/spec/01_lib_spec.sh b/spec/01_lib_spec.sh index b56ac32..b7d83f3 100644 --- a/spec/01_lib_spec.sh +++ b/spec/01_lib_spec.sh @@ -112,16 +112,16 @@ Describe 'CPT Library' Describe '_readlinkf()' mklink() { :> tests/testfile; ln -s testfile tests/testfile2 ;} - rmlink() { rm -f tests/testfile tests/testfile2 ;} + rmlink() { rm tests/testfile tests/testfile2 ;} RPWD=$(cd -P .||:; printf %s "$PWD") - Before mklink - After rmlink + BeforeEach mklink + AfterEach rmlink Parameters "#1" . "$RPWD" - "#2" "$PWD/tests/testfile2" "$RPWD/tests/testfile" + "#2" "./tests/testfile2" "$RPWD/tests/testfile" End - It "outputs the real location of the given file ($1)" - When call _readlinkf "$2" + It "outputs the real location of the given file [$1] ($2 -> $3)" + When run _readlinkf "$2" The output should eq "$3" End End @@ -151,6 +151,53 @@ Describe 'CPT Library' End End + Describe 'version control functions' + check_internet_connection() { ! curl -L git.carbslinux.org >/dev/null 2>&1 ;} + Skip if "no internet connection" check_internet_connection + Describe 'pkg_vcs_clone_git()' + tmpfos=$$ + setup() { mkdir "/tmp/test_repository.$tmpfos" && cd "/tmp/test_repository.$tmpfos" || return ;} + cleanup() { cd /tmp && rm -rf "test_repository.$tmpfos" ;} + check_version() { [ "$1" = "$(sed -n '/^version=/s/.*=//p' configure)" ] ;} + BeforeEach setup + AfterEach cleanup + It "clones the given git repository to the current directory" + When call pkg_vcs_clone_git https://git.carbslinux.org/cpt + The output should not eq "" + The stderr should not eq "" + The status should be success + Assert [ ! -d test_repository ] + Assert [ -f README.md ] + Assert check_version Fossil + End + It "clones the given tag when asked for it" + When call pkg_vcs_clone_git https://git.carbslinux.org/cpt @6.2.4 + The output should not eq "" + The stderr should not eq "" + The status should be success + Assert [ ! -d test_repository ] + Assert [ -f README.md ] + Assert check_version 6.2.4 + End + End + Describe 'pkg_vcs_clone_fossil()' + tmpfos=$$ + setup() { mkdir "/tmp/test_repository.$tmpfos" && cd "/tmp/test_repository.$tmpfos" || return ;} + cleanup() { cd /tmp && rm -rf "test_repository.$tmpfos" ;} + check_version() { [ "$1" = "$(sed -n '/^version=/s/.*=//p' configure)" ] ;} + BeforeEach setup + AfterEach cleanup + It "clones the given fossil repository to the current directory" + When call pkg_vcs_clone_fossil https://fossil.carbslinux.org/cpt + The output should not eq "" + The stderr should eq "" + The status should be success + Assert [ ! -d test_repository ] + Assert [ -f README.md ] + Assert check_version Fossil + End + End + End Describe 'package functions' Describe 'run_hook()' CPT_HOOK=$PWD/tests/hook-file @@ -162,15 +209,9 @@ Describe 'CPT Library' End It "doesn't log 'running hook' if no package is given" When call run_hook 2 '' destination - The stderr should eq "-> Running 2 hook " + The stderr should eq "-> Running 2 hook" The output should eq "$CPT_HOOK 2 null destination" End - It "uses the /etc/cpt-hook file of the root when called with a fourth arg" - When call run_hook 3 cpt destdir root - The stderr should eq "-> cpt Running 3 hook" - The output should eq "$CPT_ROOT/etc/cpt-hook 3 cpt destdir" - The variable CPT_HOOK should eq "$PWD/tests/hook-file" - End It "returns with success even when the file doesn't exist" CPT_HOOK=$PWD/some-non-existent-file When call run_hook 4 thiswillnotrun @@ -178,14 +219,6 @@ Describe 'CPT Library' The stderr should eq "" The status should be success End - It "restores the \$CPT_HOOK variable when called with root" - CPT_ROOT=$PWD/nonexistentdir - When call run_hook 5 cpt dest root - The variable CPT_ROOT should not be exist - The stderr should eq "" - The status should be success - The variable CPT_HOOK should eq "$PWD/tests/hook-file" - End End Describe 'create_tmp()' After pkg_clean @@ -197,10 +230,31 @@ Describe 'CPT Library' Describe 'pkg_get_base()' CPT_ROOT=$PWD/tests CPT_PATH=$PWD/tests/repository + cpt_base=$PWD/tests/etc/cpt-base It 'returns packages defined in base' When call pkg_get_base nonl The output should eq "dummy-pkg contrib-dummy-pkg " End End + Describe 'pkg_query_meta()' + CPT_PATH=$PWD/tests/repository + It 'queries package meta information' + When call pkg_query_meta contrib-dummy-pkg description + The output should eq "This is a dummy package" + End + It 'returns an error if there is no meta file' + When call pkg_query_meta dummy-pkg description + The status should be failure + End + It 'returns an error if the queried key is unavailable' + When call pkg_query_meta contrib-dummy-pkg license + The status should be failure + End + It "accepts full paths to the package location" + When call pkg_query_meta "$PWD/tests/repository/contrib-dummy-pkg" description + The output should eq "This is a dummy package" + The status should be success + End + End End End diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh index be81775..2c20849 100644 --- a/spec/02_src_spec.sh +++ b/spec/02_src_spec.sh @@ -1,7 +1,8 @@ Describe 'Main toolchain' - export PATH=$PWD/src:$PATH - export CPT_ROOT=$PWD/tests/02 - export CPT_PATH=$PWD/tests/repository + PATH=$PWD/src:$PATH + CPT_ROOT=$PWD/tests/02 + CPT_PATH=$PWD/tests/repository + export PATH CPT_ROOT CPT_PATH install_dummy() { CPT_HOOK='' ./src/cpt bi dummy-pkg >/dev/null 2>&1 ;} remove_dummy() { rm -rf "${CPT_ROOT:?}/var" ;} BeforeAll install_dummy @@ -20,7 +21,7 @@ Describe 'Main toolchain' Describe '--help' It 'outputs usage information' When run script src/cpt --help - The line 1 of stderr should eq "-> Carbs Packaging Tool " + The line 1 of stderr should eq "-> Carbs Packaging Tool" End End @@ -52,7 +53,7 @@ Describe 'Main toolchain' It "expands the '$1' shortcut to '$2'" When run script src/cpt "$1" --help The status should be success - The word 2 of line 1 should eq "cpt-${2%% *}" + The word 3 of line 1 should eq "$1" End End End diff --git a/spec/03_contrib_spec.sh b/spec/03_contrib_spec.sh index 9c7589b..b3d6df4 100644 --- a/spec/03_contrib_spec.sh +++ b/spec/03_contrib_spec.sh @@ -1,8 +1,9 @@ Describe 'contrib scripts' - export PATH=$PWD/src:$PWD/contrib:$PATH - export CPT_ROOT=$PWD/tests/03 - export CPT_PATH=$PWD/tests/repository - export CPT_COMPRESS='' + PATH=$PWD/src:$PWD/contrib:$PATH + CPT_ROOT=$PWD/tests/03 + CPT_PATH=$PWD/tests/repository + CPT_COMPRESS='' + export PATH CPT_ROOT CPT_PATH 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 @@ -17,13 +18,13 @@ Describe 'contrib scripts' 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')" + The line 1 of stderr should eq "build:" End 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')" + The line 1 of stderr should eq "build:" End It "exits with error if the package isn't installed" When run script ./contrib/cpt-cat somerandompackage @@ -44,13 +45,13 @@ Describe 'contrib scripts' 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")" + The stderr should eq "$1:" End 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")" + The stderr should eq "$1:" End End Describe 'cpt-depends' @@ -94,6 +95,7 @@ Describe 'contrib scripts' 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" + The stderr should eq "WARNING 'typo' is not a valid CPT_COMPRESS value, falling back to 'gz' " End Parameters bz2 bzip2 |