Annotation of pkgsrc/mk/pkgformat/pkg/tests/scripts_test, revision 1.1

1.1     ! jlam        1: #!/usr/bin/env atf-sh
        !             2: #
        !             3: # $NetBSD$
        !             4: #
        !             5: # Copyright (c) 2017 The NetBSD Foundation, Inc.
        !             6: # All rights reserved.
        !             7: #
        !             8: # This code is derived from software contributed to The NetBSD Foundation
        !             9: # by Johnny C. Lam.
        !            10: #
        !            11: # Redistribution and use in source and binary forms, with or without
        !            12: # modification, are permitted provided that the following conditions
        !            13: # are met:
        !            14: # 1. Redistributions of source code must retain the above copyright
        !            15: #    notice, this list of conditions and the following disclaimer.
        !            16: # 2. Redistributions in binary form must reproduce the above copyright
        !            17: #    notice, this list of conditions and the following disclaimer in the
        !            18: #    documentation and/or other materials provided with the distribution.
        !            19: #
        !            20: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            21: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            22: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            23: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            24: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            25: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            26: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            27: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            28: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            29: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            30: # POSSIBILITY OF SUCH DAMAGE.
        !            31: 
        !            32: # ENVIRONMENT
        !            33: #      The following variables are used if they are set:
        !            34: #
        !            35: #      MAKE    The name or path to the BSD make(1) utility.  The default
        !            36: #              is "make".
        !            37: #
        !            38: #      PKGSRCDIR
        !            39: #              The location of the pkgsrc source tree.  The default is
        !            40: #              "/usr/pkgsrc".
        !            41: #
        !            42: 
        !            43: setup()
        !            44: {
        !            45:        cat > mk.conf << 'EOF'
        !            46: # Definitions used by pkgformat/pkg/*.mk files that are not assigned
        !            47: # default values.
        !            48: #
        !            49: CAT?=          cat
        !            50: CHMOD?=                chmod
        !            51: MKDIR?=                mkdir -p
        !            52: MV?=           mv
        !            53: RUN?=          @
        !            54: SED?=          sed
        !            55: 
        !            56: # Override any other default definitions so that generated files go into
        !            57: # the current directory.
        !            58: #
        !            59: PKGDIR=                ${.CURDIR}
        !            60: WRKDIR=                ${.CURDIR}
        !            61: PKG_DB_TMPDIR= ${.CURDIR}/.pkgdb
        !            62: 
        !            63: # Don't generate a pkgtasks datafile.
        !            64: PKGTASKS_DATAFILE=     # empty
        !            65: # Generate a sed(1) script from ${FILES_SUBST}.
        !            66: FILES_SUBST_SED=       ${FILES_SUBST:S/=/@!/:S/$/!g/:S/^/ -e s!@/}
        !            67: EOF
        !            68: }
        !            69: 
        !            70: ###
        !            71: ### test1: no scripts
        !            72: ###
        !            73: 
        !            74: atf_test_case test1
        !            75: 
        !            76: test1_head()
        !            77: {
        !            78:        atf_set "descr" "no scripts"
        !            79: }
        !            80: 
        !            81: test1_body()
        !            82: {
        !            83:        : ${MAKE:=make}
        !            84:        : ${PKGSRCDIR:=/usr/pkgsrc}
        !            85: 
        !            86:        setup
        !            87:        cat > Makefile << 'EOF'
        !            88: .include "mk.conf"
        !            89: .include "${PKGSRCDIR}/mk/pkgformat/pkg/scripts.mk"
        !            90: 
        !            91: .PHONY: all
        !            92: all:
        !            93: .if defined(_DEINSTALL_FILE)
        !            94:        @echo "_DEINSTALL_FILE = "${_DEINSTALL_FILE:Q}
        !            95: .endif
        !            96: .if defined(_INSTALL_FILE)
        !            97:        @echo "_INSTALL_FILE = "${_INSTALL_FILE:Q}
        !            98: .endif
        !            99: EOF
        !           100:        ${MAKE} all PKGSRCDIR="${PKGSRCDIR}" > output
        !           101:        if grep -cq "^" output; then
        !           102:                cat output
        !           103:                atf_fail "variables should not be defined"
        !           104:        fi
        !           105:        atf_pass
        !           106: }
        !           107: 
        !           108: ###
        !           109: ### test2: named template files exist"
        !           110: ###
        !           111: 
        !           112: atf_test_case test2
        !           113: 
        !           114: test2_head()
        !           115: {
        !           116:        atf_set "descr" "named template files exist"
        !           117: }
        !           118: 
        !           119: test2_body()
        !           120: {
        !           121:        : ${MAKE:=make}
        !           122:        : ${PKGSRCDIR:=/usr/pkgsrc}
        !           123: 
        !           124:        setup
        !           125:        echo "### HEADER SCRIPT TEMPLATE ###" > HEADER
        !           126:        echo "### DEINSTALL SCRIPT TEMPLATE ###" > DEINSTALL
        !           127:        echo "### INSTALL SCRIPT TEMPLATE ###" > INSTALL
        !           128: 
        !           129:        cat > Makefile << 'EOF'
        !           130: .include "mk.conf"
        !           131: 
        !           132: HEADER_TEMPLATES+=     ${PKGDIR}/HEADER
        !           133: DEINSTALL_TEMPLATES+=  ${PKGDIR}/DEINSTALL
        !           134: INSTALL_TEMPLATES+=    ${PKGDIR}/INSTALL
        !           135: 
        !           136: .include "${PKGSRCDIR}/mk/pkgformat/pkg/scripts.mk"
        !           137: 
        !           138: .PHONY: all
        !           139: all: _pkgformat-generate-install-scripts
        !           140: EOF
        !           141:        ${MAKE} all PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
        !           142:        local count
        !           143: 
        !           144:        count=$( grep -c "### HEADER SCRIPT TEMPLATE ###" .pkgdb/+DEINSTALL )
        !           145:        case $count in
        !           146:        0)      cat .pkgdb/+DEINSTALL
        !           147:                atf_fail "HEADER template was not used in +DEINSTALL" ;;
        !           148:        1)      : "success" ;;
        !           149:        *)      cat .pkgdb/+DEINSTALL
        !           150:                atf_fail "HEADER template used too many times in +DEINSTALL" ;;
        !           151:        esac
        !           152: 
        !           153:        count=$( grep -c "### HEADER SCRIPT TEMPLATE ###" .pkgdb/+INSTALL )
        !           154:        case $count in
        !           155:        0)      cat .pkgdb/+INSTALL
        !           156:                atf_fail "HEADER template was not used in +INSTALL" ;;
        !           157:        1)      : "success" ;;
        !           158:        *)      cat .pkgdb/+INSTALL
        !           159:                atf_fail "HEADER template used too many times in +INSTALL" ;;
        !           160:        esac
        !           161: 
        !           162:        count=$( grep -c "### DEINSTALL SCRIPT TEMPLATE ###" .pkgdb/+DEINSTALL )
        !           163:        case $count in
        !           164:        0)      cat .pkgdb/+DEINSTALL
        !           165:                atf_fail "DEINSTALL template was not used in +DEINSTALL" ;;
        !           166:        1)      : "success" ;;
        !           167:        *)      cat .pkgdb/+DEINSTALL
        !           168:                atf_fail "DEINSTALL template used too many times in +DEINSTALL" ;;
        !           169:        esac
        !           170: 
        !           171:        count=$( grep -c "### INSTALL SCRIPT TEMPLATE ###" .pkgdb/+INSTALL )
        !           172:        case $count in
        !           173:        0)      cat .pkgdb/+INSTALL
        !           174:                atf_fail "INSTALL template was not used in +INSTALL" ;;
        !           175:        1)      : "success" ;;
        !           176:        *)      cat .pkgdb/+INSTALL
        !           177:                atf_fail "INSTALL template used too many times in +INSTALL" ;;
        !           178:        esac
        !           179: 
        !           180:        atf_pass
        !           181: }
        !           182: 
        !           183: ###
        !           184: ### test3: DEINSTALL_SRC and INSTALL_SRC
        !           185: ###
        !           186: 
        !           187: atf_test_case test3
        !           188: 
        !           189: test3_head()
        !           190: {
        !           191:        atf_set "descr" "DEINSTALL_SRC and INSTALL_SRC"
        !           192: }
        !           193: 
        !           194: test3_body()
        !           195: {
        !           196:        : ${MAKE:=make}
        !           197:        : ${PKGSRCDIR:=/usr/pkgsrc}
        !           198: 
        !           199:        setup
        !           200:        ( exec > INSTALL )      # empty INSTALL script
        !           201:        cat > Makefile << 'EOF'
        !           202: .include "mk.conf"
        !           203: 
        !           204: DEINSTALL_SRC= # empty
        !           205: INSTALL_SRC=   INSTALL
        !           206: 
        !           207: .include "${PKGSRCDIR}/mk/pkgformat/pkg/scripts.mk"
        !           208: 
        !           209: .PHONY: all
        !           210: all: _pkgformat-generate-install-scripts
        !           211: EOF
        !           212:        ${MAKE} all PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
        !           213: 
        !           214:        if [ -f .pkgdb/+DEINSTALL ]; then
        !           215:                find .
        !           216:                atf_fail "DEINSTALL_SRC is empty but +DEINSTALL script exists."
        !           217:        fi
        !           218: 
        !           219:        if cmp INSTALL .pkgdb/+INSTALL; then
        !           220:                : "success"
        !           221:        else
        !           222:                cat .pkgdb/+INSTALL
        !           223:                atf_fail "INSTALL script not based solely on INSTALL_SRC"
        !           224:        fi
        !           225: 
        !           226:        atf_pass
        !           227: }
        !           228: 
        !           229: atf_init_test_cases()
        !           230: {
        !           231:        atf_add_test_case test1
        !           232:        atf_add_test_case test2
        !           233:        atf_add_test_case test3
        !           234: }

CVSweb <webmaster@jp.NetBSD.org>