Improve the process for GNU tools
[minix3.git] / external / bsd / kyua-cli / dist / integration / cmd_db_exec_test.sh
blob529b1533c43ccd15f86ceabf3310c613c5d986f6
1 # Copyright 2011 Google Inc.
2 # All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
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 utils_test_case one_arg
31 one_arg_body() {
32 atf_check -s exit:0 -o save:metadata.csv -e empty \
33 kyua db-exec "SELECT * FROM metadata"
34 atf_check -s exit:0 -o ignore -e empty \
35 grep 'schema_version,.*timestamp' metadata.csv
39 utils_test_case many_args
40 many_args_body() {
41 atf_check -s exit:0 -o save:metadata.csv -e empty \
42 kyua db-exec SELECT "*" FROM metadata
43 atf_check -s exit:0 -o ignore -e empty \
44 grep 'schema_version,.*timestamp' metadata.csv
48 utils_test_case no_args
49 no_args_body() {
50 atf_check -s exit:3 -o empty -e match:"Not enough arguments" kyua db-exec
51 test ! -f .kyua/store.db || atf_fail "Database created but it should" \
52 "not have been"
56 utils_test_case invalid_statement
57 invalid_statement_body() {
58 atf_check -s exit:1 -o empty -e match:"SQLite error.*foo" \
59 kyua db-exec foo
60 test -f .kyua/store.db || atf_fail "Database not created as part of" \
61 "initialization"
65 utils_test_case store_flag__default_home
66 store_flag__default_home_body() {
67 HOME=home-dir
68 atf_check -s exit:0 -o save:metadata.csv -e empty \
69 kyua db-exec "SELECT * FROM metadata"
70 test -f home-dir/.kyua/store.db || atf_fail "Database not created in" \
71 "the home directory"
72 atf_check -s exit:0 -o ignore -e empty \
73 grep 'schema_version,.*timestamp' metadata.csv
77 utils_test_case store_flag__explicit__ok
78 store_flag__explicit__ok_body() {
79 HOME=home-dir
80 atf_check -s exit:0 -o save:metadata.csv -e empty \
81 kyua --logfile=/dev/null db-exec -s store.db "SELECT * FROM metadata"
82 test ! -d home-dir/.kyua || atf_fail "Home directory created but this" \
83 "should not have happened"
84 test -f store.db || atf_fail "Database not created in expected directory"
85 atf_check -s exit:0 -o ignore -e empty \
86 grep 'schema_version,.*timestamp' metadata.csv
90 utils_test_case store_flag__explicit__fail
91 store_flag__explicit__fail_head() {
92 atf_set "require.user" "unprivileged"
94 store_flag__explicit__fail_body() {
95 mkdir dir
96 chmod 555 dir
97 atf_check -s exit:2 -o empty -e match:"Cannot open.*dir/foo.db" \
98 kyua db-exec --store=dir/foo.db "SELECT * FROM metadata"
102 utils_test_case no_headers_flag
103 no_headers_flag_body() {
104 atf_check kyua db-exec "CREATE TABLE data" \
105 "(a INTEGER PRIMARY KEY, b INTEGER, c TEXT)"
106 atf_check kyua db-exec "INSERT INTO data VALUES (65, 43, NULL)"
107 atf_check kyua db-exec "INSERT INTO data VALUES (23, 42, 'foo')"
109 cat >expout <<EOF
110 a,b,c
111 23,42,foo
112 65,43,NULL
114 atf_check -s exit:0 -o file:expout -e empty \
115 kyua db-exec "SELECT * FROM data ORDER BY a"
117 tail -n 2 <expout >expout2
118 atf_check -s exit:0 -o file:expout2 -e empty \
119 kyua db-exec --no-headers "SELECT * FROM data ORDER BY a"
123 atf_init_test_cases() {
124 atf_add_test_case one_arg
125 atf_add_test_case many_args
126 atf_add_test_case no_args
127 atf_add_test_case invalid_statement
129 atf_add_test_case store_flag__default_home
130 atf_add_test_case store_flag__explicit__ok
131 atf_add_test_case store_flag__explicit__fail
133 atf_add_test_case no_headers_flag