cmd_about_test.sh revision 1.1 1 # Copyright 2011 Google Inc.
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.
38 check_all() {
39 local file="${1}"; shift
40
41 grep -E 'kyua-cli.*[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 'Homepage' "${file}" || atf_fail 'No homepage reported'
46 }
47
48
49 utils_test_case all_topics__installed
50 all_topics__installed_head() {
51 atf_set "require.files" "${KYUA_DOCDIR}/AUTHORS ${KYUA_DOCDIR}/COPYING"
52 }
53 all_topics__installed_body() {
54 atf_check -s exit:0 -o save:stdout -e empty kyua about
55 check_all stdout
56 }
57
58
59 utils_test_case all_topics__override
60 all_topics__override_body() {
61 mkdir docs
62 echo "Author <author (at] example.net>" >docs/AUTHORS
63 echo "Copyright text" >docs/COPYING
64 export KYUA_DOCDIR=docs
65 atf_check -s exit:0 -o save:stdout -e empty kyua about
66 check_all stdout
67 }
68
69
70 utils_test_case topic__authors__installed
71 topic__authors__installed_head() {
72 atf_set "require.files" "${KYUA_DOCDIR}/AUTHORS"
73 }
74 topic__authors__installed_body() {
75 atf_check -s exit:0 -o file:"${KYUA_DOCDIR}/AUTHORS" -e empty \
76 kyua about authors
77 }
78
79
80 utils_test_case topic__authors__override
81 topic__authors__override_body() {
82 mkdir docs
83 echo "Author <author (at] example.net>" >docs/AUTHORS
84 export KYUA_DOCDIR=docs
85 atf_check -s exit:0 -o file:docs/AUTHORS -e empty kyua about authors
86 }
87
88
89 utils_test_case topic__license__installed
90 topic__license__installed_head() {
91 atf_set "require.files" "${KYUA_DOCDIR}/COPYING"
92 }
93 topic__license__installed_body() {
94 atf_check -s exit:0 -o file:"${KYUA_DOCDIR}/COPYING" -e empty \
95 kyua about license
96 }
97
98
99 utils_test_case topic__license__override
100 topic__license__override_body() {
101 mkdir docs
102 echo "Copyright text" >docs/COPYING
103 export KYUA_DOCDIR=docs
104 atf_check -s exit:0 -o file:docs/COPYING -e empty kyua about license
105 }
106
107
108 utils_test_case topic__version
109 topic__version_body() {
110 atf_check -s exit:0 -o save:stdout -e empty kyua about version
111
112 local lines="$(wc -l stdout | awk '{ print $1 }')"
113 [ "${lines}" -eq 1 ] || atf_fail "Version query returned more than one line"
114
115 grep '^kyua-cli (.*) [0-9]\.[0-9]$' stdout || \
116 atf_fail "Invalid version message"
117 }
118
119
120 utils_test_case topic__invalid
121 topic__invalid_body() {
122 cat >experr <<EOF
123 Usage error for command about: Invalid about topic 'foo'.
124 Type 'kyua help about' for usage information.
125 EOF
126 atf_check -s exit:3 -o empty -e file:experr kyua about foo
127 }
128
129
130 utils_test_case too_many_arguments
131 too_many_arguments_body() {
132 cat >stderr <<EOF
133 Usage error for command about: Too many arguments.
134 Type 'kyua help about' for usage information.
135 EOF
136 atf_check -s exit:3 -o empty -e file:stderr kyua about abc def
137 }
138
139
140 atf_init_test_cases() {
141 atf_add_test_case all_topics__installed
142 atf_add_test_case all_topics__override
143 atf_add_test_case topic__authors__installed
144 atf_add_test_case topic__authors__override
145 atf_add_test_case topic__license__installed
146 atf_add_test_case topic__license__override
147 atf_add_test_case topic__version
148 atf_add_test_case topic__invalid
149
150 atf_add_test_case too_many_arguments
151 }
152