1*11be35a1SLionel Sambuc# Copyright 2011 Google Inc. 2*11be35a1SLionel Sambuc# All rights reserved. 3*11be35a1SLionel Sambuc# 4*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 5*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions are 6*11be35a1SLionel Sambuc# met: 7*11be35a1SLionel Sambuc# 8*11be35a1SLionel Sambuc# * Redistributions of source code must retain the above copyright 9*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 10*11be35a1SLionel Sambuc# * Redistributions in binary form must reproduce the above copyright 11*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 12*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 13*11be35a1SLionel Sambuc# * Neither the name of Google Inc. nor the names of its contributors 14*11be35a1SLionel Sambuc# may be used to endorse or promote products derived from this software 15*11be35a1SLionel Sambuc# without specific prior written permission. 16*11be35a1SLionel Sambuc# 17*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*11be35a1SLionel Sambuc# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*11be35a1SLionel Sambuc# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*11be35a1SLionel Sambuc# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*11be35a1SLionel Sambuc# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*11be35a1SLionel Sambuc# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*11be35a1SLionel Sambuc# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*11be35a1SLionel Sambuc# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*11be35a1SLionel Sambuc# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*11be35a1SLionel Sambuc# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*11be35a1SLionel Sambuc# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*11be35a1SLionel Sambuc 29*11be35a1SLionel Sambuc 30*11be35a1SLionel Sambuc# Location of installed documents. Used to validate the output of the about 31*11be35a1SLionel Sambuc# messages against the golden files. 32*11be35a1SLionel SambucKYUA_DOCDIR='__KYUA_DOCDIR__' 33*11be35a1SLionel Sambuc 34*11be35a1SLionel Sambuc 35*11be35a1SLionel Sambuc# Common code to validate the output of all about information. 36*11be35a1SLionel Sambuc# 37*11be35a1SLionel Sambuc# \param file The name of the file with the output. 38*11be35a1SLionel Sambuccheck_all() { 39*11be35a1SLionel Sambuc local file="${1}"; shift 40*11be35a1SLionel Sambuc 41*11be35a1SLionel Sambuc grep -E 'kyua-cli.*[0-9]+\.[0-9]+' "${file}" || \ 42*11be35a1SLionel Sambuc atf_fail 'No version reported' 43*11be35a1SLionel Sambuc grep 'Copyright' "${file}" || atf_fail 'No license reported' 44*11be35a1SLionel Sambuc grep '<.*@.*>' "${file}" || atf_fail 'No authors reported' 45*11be35a1SLionel Sambuc grep 'Homepage' "${file}" || atf_fail 'No homepage reported' 46*11be35a1SLionel Sambuc} 47*11be35a1SLionel Sambuc 48*11be35a1SLionel Sambuc 49*11be35a1SLionel Sambucutils_test_case all_topics__installed 50*11be35a1SLionel Sambucall_topics__installed_head() { 51*11be35a1SLionel Sambuc atf_set "require.files" "${KYUA_DOCDIR}/AUTHORS ${KYUA_DOCDIR}/COPYING" 52*11be35a1SLionel Sambuc} 53*11be35a1SLionel Sambucall_topics__installed_body() { 54*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stdout -e empty kyua about 55*11be35a1SLionel Sambuc check_all stdout 56*11be35a1SLionel Sambuc} 57*11be35a1SLionel Sambuc 58*11be35a1SLionel Sambuc 59*11be35a1SLionel Sambucutils_test_case all_topics__override 60*11be35a1SLionel Sambucall_topics__override_body() { 61*11be35a1SLionel Sambuc mkdir docs 62*11be35a1SLionel Sambuc echo "Author <author@example.net>" >docs/AUTHORS 63*11be35a1SLionel Sambuc echo "Copyright text" >docs/COPYING 64*11be35a1SLionel Sambuc export KYUA_DOCDIR=docs 65*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stdout -e empty kyua about 66*11be35a1SLionel Sambuc check_all stdout 67*11be35a1SLionel Sambuc} 68*11be35a1SLionel Sambuc 69*11be35a1SLionel Sambuc 70*11be35a1SLionel Sambucutils_test_case topic__authors__installed 71*11be35a1SLionel Sambuctopic__authors__installed_head() { 72*11be35a1SLionel Sambuc atf_set "require.files" "${KYUA_DOCDIR}/AUTHORS" 73*11be35a1SLionel Sambuc} 74*11be35a1SLionel Sambuctopic__authors__installed_body() { 75*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:"${KYUA_DOCDIR}/AUTHORS" -e empty \ 76*11be35a1SLionel Sambuc kyua about authors 77*11be35a1SLionel Sambuc} 78*11be35a1SLionel Sambuc 79*11be35a1SLionel Sambuc 80*11be35a1SLionel Sambucutils_test_case topic__authors__override 81*11be35a1SLionel Sambuctopic__authors__override_body() { 82*11be35a1SLionel Sambuc mkdir docs 83*11be35a1SLionel Sambuc echo "Author <author@example.net>" >docs/AUTHORS 84*11be35a1SLionel Sambuc export KYUA_DOCDIR=docs 85*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:docs/AUTHORS -e empty kyua about authors 86*11be35a1SLionel Sambuc} 87*11be35a1SLionel Sambuc 88*11be35a1SLionel Sambuc 89*11be35a1SLionel Sambucutils_test_case topic__license__installed 90*11be35a1SLionel Sambuctopic__license__installed_head() { 91*11be35a1SLionel Sambuc atf_set "require.files" "${KYUA_DOCDIR}/COPYING" 92*11be35a1SLionel Sambuc} 93*11be35a1SLionel Sambuctopic__license__installed_body() { 94*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:"${KYUA_DOCDIR}/COPYING" -e empty \ 95*11be35a1SLionel Sambuc kyua about license 96*11be35a1SLionel Sambuc} 97*11be35a1SLionel Sambuc 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambucutils_test_case topic__license__override 100*11be35a1SLionel Sambuctopic__license__override_body() { 101*11be35a1SLionel Sambuc mkdir docs 102*11be35a1SLionel Sambuc echo "Copyright text" >docs/COPYING 103*11be35a1SLionel Sambuc export KYUA_DOCDIR=docs 104*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:docs/COPYING -e empty kyua about license 105*11be35a1SLionel Sambuc} 106*11be35a1SLionel Sambuc 107*11be35a1SLionel Sambuc 108*11be35a1SLionel Sambucutils_test_case topic__version 109*11be35a1SLionel Sambuctopic__version_body() { 110*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stdout -e empty kyua about version 111*11be35a1SLionel Sambuc 112*11be35a1SLionel Sambuc local lines="$(wc -l stdout | awk '{ print $1 }')" 113*11be35a1SLionel Sambuc [ "${lines}" -eq 1 ] || atf_fail "Version query returned more than one line" 114*11be35a1SLionel Sambuc 115*11be35a1SLionel Sambuc grep '^kyua-cli (.*) [0-9]\.[0-9]$' stdout || \ 116*11be35a1SLionel Sambuc atf_fail "Invalid version message" 117*11be35a1SLionel Sambuc} 118*11be35a1SLionel Sambuc 119*11be35a1SLionel Sambuc 120*11be35a1SLionel Sambucutils_test_case topic__invalid 121*11be35a1SLionel Sambuctopic__invalid_body() { 122*11be35a1SLionel Sambuc cat >experr <<EOF 123*11be35a1SLionel SambucUsage error for command about: Invalid about topic 'foo'. 124*11be35a1SLionel SambucType 'kyua help about' for usage information. 125*11be35a1SLionel SambucEOF 126*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e file:experr kyua about foo 127*11be35a1SLionel Sambuc} 128*11be35a1SLionel Sambuc 129*11be35a1SLionel Sambuc 130*11be35a1SLionel Sambucutils_test_case too_many_arguments 131*11be35a1SLionel Sambuctoo_many_arguments_body() { 132*11be35a1SLionel Sambuc cat >stderr <<EOF 133*11be35a1SLionel SambucUsage error for command about: Too many arguments. 134*11be35a1SLionel SambucType 'kyua help about' for usage information. 135*11be35a1SLionel SambucEOF 136*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e file:stderr kyua about abc def 137*11be35a1SLionel Sambuc} 138*11be35a1SLionel Sambuc 139*11be35a1SLionel Sambuc 140*11be35a1SLionel Sambucatf_init_test_cases() { 141*11be35a1SLionel Sambuc atf_add_test_case all_topics__installed 142*11be35a1SLionel Sambuc atf_add_test_case all_topics__override 143*11be35a1SLionel Sambuc atf_add_test_case topic__authors__installed 144*11be35a1SLionel Sambuc atf_add_test_case topic__authors__override 145*11be35a1SLionel Sambuc atf_add_test_case topic__license__installed 146*11be35a1SLionel Sambuc atf_add_test_case topic__license__override 147*11be35a1SLionel Sambuc atf_add_test_case topic__version 148*11be35a1SLionel Sambuc atf_add_test_case topic__invalid 149*11be35a1SLionel Sambuc 150*11be35a1SLionel Sambuc atf_add_test_case too_many_arguments 151*11be35a1SLionel Sambuc} 152