1 # Copyright 2011 The Kyua Authors.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
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.
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.
30 # Location of installed documents. Used to validate the output of the about
31 # messages against the golden files.
32 : "${KYUA_DOCDIR:=__KYUA_DOCDIR__}"
35 # Common code to validate the output of all about information.
37 # \param file The name of the file with the output.
39 local file="${1}"; shift
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'
50 utils_test_case all_topics__installed
51 all_topics__installed_head() {
52 atf_set "require.files" "${KYUA_DOCDIR}/AUTHORS" \
53 "${KYUA_DOCDIR}/CONTRIBUTORS" "${KYUA_DOCDIR}/LICENSE"
55 all_topics__installed_body() {
56 atf_check -s exit:0 -o save:stdout -e empty kyua about
61 utils_test_case all_topics__override
62 all_topics__override_body() {
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
73 utils_test_case topic__authors__installed
74 topic__authors__installed_head() {
75 atf_set "require.files" "${KYUA_DOCDIR}/AUTHORS" \
76 "${KYUA_DOCDIR}/CONTRIBUTORS"
78 topic__authors__installed_body() {
79 grep -h '^\* ' "${KYUA_DOCDIR}/AUTHORS" "${KYUA_DOCDIR}/CONTRIBUTORS" \
81 atf_check -s exit:0 -o file:expout -e empty kyua about authors
85 utils_test_case topic__authors__override
86 topic__authors__override_body() {
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
96 utils_test_case topic__license__installed
97 topic__license__installed_head() {
98 atf_set "require.files" "${KYUA_DOCDIR}/LICENSE"
100 topic__license__installed_body() {
101 atf_check -s exit:0 -o file:"${KYUA_DOCDIR}/LICENSE" -e empty \
106 utils_test_case topic__license__override
107 topic__license__override_body() {
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
115 utils_test_case topic__version
116 topic__version_body() {
117 atf_check -s exit:0 -o save:stdout -e empty kyua about version
119 local lines="$(wc -l stdout | awk '{ print $1 }')"
120 [ "${lines}" -eq 1 ] || atf_fail "Version query returned more than one line"
122 grep -E '^kyua (.*) [0-9]+\.[0-9]+$' stdout || \
123 atf_fail "Invalid version message"
127 utils_test_case topic__invalid
128 topic__invalid_body() {
130 Usage error for command about: Invalid about topic 'foo'.
131 Type 'kyua help about' for usage information.
133 atf_check -s exit:3 -o empty -e file:experr kyua about foo
137 utils_test_case too_many_arguments
138 too_many_arguments_body() {
140 Usage error for command about: Too many arguments.
141 Type 'kyua help about' for usage information.
143 atf_check -s exit:3 -o empty -e file:stderr kyua about abc def
147 atf_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
157 atf_add_test_case too_many_arguments