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 # Creates a new database file in the store directory.
32 # Subsequent invocations of db-exec should just pick this new file up.
33 create_empty_store() {
37 atf_check -s exit:0 -o ignore -e empty kyua test
41 utils_test_case one_arg
45 atf_check -s exit:0 -o save:metadata.csv -e empty \
46 kyua db-exec "SELECT * FROM metadata"
47 atf_check -s exit:0 -o ignore -e empty \
48 grep 'schema_version,.*timestamp' metadata.csv
52 utils_test_case many_args
56 atf_check -s exit:0 -o save:metadata.csv -e empty \
57 kyua db-exec SELECT "*" FROM metadata
58 atf_check -s exit:0 -o ignore -e empty \
59 grep 'schema_version,.*timestamp' metadata.csv
63 utils_test_case no_args
65 atf_check -s exit:3 -o empty -e match:"Not enough arguments" kyua db-exec
66 test ! -d .kyua/store/ || atf_fail "Database created but it should" \
71 utils_test_case invalid_statement
72 invalid_statement_body() {
75 atf_check -s exit:1 -o empty -e match:"SQLite error.*foo" \
80 utils_test_case no_create_store
81 no_create_store_body() {
82 atf_check -s exit:1 -o empty -e match:"No previous results.*not-here" \
83 kyua db-exec --results-file=not-here "SELECT * FROM metadata"
84 if [ -f not-here ]; then
85 atf_fail "Database created but it should not have been"
90 utils_test_case results_file__default_home
91 results_file__default_home_body() {
95 atf_check -s exit:0 -o save:metadata.csv -e empty \
96 kyua db-exec "SELECT * FROM metadata"
97 test -f home-dir/.kyua/store/*.db || atf_fail "Database not created in" \
99 atf_check -s exit:0 -o ignore -e empty \
100 grep 'schema_version,.*timestamp' metadata.csv
104 utils_test_case results_file__explicit__ok
105 results_file__explicit__ok_body() {
107 mv .kyua/store/*.db custom.db
111 atf_check -s exit:0 -o save:metadata.csv -e empty \
112 kyua --logfile=/dev/null db-exec -r custom.db "SELECT * FROM metadata"
113 test ! -d home-dir/.kyua || atf_fail "Home directory created but this" \
114 "should not have happened"
115 atf_check -s exit:0 -o ignore -e empty \
116 grep 'schema_version,.*timestamp' metadata.csv
120 utils_test_case results_file__explicit__fail
121 results_file__explicit__fail_head() {
122 atf_set "require.user" "unprivileged"
124 results_file__explicit__fail_body() {
125 atf_check -s exit:1 -o empty -e match:"No previous results.*foo.db" \
126 kyua db-exec --results-file=foo.db "SELECT * FROM metadata"
130 utils_test_case no_headers_flag
131 no_headers_flag_body() {
134 atf_check kyua db-exec "CREATE TABLE data" \
135 "(a INTEGER PRIMARY KEY, b INTEGER, c TEXT)"
136 atf_check kyua db-exec "INSERT INTO data VALUES (65, 43, NULL)"
137 atf_check kyua db-exec "INSERT INTO data VALUES (23, 42, 'foo')"
144 atf_check -s exit:0 -o file:expout -e empty \
145 kyua db-exec "SELECT * FROM data ORDER BY a"
147 tail -n 2 <expout >expout2
148 atf_check -s exit:0 -o file:expout2 -e empty \
149 kyua db-exec --no-headers "SELECT * FROM data ORDER BY a"
153 atf_init_test_cases() {
154 atf_add_test_case one_arg
155 atf_add_test_case many_args
156 atf_add_test_case no_args
157 atf_add_test_case invalid_statement
158 atf_add_test_case no_create_store
160 atf_add_test_case results_file__default_home
161 atf_add_test_case results_file__explicit__ok
162 atf_add_test_case results_file__explicit__fail
164 atf_add_test_case no_headers_flag