aboutsummaryrefslogtreecommitdiff
path: root/spec/03_contrib_spec.sh
blob: d9fcd30c810c7fc064ce8c6b7dbae4b531718789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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=''
    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"
    }
    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 "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 "build:"
        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 "$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 "$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 (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"
            When run script ./contrib/cpt-depends --help
            The word 1 of stdout should eq usage:
        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"
            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"
            The stderr should eq "WARNING 'typo' is not a valid CPT_COMPRESS value, falling back to '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