shellscript.sh
1 #! /usr/bin/env atf-sh 2 3 . $(atf_get_srcdir)/test_environment.sh 4 5 tests_init \ 6 basic \ 7 message \ 8 daemon \ 9 upgrade 10 11 basic_body() { 12 atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" 13 cat << EOF >> test.ucl 14 scripts: { 15 post-install: <<EOS 16 echo this is post install1 17 echo this is post install2 18 EOS 19 } 20 EOF 21 22 atf_check \ 23 -o empty \ 24 -e empty \ 25 -s exit:0 \ 26 pkg create -M test.ucl 27 28 mkdir ${TMPDIR}/target 29 atf_check \ 30 -o inline:"this is post install1\nthis is post install2\n" \ 31 -e empty \ 32 -s exit:0 \ 33 pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg 34 35 } 36 37 message_body() { 38 # The message should be the last thing planned 39 atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" 40 cat << EOF >> test.ucl 41 scripts: { 42 post-install: <<EOS 43 echo this is post install1 44 echo this is a message >&\${PKG_MSGFD} 45 echo this is post install2 46 EOS 47 } 48 EOF 49 50 atf_check \ 51 -o empty \ 52 -e empty \ 53 -s exit:0 \ 54 pkg create -M test.ucl 55 56 mkdir ${TMPDIR}/target 57 atf_check \ 58 -o inline:"this is post install1\nthis is post install2\nthis is a message\n" \ 59 -e empty \ 60 -s exit:0 \ 61 pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg 62 63 } 64 65 daemon_body() { 66 # We should not see the daemon's message 67 atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" 68 cat << EOF >> test.ucl 69 scripts: { 70 post-install: <<EOS 71 echo this is post install1 72 echo this is a message >&\${PKG_MSGFD} 73 (sleep 2; echo this is a daemon >&\${PKG_MSGFD}) < /dev/null > /dev/null 2>&1 & 74 echo this is post install2 75 EOS 76 } 77 EOF 78 79 atf_check \ 80 -o empty \ 81 -e empty \ 82 -s exit:0 \ 83 pkg create -M test.ucl 84 85 mkdir ${TMPDIR}/target 86 atf_check \ 87 -o inline:"this is post install1\nthis is post install2\nthis is a message\n" \ 88 -e empty \ 89 -s exit:0 \ 90 pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg 91 92 } 93 94 upgrade_body() { 95 atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" 96 cat << EOF >> test.ucl 97 scripts: { 98 post-install: <<EOS 99 if [ -n "\${PKG_UPGRADE+x}" ]; then 100 echo "upgrade:\${PKG_UPGRADE}">&\${PKG_MSGFD} 101 fi 102 EOS 103 } 104 EOF 105 106 107 atf_check \ 108 -o empty \ 109 -e empty \ 110 -s exit:0 \ 111 pkg create -M test.ucl 112 mkdir -p ${TMPDIR}/target 113 atf_check \ 114 -e empty \ 115 -o ignore \ 116 -s exit:0 \ 117 pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg 118 119 atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2" 120 cat << EOF >> test.ucl 121 scripts: { 122 post-install: <<EOS 123 if [ -n "\${PKG_UPGRADE+x}" ]; then 124 echo "upgrade:\${PKG_UPGRADE}">&\${PKG_MSGFD} 125 fi 126 EOS 127 } 128 EOF 129 130 rm ${TMPDIR}/test-1.pkg 131 atf_check \ 132 -o empty \ 133 -e empty \ 134 -s exit:0 \ 135 pkg create -M test.ucl 136 mkdir -p ${TMPDIR}/target 137 atf_check \ 138 -o ignore \ 139 -e empty \ 140 -s exit:0 \ 141 pkg info -R -F ./test-2.pkg 142 atf_check \ 143 -o ignore \ 144 -e empty \ 145 -s exit:0 \ 146 pkg repo . 147 mkdir reposconf 148 cat <<EOF >> reposconf/repo.conf 149 local: { 150 url: file:///${TMPDIR}, 151 enabled: true 152 } 153 EOF 154 atf_check \ 155 -e empty \ 156 -o match:"upgrade:true" \ 157 -s exit:0 \ 158 pkg -o REPOS_DIR="${TMPDIR}/reposconf" -r ${TMPDIR}/target upgrade -y 159 }