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