Use cleaner idiom to capture output and return code
[xapian.git] / xapian-applications / omega / omegatest
bloba682a8daf217b96a27e201b36d924e964c045a03
1 #!/bin/sh
2 # omegatest: Test omega CGI
4 # Copyright (C) 2015,2016,2017,2018 Olly Betts
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 # USA
20 set -e
22 : ${OMEGA=./omega}
23 : ${SCRIPTINDEX=./scriptindex}
25 # Suppress HTTP Content-Type header.
26 SERVER_PROTOCOL=INCLUDED
27 export SERVER_PROTOCOL
29 # Set up an empty database.
30 TEST_DB=test-db
31 rm -rf "$TEST_DB"
32 echo 'inmemory' > "$TEST_DB"
34 # Simple template which just shows the parsed query.
35 TEST_TEMPLATE=test-template
36 printf '$querydescription' > "$TEST_TEMPLATE"
38 TEST_INDEXSCRIPT=test-indexscript
40 OMEGA_CONFIG_FILE=test-omega.conf
41 export OMEGA_CONFIG_FILE
42 cat > "$OMEGA_CONFIG_FILE" <<__END__
43 database_dir .
44 template_dir .
45 log_dir tmplog
46 default_template $TEST_TEMPLATE
47 default_db $TEST_DB
48 __END__
50 failed=0
52 testcase() {
53 expected=$1
54 shift
55 # If there are no positional parameters, pass one as otherwise omega will
56 # wait for parameters on stdin.
57 [ "$#" != 0 ] || set - dummy
58 output=`$FAKETIME ${FAKE_NOW+"$FAKE_NOW"} "$OMEGA" "$@"`
59 if [ "$output" != "$expected" ] ; then
60 echo "$OMEGA $@:"
61 echo " expected: «$expected»"
62 echo " received: «$output»"
63 failed=`expr $failed + 1`
67 qtestcase() {
68 expected="Query($1)"
69 shift
70 testcase "$expected" "$@"
73 FAKETIME=
74 unset FAKE_NOW
76 # Test a few simple things.
77 qtestcase 'Zsimpl@1' P=simple
78 qtestcase '(chocolate@1 FILTER Tconfectionary/fudge)' P=Chocolate B=Tconfectionary/fudge
80 # Test date value ranges.
81 qtestcase 'VALUE_RANGE 0 2 ~' DATEVALUE=0 START=2000
82 qtestcase 'VALUE_RANGE 0 2 ~' DATEVALUE=0 START=200001
83 qtestcase 'VALUE_RANGE 0 2 ~' DATEVALUE=0 START=20000101
84 qtestcase 'VALUE_LE 1 1~' DATEVALUE=1 END=1999
85 qtestcase 'VALUE_LE 1 1~' DATEVALUE=1 END=199912
86 qtestcase 'VALUE_LE 1 1~' DATEVALUE=1 END=19991231
87 qtestcase 'VALUE_RANGE 2 201 ~' DATEVALUE=2 START=2010
88 qtestcase 'VALUE_RANGE 2 201 ~' DATEVALUE=2 START=201001
89 qtestcase 'VALUE_RANGE 2 201 ~' DATEVALUE=2 START=20100101
90 qtestcase 'VALUE_LE 3 198~' DATEVALUE=3 END=1989
91 qtestcase 'VALUE_LE 3 198~' DATEVALUE=3 END=198912
92 qtestcase 'VALUE_LE 3 198~' DATEVALUE=3 END=19891231
93 qtestcase 'VALUE_RANGE 4 1974 ~' DATEVALUE=4 START=1974
94 qtestcase 'VALUE_RANGE 4 1974 ~' DATEVALUE=4 START=197401
95 qtestcase 'VALUE_RANGE 4 1974 ~' DATEVALUE=4 START=19740101
96 qtestcase 'VALUE_LE 5 1974~' DATEVALUE=5 END=1974
97 qtestcase 'VALUE_LE 5 1974~' DATEVALUE=5 END=197412
98 qtestcase 'VALUE_LE 5 1974~' DATEVALUE=5 END=19741231
99 qtestcase 'VALUE_RANGE 6 20151 ~' DATEVALUE=6 START=201510
100 qtestcase 'VALUE_RANGE 6 20151 ~' DATEVALUE=6 START=20151001
101 qtestcase 'VALUE_LE 7 19870~' DATEVALUE=7 END=198709
102 qtestcase 'VALUE_LE 7 19870~' DATEVALUE=7 END=19870930
103 qtestcase 'VALUE_RANGE 8 201512 ~' DATEVALUE=8 START=201512
104 qtestcase 'VALUE_RANGE 8 201512 ~' DATEVALUE=8 START=20151201
105 qtestcase 'VALUE_LE 9 201511~' DATEVALUE=9 END=201511
106 qtestcase 'VALUE_LE 9 201511~' DATEVALUE=9 END=20151130
107 qtestcase 'VALUE_RANGE 10 2015021 ~' DATEVALUE=10 START=20150210
108 qtestcase 'VALUE_RANGE 10 2000022 ~' DATEVALUE=10 START=20000220
109 qtestcase 'VALUE_LE 11 19840401~' DATEVALUE=11 END=19840401
110 qtestcase 'VALUE_LE 11 19881128~' DATEVALUE=11 END=19881128
112 # Leap year tests:
113 qtestcase 'VALUE_LE 1 201502~' DATEVALUE=1 END=20150228
114 qtestcase 'VALUE_LE 1 198802~' DATEVALUE=1 END=19880229
115 qtestcase 'VALUE_LE 1 19880228~' DATEVALUE=1 END=19880228
116 qtestcase 'VALUE_LE 1 200002~' DATEVALUE=1 END=20000229
117 qtestcase 'VALUE_LE 1 20000228~' DATEVALUE=1 END=20000228
118 # FIXME: These two currently require 64-bit time_t:
119 #qtestcase 'VALUE_LE 1 190002~' DATEVALUE=1 END=19000228
120 #qtestcase 'VALUE_LE 1 210002~' DATEVALUE=1 END=21000228
122 # Month starts and ends:
123 qtestcase 'VALUE_RANGE 0 2015 201501~' DATEVALUE=0 START=20150101 END=20150131
124 qtestcase 'VALUE_RANGE 0 2015 20150130~' DATEVALUE=0 START=20150101 END=20150130
125 qtestcase 'VALUE_RANGE 0 201502 201502~' DATEVALUE=0 START=20150201 END=20150228
126 qtestcase 'VALUE_RANGE 0 201502 20150227~' DATEVALUE=0 START=20150201 END=20150227
127 qtestcase 'VALUE_RANGE 0 201503 201503~' DATEVALUE=0 START=20150301 END=20150331
128 qtestcase 'VALUE_RANGE 0 201503 20150330~' DATEVALUE=0 START=20150301 END=20150330
129 qtestcase 'VALUE_RANGE 0 201504 201504~' DATEVALUE=0 START=20150401 END=20150430
130 qtestcase 'VALUE_RANGE 0 201504 2015042~' DATEVALUE=0 START=20150401 END=20150429
131 qtestcase 'VALUE_RANGE 0 201505 201505~' DATEVALUE=0 START=20150501 END=20150531
132 qtestcase 'VALUE_RANGE 0 201505 20150530~' DATEVALUE=0 START=20150501 END=20150530
133 qtestcase 'VALUE_RANGE 0 201506 201506~' DATEVALUE=0 START=20150601 END=20150630
134 qtestcase 'VALUE_RANGE 0 201506 2015062~' DATEVALUE=0 START=20150601 END=20150629
135 qtestcase 'VALUE_RANGE 0 201507 201507~' DATEVALUE=0 START=20150701 END=20150731
136 qtestcase 'VALUE_RANGE 0 201507 20150730~' DATEVALUE=0 START=20150701 END=20150730
137 qtestcase 'VALUE_RANGE 0 201508 201508~' DATEVALUE=0 START=20150801 END=20150831
138 qtestcase 'VALUE_RANGE 0 201508 20150830~' DATEVALUE=0 START=20150801 END=20150830
139 qtestcase 'VALUE_RANGE 0 201509 20150~' DATEVALUE=0 START=20150901 END=20150930
140 qtestcase 'VALUE_RANGE 0 201509 2015092~' DATEVALUE=0 START=20150901 END=20150929
141 qtestcase 'VALUE_RANGE 0 20151 201510~' DATEVALUE=0 START=20151001 END=20151031
142 qtestcase 'VALUE_RANGE 0 20151 20151030~' DATEVALUE=0 START=20151001 END=20151030
143 qtestcase 'VALUE_RANGE 0 201511 201511~' DATEVALUE=0 START=20151101 END=20151130
144 qtestcase 'VALUE_RANGE 0 201511 2015112~' DATEVALUE=0 START=20151101 END=20151129
145 qtestcase 'VALUE_RANGE 0 201512 2015~' DATEVALUE=0 START=20151201 END=20151231
146 qtestcase 'VALUE_RANGE 0 201512 20151230~' DATEVALUE=0 START=20151201 END=20151230
148 # Forward spans:
149 qtestcase 'VALUE_RANGE 0 20151104 20151106~' DATEVALUE=0 START=20151104 SPAN=3
150 qtestcase 'VALUE_RANGE 0 20141104 20151103~' DATEVALUE=0 START=20141104 SPAN=365
152 # Backward spans:
153 qtestcase 'VALUE_RANGE 0 20151104 20151106~' DATEVALUE=0 END=20151106 SPAN=3
154 qtestcase 'VALUE_RANGE 0 20141104 20151103~' DATEVALUE=0 END=20151103 SPAN=365
156 # Check that if START, END and SPAN are all passed, START is ignored:
157 qtestcase 'VALUE_RANGE 0 20151104 20151106~' DATEVALUE=0 START=19700101 END=20151106 SPAN=3
159 # Tests of term-based date range filtering:
161 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999) OR Dlatest)' END=19991231
162 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989) OR Dlatest)' END=19891231
163 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974) OR Dlatest)' END=19741231
164 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR M198701 OR M198702 OR M198703 OR M198704 OR M198705 OR M198706 OR M198707 OR M198708 OR M198709) OR Dlatest)' END=19870930
165 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999 OR Y2000 OR Y2001 OR Y2002 OR Y2003 OR Y2004 OR Y2005 OR Y2006 OR Y2007 OR Y2008 OR Y2009 OR Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR M201511) OR Dlatest)' END=20151130
166 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR M198401 OR M198402 OR M198403 OR D19840401) OR Dlatest)' END=19840401
167 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR M198801 OR M198802 OR M198803 OR M198804 OR M198805 OR M198806 OR M198807 OR M198808 OR M198809 OR M198810 OR D19881101 OR D19881102 OR D19881103 OR D19881104 OR D19881105 OR D19881106 OR D19881107 OR D19881108 OR D19881109 OR D19881110 OR D19881111 OR D19881112 OR D19881113 OR D19881114 OR D19881115 OR D19881116 OR D19881117 OR D19881118 OR D19881119 OR D19881120 OR D19881121 OR D19881122 OR D19881123 OR D19881124 OR D19881125 OR D19881126 OR D19881127 OR D19881128) OR Dlatest)' END=19881128
169 # Leap year tests:
170 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999 OR Y2000 OR Y2001 OR Y2002 OR Y2003 OR Y2004 OR Y2005 OR Y2006 OR Y2007 OR Y2008 OR Y2009 OR Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR M201501 OR M201502) OR Dlatest)' END=20150228
171 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR M198801 OR M198802) OR Dlatest)' END=19880229
172 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR M198801 OR D19880201 OR D19880202 OR D19880203 OR D19880204 OR D19880205 OR D19880206 OR D19880207 OR D19880208 OR D19880209 OR D19880210 OR D19880211 OR D19880212 OR D19880213 OR D19880214 OR D19880215 OR D19880216 OR D19880217 OR D19880218 OR D19880219 OR D19880220 OR D19880221 OR D19880222 OR D19880223 OR D19880224 OR D19880225 OR D19880226 OR D19880227 OR D19880228) OR Dlatest)' END=19880228
173 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999 OR M200001 OR M200002) OR Dlatest)' END=20000229
174 qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999 OR M200001 OR D20000201 OR D20000202 OR D20000203 OR D20000204 OR D20000205 OR D20000206 OR D20000207 OR D20000208 OR D20000209 OR D20000210 OR D20000211 OR D20000212 OR D20000213 OR D20000214 OR D20000215 OR D20000216 OR D20000217 OR D20000218 OR D20000219 OR D20000220 OR D20000221 OR D20000222 OR D20000223 OR D20000224 OR D20000225 OR D20000226 OR D20000227 OR D20000228) OR Dlatest)' END=20000228
175 # FIXME: These two currently require 64-bit time_t:
176 #qtestcase 'Dlatest' END=19000228 # Assumed start is 19700101
177 #qtestcase '((Y1970 OR Y1971 OR Y1972 OR Y1973 OR Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999 OR Y2000 OR Y2001 OR Y2002 OR Y2003 OR Y2004 OR Y2005 OR Y2006 OR Y2007 OR Y2008 OR Y2009 OR Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR Y2015 OR Y2016 OR Y2017 OR Y2018 OR Y2019 OR Y2020 OR Y2021 OR Y2022 OR Y2023 OR Y2024 OR Y2025 OR Y2026 OR Y2027 OR Y2028 OR Y2029 OR Y2030 OR Y2031 OR Y2032 OR Y2033 OR Y2034 OR Y2035 OR Y2036 OR Y2037 OR Y2038 OR Y2039 OR Y2040 OR Y2041 OR Y2042 OR Y2043 OR Y2044 OR Y2045 OR Y2046 OR Y2047 OR Y2048 OR Y2049 OR Y2050 OR Y2051 OR Y2052 OR Y2053 OR Y2054 OR Y2055 OR Y2056 OR Y2057 OR Y2058 OR Y2059 OR Y2060 OR Y2061 OR Y2062 OR Y2063 OR Y2064 OR Y2065 OR Y2066 OR Y2067 OR Y2068 OR Y2069 OR Y2070 OR Y2071 OR Y2072 OR Y2073 OR Y2074 OR Y2075 OR Y2076 OR Y2077 OR Y2078 OR Y2079 OR Y2080 OR Y2081 OR Y2082 OR Y2083 OR Y2084 OR Y2085 OR Y2086 OR Y2087 OR Y2088 OR Y2089 OR Y2090 OR Y2091 OR Y2092 OR Y2093 OR Y2094 OR Y2095 OR Y2096 OR Y2097 OR Y2098 OR Y2099 OR M210001 OR M210002) OR Dlatest)' END=21000228
179 # Month starts and ends:
180 qtestcase '(M201501 OR Dlatest)' START=20150101 END=20150131
181 qtestcase '((D20150101 OR D20150102 OR D20150103 OR D20150104 OR D20150105 OR D20150106 OR D20150107 OR D20150108 OR D20150109 OR D20150110 OR D20150111 OR D20150112 OR D20150113 OR D20150114 OR D20150115 OR D20150116 OR D20150117 OR D20150118 OR D20150119 OR D20150120 OR D20150121 OR D20150122 OR D20150123 OR D20150124 OR D20150125 OR D20150126 OR D20150127 OR D20150128 OR D20150129 OR D20150130) OR Dlatest)' START=20150101 END=20150130
182 qtestcase '(M201502 OR Dlatest)' START=20150201 END=20150228
183 qtestcase '((D20150201 OR D20150202 OR D20150203 OR D20150204 OR D20150205 OR D20150206 OR D20150207 OR D20150208 OR D20150209 OR D20150210 OR D20150211 OR D20150212 OR D20150213 OR D20150214 OR D20150215 OR D20150216 OR D20150217 OR D20150218 OR D20150219 OR D20150220 OR D20150221 OR D20150222 OR D20150223 OR D20150224 OR D20150225 OR D20150226 OR D20150227) OR Dlatest)' START=20150201 END=20150227
184 qtestcase '(M201503 OR Dlatest)' START=20150301 END=20150331
185 qtestcase '((D20150301 OR D20150302 OR D20150303 OR D20150304 OR D20150305 OR D20150306 OR D20150307 OR D20150308 OR D20150309 OR D20150310 OR D20150311 OR D20150312 OR D20150313 OR D20150314 OR D20150315 OR D20150316 OR D20150317 OR D20150318 OR D20150319 OR D20150320 OR D20150321 OR D20150322 OR D20150323 OR D20150324 OR D20150325 OR D20150326 OR D20150327 OR D20150328 OR D20150329 OR D20150330) OR Dlatest)' START=20150301 END=20150330
186 qtestcase '(M201504 OR Dlatest)' START=20150401 END=20150430
187 qtestcase '((D20150401 OR D20150402 OR D20150403 OR D20150404 OR D20150405 OR D20150406 OR D20150407 OR D20150408 OR D20150409 OR D20150410 OR D20150411 OR D20150412 OR D20150413 OR D20150414 OR D20150415 OR D20150416 OR D20150417 OR D20150418 OR D20150419 OR D20150420 OR D20150421 OR D20150422 OR D20150423 OR D20150424 OR D20150425 OR D20150426 OR D20150427 OR D20150428 OR D20150429) OR Dlatest)' START=20150401 END=20150429
188 qtestcase '(M201505 OR Dlatest)' START=20150501 END=20150531
189 qtestcase '((D20150501 OR D20150502 OR D20150503 OR D20150504 OR D20150505 OR D20150506 OR D20150507 OR D20150508 OR D20150509 OR D20150510 OR D20150511 OR D20150512 OR D20150513 OR D20150514 OR D20150515 OR D20150516 OR D20150517 OR D20150518 OR D20150519 OR D20150520 OR D20150521 OR D20150522 OR D20150523 OR D20150524 OR D20150525 OR D20150526 OR D20150527 OR D20150528 OR D20150529 OR D20150530) OR Dlatest)' START=20150501 END=20150530
190 qtestcase '(M201506 OR Dlatest)' START=20150601 END=20150630
191 qtestcase '((D20150601 OR D20150602 OR D20150603 OR D20150604 OR D20150605 OR D20150606 OR D20150607 OR D20150608 OR D20150609 OR D20150610 OR D20150611 OR D20150612 OR D20150613 OR D20150614 OR D20150615 OR D20150616 OR D20150617 OR D20150618 OR D20150619 OR D20150620 OR D20150621 OR D20150622 OR D20150623 OR D20150624 OR D20150625 OR D20150626 OR D20150627 OR D20150628 OR D20150629) OR Dlatest)' START=20150601 END=20150629
192 qtestcase '(M201507 OR Dlatest)' START=20150701 END=20150731
193 qtestcase '((D20150701 OR D20150702 OR D20150703 OR D20150704 OR D20150705 OR D20150706 OR D20150707 OR D20150708 OR D20150709 OR D20150710 OR D20150711 OR D20150712 OR D20150713 OR D20150714 OR D20150715 OR D20150716 OR D20150717 OR D20150718 OR D20150719 OR D20150720 OR D20150721 OR D20150722 OR D20150723 OR D20150724 OR D20150725 OR D20150726 OR D20150727 OR D20150728 OR D20150729 OR D20150730) OR Dlatest)' START=20150701 END=20150730
194 qtestcase '(M201508 OR Dlatest)' START=20150801 END=20150831
195 qtestcase '((D20150801 OR D20150802 OR D20150803 OR D20150804 OR D20150805 OR D20150806 OR D20150807 OR D20150808 OR D20150809 OR D20150810 OR D20150811 OR D20150812 OR D20150813 OR D20150814 OR D20150815 OR D20150816 OR D20150817 OR D20150818 OR D20150819 OR D20150820 OR D20150821 OR D20150822 OR D20150823 OR D20150824 OR D20150825 OR D20150826 OR D20150827 OR D20150828 OR D20150829 OR D20150830) OR Dlatest)' START=20150801 END=20150830
196 qtestcase '(M201509 OR Dlatest)' START=20150901 END=20150930
197 qtestcase '((D20150901 OR D20150902 OR D20150903 OR D20150904 OR D20150905 OR D20150906 OR D20150907 OR D20150908 OR D20150909 OR D20150910 OR D20150911 OR D20150912 OR D20150913 OR D20150914 OR D20150915 OR D20150916 OR D20150917 OR D20150918 OR D20150919 OR D20150920 OR D20150921 OR D20150922 OR D20150923 OR D20150924 OR D20150925 OR D20150926 OR D20150927 OR D20150928 OR D20150929) OR Dlatest)' START=20150901 END=20150929
198 qtestcase '(M201510 OR Dlatest)' START=20151001 END=20151031
199 qtestcase '((D20151001 OR D20151002 OR D20151003 OR D20151004 OR D20151005 OR D20151006 OR D20151007 OR D20151008 OR D20151009 OR D20151010 OR D20151011 OR D20151012 OR D20151013 OR D20151014 OR D20151015 OR D20151016 OR D20151017 OR D20151018 OR D20151019 OR D20151020 OR D20151021 OR D20151022 OR D20151023 OR D20151024 OR D20151025 OR D20151026 OR D20151027 OR D20151028 OR D20151029 OR D20151030) OR Dlatest)' START=20151001 END=20151030
200 qtestcase '(M201511 OR Dlatest)' START=20151101 END=20151130
201 qtestcase '((D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128 OR D20151129) OR Dlatest)' START=20151101 END=20151129
202 qtestcase '(M201512 OR Dlatest)' START=20151201 END=20151231
203 qtestcase '((D20151201 OR D20151202 OR D20151203 OR D20151204 OR D20151205 OR D20151206 OR D20151207 OR D20151208 OR D20151209 OR D20151210 OR D20151211 OR D20151212 OR D20151213 OR D20151214 OR D20151215 OR D20151216 OR D20151217 OR D20151218 OR D20151219 OR D20151220 OR D20151221 OR D20151222 OR D20151223 OR D20151224 OR D20151225 OR D20151226 OR D20151227 OR D20151228 OR D20151229 OR D20151230) OR Dlatest)' START=20151201 END=20151230
205 # Forward spans:
206 qtestcase '((D20151104 OR D20151105 OR D20151106 OR D20151107) OR Dlatest)' START=20151104 SPAN=3
207 qtestcase '((D20141104 OR D20141105 OR D20141106 OR D20141107 OR D20141108 OR D20141109 OR D20141110 OR D20141111 OR D20141112 OR D20141113 OR D20141114 OR D20141115 OR D20141116 OR D20141117 OR D20141118 OR D20141119 OR D20141120 OR D20141121 OR D20141122 OR D20141123 OR D20141124 OR D20141125 OR D20141126 OR D20141127 OR D20141128 OR D20141129 OR D20141130 OR M201412 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104) OR Dlatest)' START=20141104 SPAN=365
209 # Backward spans:
210 qtestcase '((D20151103 OR D20151104 OR D20151105 OR D20151106) OR Dlatest)' END=20151106 SPAN=3
211 qtestcase '((D20141103 OR D20141104 OR D20141105 OR D20141106 OR D20141107 OR D20141108 OR D20141109 OR D20141110 OR D20141111 OR D20141112 OR D20141113 OR D20141114 OR D20141115 OR D20141116 OR D20141117 OR D20141118 OR D20141119 OR D20141120 OR D20141121 OR D20141122 OR D20141123 OR D20141124 OR D20141125 OR D20141126 OR D20141127 OR D20141128 OR D20141129 OR D20141130 OR M201412 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103) OR Dlatest)' END=20151103 SPAN=365
213 # Check that if START, END and SPAN are all passed, START is ignored:
214 qtestcase '((D20151103 OR D20151104 OR D20151105 OR D20151106) OR Dlatest)' START=19700101 END=20151106 SPAN=3
216 # Check combining of filter terms:
217 qtestcase '(Horg AND Len)' B=Len B=Horg
218 qtestcase '(Len OR Lde)' B=Len B=Lde
219 qtestcase '((Horg OR Hcom) AND (Len OR Lfr))' B=Len B=Lfr B=Horg B=Hcom
221 # Check combining of filter terms with filter_op set:
222 printf '$setmap{nonexclusiveprefix,L,1,XAND,1}$setmap{boolprefix,lang,L,and,XAND,host,H,year,Y}$querydescription' > "$TEST_TEMPLATE"
223 qtestcase 'Len' B=Len
224 qtestcase '0 * Len' P=lang:en
225 qtestcase 'XANDtest' B=XANDtest
226 qtestcase '0 * XANDtest' P=and:test
227 qtestcase '(Len AND XANDtest)' B=Len B=XANDtest
228 qtestcase '0 * (Len AND XANDtest)' P='lang:en and:test'
229 qtestcase '(Len AND Lde)' B=Len B=Lde
230 qtestcase '0 * (Len AND Lde)' P='lang:en lang:de'
231 qtestcase '((Horg OR Hcom) AND (Len AND Lfr))' B=Len B=Lfr B=Horg B=Hcom
232 qtestcase '0 * ((Len AND Lfr) AND (Horg OR Hcom))' P='lang:en lang:fr host:org host:com'
233 qtestcase '((XANDa AND XANDb AND XANDc) AND (Y1998 OR Y2001))' B=Y1998 B=Y2001 B=XANDa B=XANDb B=XANDc
234 qtestcase '0 * (((XANDa AND XANDb) AND XANDc) AND (Y1998 OR Y2001))' P='year:1998 year:2001 and:a and:b and:c'
236 # Check combining of filters around CGI parameter 'N':
237 qtestcase '(Ztruth@1 AND_NOT Epdf)' P=truth N=Epdf
238 qtestcase '(Ztruth@1 AND_NOT (Ehtm OR Epdf))' P=truth N=Epdf N=Ehtm
239 qtestcase '(Ztruth@1 AND_NOT (Ehtm OR Epdf OR Lde OR Lfr))' P=truth N=Lfr N=Epdf N=Ehtm N=Lde
240 qtestcase '((Ztruth@1 FILTER (Lfr AND Lzh)) AND_NOT (Lde OR Len))' P=truth N=Lde N=Len B=Lfr B=Lzh
241 qtestcase '((Ztruth@1 FILTER Lfr) AND_NOT (Ehtm OR Epdf))' P=truth N=Epdf N=Ehtm B=Lfr
242 qtestcase '(<alldocuments> AND_NOT (Len OR Lfr))' N=Lfr N=Len
243 qtestcase '(VALUE_RANGE 0 2015 201501~ AND_NOT Len)' DATEVALUE=0 START=20150101 END=20150131 N=Len
245 # If faketime is available and works, test cases where the output depends on
246 # "now".
247 rc=0
248 out=`faketime -f '1980-12-08 00:00:00' date +%Y 2>&1` || rc=$?
249 if [ "$rc:$out" = "0:1980" ] ; then
250 TZ=UTC
251 export TZ
252 FAKETIME='faketime -f'
253 FAKE_NOW='2015-11-28 06:07:08'
254 qtestcase 'VALUE_RANGE 0 20151127060709 20151128060708' DATEVALUE=0 SPAN=1
256 # Tests of term-based date range filtering:
257 qtestcase '((Y2000 OR Y2001 OR Y2002 OR Y2003 OR Y2004 OR Y2005 OR Y2006 OR Y2007 OR Y2008 OR Y2009 OR Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128) OR Dlatest)' START=20000101
258 qtestcase '((Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128) OR Dlatest)' START=20100101
259 qtestcase '((Y1974 OR Y1975 OR Y1976 OR Y1977 OR Y1978 OR Y1979 OR Y1980 OR Y1981 OR Y1982 OR Y1983 OR Y1984 OR Y1985 OR Y1986 OR Y1987 OR Y1988 OR Y1989 OR Y1990 OR Y1991 OR Y1992 OR Y1993 OR Y1994 OR Y1995 OR Y1996 OR Y1997 OR Y1998 OR Y1999 OR Y2000 OR Y2001 OR Y2002 OR Y2003 OR Y2004 OR Y2005 OR Y2006 OR Y2007 OR Y2008 OR Y2009 OR Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128) OR Dlatest)' START=19740101
260 qtestcase '((M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128) OR Dlatest)' START=20151001
261 # Date range with start after end:
262 qtestcase 'Dlatest' START=201512
263 qtestcase 'Dlatest' START=20151201
264 qtestcase '((D20150210 OR D20150211 OR D20150212 OR D20150213 OR D20150214 OR D20150215 OR D20150216 OR D20150217 OR D20150218 OR D20150219 OR D20150220 OR D20150221 OR D20150222 OR D20150223 OR D20150224 OR D20150225 OR D20150226 OR D20150227 OR D20150228 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128) OR Dlatest)' START=20150210
265 qtestcase '((D20000220 OR D20000221 OR D20000222 OR D20000223 OR D20000224 OR D20000225 OR D20000226 OR D20000227 OR D20000228 OR D20000229 OR M200003 OR M200004 OR M200005 OR M200006 OR M200007 OR M200008 OR M200009 OR M200010 OR M200011 OR M200012 OR Y2001 OR Y2002 OR Y2003 OR Y2004 OR Y2005 OR Y2006 OR Y2007 OR Y2008 OR Y2009 OR Y2010 OR Y2011 OR Y2012 OR Y2013 OR Y2014 OR M201501 OR M201502 OR M201503 OR M201504 OR M201505 OR M201506 OR M201507 OR M201508 OR M201509 OR M201510 OR D20151101 OR D20151102 OR D20151103 OR D20151104 OR D20151105 OR D20151106 OR D20151107 OR D20151108 OR D20151109 OR D20151110 OR D20151111 OR D20151112 OR D20151113 OR D20151114 OR D20151115 OR D20151116 OR D20151117 OR D20151118 OR D20151119 OR D20151120 OR D20151121 OR D20151122 OR D20151123 OR D20151124 OR D20151125 OR D20151126 OR D20151127 OR D20151128) OR Dlatest)' START=20000220
266 FAKETIME=
267 unset FAKE_NOW
268 else
269 if [ "$rc" = 127 ] ; then
270 echo "Skipping testcases which need 'faketime' tool installed"
271 else
272 echo "Skipping testcases which need 'faketime' tool - it's installed but doesn't work"
276 # Test stem_all and stem_strategy.
277 printf '$if{$cgi{stem_all},$set{stem_all,$cgi{stem_all}}}$if{$cgi{stem_strategy},$set{stem_strategy,$cgi{stem_strategy}}}$querydescription' > "$TEST_TEMPLATE"
278 qtestcase '((capitalised@1 AND tests@2) AND Zstem@3)' P='Capitalised "tests" stemmed'
279 qtestcase '(nearing@1 NEAR 11 distances@2)' P='nearing NEAR distances'
280 qtestcase '((capitalis@1 AND test@2) AND stem@3)' P='Capitalised "tests" stemmed' stem_all=true
281 qtestcase '(near@1 NEAR 11 distanc@2)' P='nearing NEAR distances' stem_all=true
282 qtestcase '((capitalis@1 AND test@2) AND stem@3)' P='Capitalised "tests" stemmed' stem_strategy=all
283 qtestcase '(near@1 NEAR 11 distanc@2)' P='nearing NEAR distances' stem_strategy=all
284 qtestcase '((Zcapitalis@1 AND Ztest@2) AND Zstem@3)' P='Capitalised "tests" stemmed' stem_strategy=all_z
285 qtestcase '(Znear@1 NEAR 11 Zdistanc@2)' P='nearing NEAR distances' stem_strategy=all_z
286 qtestcase '((capitalised@1 AND tests@2) AND stemmed@3)' P='Capitalised "tests" stemmed' stem_strategy=none
287 qtestcase '(nearing@1 NEAR 11 distances@2)' P='nearing NEAR distances' stem_strategy=none
288 qtestcase '((capitalised@1 AND tests@2) AND Zstem@3)' P='Capitalised "tests" stemmed' stem_strategy=some
289 qtestcase '(nearing@1 NEAR 11 distances@2)' P='nearing NEAR distances' stem_strategy=some
290 qtestcase '((capitalised@1 AND tests@2) AND Zstem@3)' P='Capitalised "tests" stemmed' stem_strategy=some_full_pos
291 qtestcase '(Znear@1 NEAR 11 Zdistanc@2)' P='nearing NEAR distances' stem_strategy=some_full_pos
292 qtestcase '((capitalised@1 AND tests@2) AND Zstem@3)' P='Capitalised "tests" stemmed' stem_strategy=some stem_all=true
293 qtestcase '(nearing@1 NEAR 11 distances@2)' P='nearing NEAR distances' stem_strategy=some stem_all=true
295 # Feature tests for $contains.
296 printf '$contains{$cgi{a},$cgi{b}}' > "$TEST_TEMPLATE"
297 testcase '6' P=text a=fish b="Hello fish"
298 testcase '' P=text a="Example" b="random"
300 NEWLINE='
303 # Feature tests for boolprefix and prefix maps.
304 printf '$set{stemmer,}$setmap{boolprefix,lang,L,host,H}$setmap{prefix,,XDEFAULT}$querydescription' > "$TEST_TEMPLATE"
305 qtestcase '((XDEFAULTfoo@1 AND XDEFAULTbar@2) FILTER (Hexample.org AND Lzh))' P='host:example.org foo bar lang:zh'
307 # Feature tests for $cond.
308 printf '$cond{$cgi{one},1,$cgi{two},2,$cgi{three},3}' > "$TEST_TEMPLATE"
309 testcase '1' one=true
310 testcase '2' two=true
311 testcase '3' three=true
312 testcase '' nothing=true
313 testcase '1' one=true two=true three=true
314 testcase '2' two=true three=true
315 printf '$cond{$cgi{one},1,$cgi{two},2,$cgi{alt}}' > "$TEST_TEMPLATE"
316 testcase '1' one=true
317 testcase '2' two=true
318 testcase 'none' alt=none
319 # Check evaluation is lazy.
320 printf '$cond{$cgi{one},$seterror{err1},$cgi{two},2,$cgi{alt}}$error' > "$TEST_TEMPLATE"
321 testcase 'err1' one=true
322 testcase '2' two=true
323 testcase 'none' alt=none
324 printf '$cond{$cgi{one},1,$cgi{two},$seterror{err2},$cgi{alt}}$error' > "$TEST_TEMPLATE"
325 testcase '1' one=true
326 testcase 'err2' two=true
327 testcase 'none' alt=none
328 printf '$cond{$cgi{one},1,$cgi{two},2,$seterror{erralt}}$error' > "$TEST_TEMPLATE"
329 testcase '1' one=true
330 testcase '2' two=true
331 testcase 'erralt' alt=none
333 # Feature tests for $switch.
334 printf '$switch{$cgi{x},1,one,2,two}' > "$TEST_TEMPLATE"
335 testcase 'one' x=1
336 testcase 'two' x=2
337 testcase '' x=3
338 printf '$switch{$cgi{x},1,one,2,two,default}' > "$TEST_TEMPLATE"
339 testcase 'one' x=1
340 testcase 'two' x=2
341 testcase 'default' x=3
342 # Check evaluation is lazy.
343 printf '$switch{$cgi{x},1,$seterror{err1},2,two}$error' > "$TEST_TEMPLATE"
344 testcase 'err1' x=1
345 testcase 'two' x=2
346 testcase '' x=3
347 printf '$switch{$cgi{x},1,one,2,$seterror{err2},default}$error' > "$TEST_TEMPLATE"
348 testcase 'one' x=1
349 testcase 'err2' x=2
350 testcase 'default' x=3
351 printf '$switch{$cgi{x},1,one,2,two,$seterror{errdefault}}$error' > "$TEST_TEMPLATE"
352 testcase 'one' x=1
353 testcase 'two' x=2
354 testcase 'errdefault' x=3
356 # Feature tests for $map.
357 printf '$list{$map{$split{-,$cgi{a}},$list{$map{$split{,$cgi{b}},$_},-}},|}' > "$TEST_TEMPLATE"
358 testcase '1-2-3|1-2-3' P=text a=ab-cd b=123
359 printf '$list{$map{$split{-,$cgi{a}},$set{__,$_}$list{$map{$split{,$cgi{b}},$opt{__}$_},-}},|}' > "$TEST_TEMPLATE"
360 testcase 'a1-a2-a3|b1-b2-b3' P=text a=a-b b=123
361 printf '$list{$map{$split{-,$cgi{a}},$list{$map{$split{$_,$cgi{b}},$_},-}},|}' > "$TEST_TEMPLATE"
362 testcase '1-2,3|1:2-3' P=text a=':-,' b='1:2,3'
363 # Check that the outer $_ is restored after the inner $map.
364 printf '$list{$map{$split{-,$cgi{a}},$list{$map{$split{,$cgi{b}},$_},-}$_},|}' > "$TEST_TEMPLATE"
365 testcase '1-2-3a|1-2-3b' P=text a='a-b' b='123'
367 # Feature tests for $match.
368 printf '$match{$cgi{a},$cgi{b},$cgi{c}}' > "$TEST_TEMPLATE"
369 testcase 'true' P=text a="ab*c+" b="ac"
370 testcase '' P=text a="acb" b="abc"
371 testcase 'true' P=text a="[A-Z]bcD" b="abcd" c="i"
372 testcase '' P=text a="[A-Z]bcD" b="abcd"
373 testcase 'true' P=text a="^abc$" b="${NEWLINE}abc${NEWLINE}def" c="m"
374 testcase '' P=text a="^abc$" b="${NEWLINE}abc${NEWLINE}def"
375 testcase 'true' P=text a="abc." b="abc${NEWLINE}" c="s"
376 testcase '' P=text a="abc." b="abc${NEWLINE}"
377 testcase 'true' P=text a=" ABC #test_comment " b="ABC" c="x"
378 testcase '' P=text a=" ABC #test_comment " b="ABC"
380 # Feature tests for $sort.
381 printf '$list{$sort{$split{|,$cgi{input}}},|}' > "$TEST_TEMPLATE"
382 testcase 'pineapple' input="pineapple"
383 testcase 'apple|banana|coconut' input="coconut|banana|apple"
384 testcase '1|b|b|c' input="b|c|b|1"
385 printf '$list{$sort{$split{|,$cgi{input}},$cgi{opt}},|}' > "$TEST_TEMPLATE"
386 testcase 'pineapple' input="pineapple" opt=
387 testcase 'pineapple' input="pineapple" opt=r
388 testcase 'pineapple' input="pineapple" opt=ru
389 testcase '1|b|c' input="b|c|b|1" opt=u
390 testcase 'c|b|b|1' input="b|c|b|1" opt=r
391 testcase 'c|b|1' input="b|c|b|1" opt=ur
392 testcase '-2|-.01|+99.99|+999|.0|0.0|.1|1|2|3|3.0|3.01|12|23|30' input='+999|2|1|12|23|3|30|3.01|3.0|.1|.0|0.0|-2|-.01|+99.99' opt=n
393 testcase '-2|-.01|+999|.1|1|2|3|3.01|12|23|30' input='+999|2|1|12|23|3|30|3.01|3.0|.1|.0|0.0|-2|-.01|+99.99' opt=nu
394 testcase '-2|-.01|+99.99|.1|1|2|3.0|3.01|12|23|30' input='+99.99|-.01|-2|0.0|.0|.1|3.0|3.01|30|3|23|12|1|2|+999' opt=nu
395 testcase '30|23|12|3.01|3.0|3|2|1|.1|0.0|.0|+999|+99.99|-.01|-2' input='+999|2|1|12|23|3|30|3.01|3.0|.1|.0|0.0|-2|-.01|+99.99' opt=nr
396 testcase '30|23|12|3.01|3|2|1|.1|+999|-.01|-2' input='+999|2|1|12|23|3|30|3.01|3.0|.1|.0|0.0|-2|-.01|+99.99' opt=nur
397 testcase '30|23|12|3.01|3.0|2|1|.1|+99.99|-.01|-2' input='+99.99|-.01|-2|0.0|.0|.1|3.0|3.01|30|3|23|12|1|2|+999' opt=nur
398 testcase 't 42|t 42:|t 42:1|t 42:09|t 42:9|t 42:11|t 42~' input='t 42:1|t 42|t 42:11|t 42:9|t 42~|t 42:|t 42:09' opt='#'
399 testcase 'A7R1:2|A7R2:6|A7R2:9|A7R2:11|A7R2:19|A7R2:47A|A7R11:1|AA|R7:1.09|R7:4A|R7:6|R7:7A|R7:404|R7:444-10|R7:1521' \
400 input='A7R1:2|R7:1521|AA|R7:4A|R7:7A|A7R2:9|R7:444-10|A7R2:6|R7:1.09|A7R2:47A|A7R11:1|R7:6|A7R2:11|R7:404|A7R2:19' \
401 opt='#'
402 testcase '30|23|12|3|03|2|1|01|0|00' input='2|1|23|12|23|3|30|0|00|0|01|03' opt='#ru'
403 testcase 'Exception: Unknown $sort option: x' input="b|c|b|1" opt=urx
404 testcase 'Exception: Invalid $sort option combination: n#' input="b|c" opt='n#'
405 testcase 'Exception: Invalid $sort option combination: #rn' input="b|1" opt='#rn'
407 # Feature tests for $terms.
408 printf 'text : index\nhost : boolean=H\nfoo : boolean=XFOO' > "$TEST_INDEXSCRIPT"
409 rm -rf "$TEST_DB"
410 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
411 text=This is some text.
412 host=example.org
413 foo=bar
415 printf '$hitlist{$list{$if{$eq{$cgi{prefix},null},$terms,$terms{$cgi{prefix}}},|}}' > "$TEST_TEMPLATE"
416 testcase 'Ztext' P=text B=Hexample.org B=Hexample.com prefix=null
417 testcase 'Hexample.org|Ztext' P=text B=Hexample.org B=Hexample.com prefix=
418 testcase 'Hexample.org' P=text B=Hexample.org B=Hexample.com prefix=H
419 testcase 'Ztext' P=text B=Hexample.org B=Hexample.com prefix=Z
420 testcase '' P=text B=Hexample.org B=Hexample.com prefix=E
422 printf '$msizelower $msize $msizeupper $msizeexact' > "$TEST_TEMPLATE"
423 testcase '1 1 1 true' P=this
424 testcase '1 1 1 true' P='Some text'
425 testcase '0 0 0 true' P=potato
427 printf '$set{weighting,coord}$hitlist{$weight.}' > "$TEST_TEMPLATE"
428 testcase '' P=aardvark
429 testcase '1.000000.' P=texting
430 testcase '' P='texting while driving'
431 testcase '' P='texting while driving' DEFAULTOP=AND
432 testcase '1.000000.' P='texting while driving' DEFAULTOP=OR
433 testcase '2.000000.' P='Some text'
434 # "this" and "is" are stopwords.
435 testcase '2.000000.' P='This is some text'
436 testcase '4.000000.' P='"This" "is" some text'
437 testcase '4.000000.' P='+This +is some text'
438 testcase '4.000000.' P='"This is some text"'
440 printf '$set{weightingpurefilter,coord}$hitlist{$weight.}' > "$TEST_TEMPLATE"
441 testcase '' B=XFOOfoo
442 testcase '1.000000.' B=Hexample.org
443 testcase '' B=Hexample.org B=XFOOfoo
444 testcase '1.000000.' B=Hexample.org B=Hexample.net
445 testcase '2.000000.' B=Hexample.org B=XFOObar
446 testcase '3.000000.' B=Hexample.org B=XFOObar B=XFOObar
448 printf '$filters' > "$TEST_TEMPLATE"
449 testcase 'Hexample.net~Hexample.org~.~~' B=Hexample.org B=Hexample.net
450 testcase '!Gmisc.test~.~~' N=Gmisc.test
451 testcase 'Hexample.net~Hexample.org~!Gmisc.test~.~~' B=Hexample.org B=Hexample.net N=Gmisc.test
452 testcase '.20040612~~~1~' DATEVALUE=1 START=20040612
453 testcase '.20040612~~~1~2' DATEVALUE=1 START=20040612 COLLAPSE=2
454 testcase '.20040612~~30~2' START=20040612 SPAN=30 COLLAPSE=2
455 testcase '.20040612~20160412~' START=20040612 END=20160412
456 testcase '.~~~2' COLLAPSE=2
457 testcase '.~~'
458 testcase '.~~1' SORT=1
459 testcase '.~~1f' SORT=+1
460 testcase '.~~1' SORT=-1
461 testcase '.~~1-2+3-27' SORT=+1-2+03,-27
462 testcase '.~~' SORTREVERSE=1
463 testcase '.~~1f' SORT=1 SORTREVERSE=1
464 testcase '.~~1' SORT=+1 SORTREVERSE=1
465 testcase '.~~1f' SORT=-1 SORTREVERSE=1
466 testcase '.~~1-2+3-27f' SORT=+1-2+03,-27 SORTREVERSE=1
467 testcase '.~~' SORTAFTER=1
468 testcase '.~~1R' SORT=1 SORTAFTER=1
469 testcase '.~~1F' SORT=+1 SORTAFTER=1
470 testcase '.~~1R' SORT=-1 SORTAFTER=1
471 testcase '.~~1-2+3-27R' SORT=+1-2+03,-27 SORTAFTER=1
472 testcase '.~~' SORTREVERSE=1 SORTAFTER=1
473 testcase '.~~1F' SORT=1 SORTREVERSE=1 SORTAFTER=1
474 testcase '.~~1R' SORT=+1 SORTREVERSE=1 SORTAFTER=1
475 testcase '.~~1F' SORT=-1 SORTREVERSE=1 SORTAFTER=1
476 testcase '.~~1-2+3-27F' SORT=+1-2+03,-27 SORTREVERSE=1 SORTAFTER=1
477 testcase '.~~X' DOCIDORDER=A # Buggy, but kept for compatibility.
478 testcase '.~~D' DOCIDORDER=D
479 testcase '.~~' DOCIDORDER=X # Buggy, but kept for compatibility.
480 testcase '.~~' DOCIDORDER=x # Buggy, but kept for compatibility.
482 tab=`printf '\t'`
483 printf '$cgi{AZ}|$cgi{AZ B}|$cgi{AZ.x}|$cgi{AZ.y}|$cgi{[}|$cgi{#}' > "$TEST_TEMPLATE"
484 testcase 'AZ|||||' AZ.x=3 AZ.y=4
485 testcase 'B|||||' 'AZ B.x=5' 'AZ B.y=12'
486 testcase 'B|||||' "AZ${tab}B.x=5" "AZ${tab}B.y=12"
487 testcase '||||2 ]|' '[ 2 ].x=123'
488 testcase '||||2 ]|' "[${tab}2 ].x=123"
489 testcase "||||2${tab}]|" "[ 2${tab}].x=123"
490 testcase "||||2${tab}]|" "[${tab}2${tab}].x=123"
491 testcase '|||||12' '12.x=37'
492 testcase 'DE|||||' 'AZ BC=DE'
493 testcase 'DE|||||' 'AZ B C=DE'
494 testcase 'DE|||||' "AZ${tab}BC=DE"
495 testcase 'DE|||||' "AZ B${tab}C=DE"
496 testcase 'DE|||||' "AZ${tab}B C=DE"
497 testcase 'DE|||||' "AZ${tab}B${tab}C=DE"
499 printf '$cgi{Search}|$cgi{Type}|$cgi{Search Type}' > "$TEST_TEMPLATE"
500 testcase 'Discover-List||' 'Search Type=Discover-List'
502 printf '$cgiparams' > "$TEST_TEMPLATE"
503 # We can't test the "no cgi parameters" case via testcase, as it passes a
504 # "dummy" parameter if there aren't any real ones.
505 #testcase ""
506 testcase "" =1
507 testcase "ABC" ABC=1
508 testcase "ABC" ABC=1 ABC=2
509 testcase "A${tab}AZ${tab}Z" A=1 A=2 A=3 AZ=1 AZ=2 Z=xxx
510 testcase "${tab}abc" =1 abc=1
511 testcase "${tab}abc${tab}def" =1 abc=1 def=7
513 # Feature tests for $highlight{}.
514 printf '$highlight{$cgi{text},$cgi{list}}' > "$TEST_TEMPLATE"
515 testcase 'A <b style="color:black;background-color:#ffff66">list</b> of <b style="color:black;background-color:#99ff99">words</b>' list="list${tab}words" text="A list of words"
517 printf '$highlight{$cgi{text},$cgi{list},$cgi{open}}' > "$TEST_TEMPLATE"
518 testcase 'A list of <b>words</b>' list="words" text="A list of words" open="<b>"
519 testcase 'A list of <span>words</span>' list="words" text="A list of words" open="<span>"
521 printf '$highlight{$cgi{text},$cgi{list},$cgi{open},$cgi{close}}' > "$TEST_TEMPLATE"
522 testcase 'A list of <b>words</b>' list="words" text="A list of words" open="<b>" close="</b>"
523 testcase 'A *list* of *words*' list="words${tab}list" text="A list of words" open="*" close="*"
525 # Test setting seterror and mset size, should not run the query after setting error.
526 printf '$if{$cgi{ERR},$seterror{$cgi{ERR}}}$msize$if{$error,!$error!}' > "$TEST_TEMPLATE"
527 testcase '1' P=text
528 testcase '0!boo!' P=text ERR=boo
530 # Test arguments inside seterror are evaluated
531 printf '$set{error,sample error}$seterror{$opt{error}}$msize$if{$error,!$error!}' > "$TEST_TEMPLATE"
532 testcase '0!sample error!' P=text
534 # Test error message doesn't get sent through HTML entity encoding.
535 printf '$seterror{{ "error": true, "error_message": "Parameter cannot be > 9" }}$if{$error,$error}' > "$TEST_TEMPLATE"
536 testcase '{ "error": true, "error_message": "Parameter cannot be > 9" }' P=text
538 # Test msize when error set after running query, should not affect running of query.
539 printf '$last$if{$cgi{ERR},$seterror{$cgi{ERR}}}$msize$if{$error,!$error!}' > "$TEST_TEMPLATE"
540 testcase '11' P=text
541 testcase '11!boo!' P=text ERR=boo
543 # Feature tests for $hash{}
544 printf '$hash{$cgi{text},md5}' > "$TEST_TEMPLATE"
545 testcase '098f6bcd4621d373cade4e832627b4f6' text="test"
546 testcase 'b4c216e4da73d1d01277ef46d0514821' text="simple query"
547 testcase 'd41d8cd98f00b204e9800998ecf8427e' text=""
548 testcase '3302c94d3500c3f695b7e09b7acd420d' text=" test "
550 # Regression test - original implementation truncated data at first zero byte.
551 printf '$hash{$cgi{text}$chr{0},md5}' > "$TEST_TEMPLATE"
552 testcase 'e2a3e68d23ce348b8f68b3079de3d4c9' text="test"
554 printf '$hash{$cgi{text},invalidhash}' > "$TEST_TEMPLATE"
555 testcase 'Exception: Unknown hash function: invalidhash' text="test"
557 # Feature tests for $uniq and $unique{}.
558 printf '$list{$uniq{$split{$cgi{text}}},:}|$list{$unique{$split{$cgi{text}}},:}' > "$TEST_TEMPLATE"
559 testcase '|' text=''
560 testcase 'foo|foo' text='foo'
561 testcase 'apple:banana:cherry|apple:banana:cherry' text='apple apple banana banana banana cherry'
562 testcase 'a:b:r:a:c:a:d:a:b:r:a|a:b:r:c:d' text='a b r a c a d a b r a'
563 testcase 'x:y:z:y|x:y:z' text='x y z z y'
565 # Regression test - $map with one argument wasn't rejected cleanly.
566 printf '$map{foo}' > "$TEST_TEMPLATE"
567 testcase 'Exception: too few arguments to $map'
569 # Feature tests for scriptindex hextobin action.
570 printf 'hex : hextobin value=0' > "$TEST_INDEXSCRIPT"
571 rm -rf "$TEST_DB"
572 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
573 hex=
575 hex=41
577 hex=54657374
579 hex=4b696C6c
581 printf '$list{$map{$split{$cgi{DOCIDS}},$value{0,$_}},|}' > "$TEST_TEMPLATE"
582 testcase '|A|Test|Kill' DOCIDS='1 2 3 4'
584 # Feature test error cases for scriptindex hextobin action.
585 rm -rf "$TEST_DB"
586 echo hex=7g |\
587 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" 2>&1 > /dev/null |\
588 grep -q ":1: error: hextobin: input must be all hex digits" ||\
589 { echo "scriptindex hextobin didn't give error for bad hex digit";\
590 failed=`expr $failed + 1`; }
591 echo hex=404 |\
592 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" 2>&1 > /dev/null |\
593 grep -q ":1: error: hextobin: input must have even length" ||\
594 { echo "scriptindex hextobin didn't give error for odd length hex string";\
595 failed=`expr $failed + 1`; }
596 testcase '7g|404' DOCIDS='1 2'
598 # Test useless action warnings.
599 printf 'foo : index weight=2' > "$TEST_INDEXSCRIPT"
600 rm -rf "$TEST_DB"
601 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
602 | grep -q ":1:13: warning: Index action 'weight' has no effect" ; then
603 : # OK
604 else
605 echo "scriptindex didn't give expected warning for useless 'weight' action"
606 failed=`expr $failed + 1`
608 printf 'foo : weight=2 weight=3 index' > "$TEST_INDEXSCRIPT"
609 rm -rf "$TEST_DB"
610 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
611 | grep -q ":1:7: warning: Index action 'weight' has no effect" ; then
612 : # OK
613 else
614 echo "scriptindex didn't give expected warning for useless 'weight' action"
615 failed=`expr $failed + 1`
617 printf 'foo : index lower' > "$TEST_INDEXSCRIPT"
618 rm -rf "$TEST_DB"
619 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
620 | grep -q ":1:13: warning: Index action 'lower' has no effect" ; then
621 : # OK
622 else
623 echo "scriptindex didn't give expected warning for useless 'lower' action"
624 failed=`expr $failed + 1`
627 # Test bad fieldname errors.
628 printf 'foo *bar : index' > "$TEST_INDEXSCRIPT"
629 rm -rf "$TEST_DB"
630 rc=0
631 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
632 if [ $rc -eq 0 ] ; then
633 echo "scriptindex didn't exit with non-zero return code on bad fieldname"
634 failed=`expr $failed + 1`
635 elif printf '%s' "$out" \
636 | grep -q ":1:5: error: field name must start with alphanumeric" ; then
637 : # OK
638 else
639 echo "scriptindex didn't give expected error for a bad fieldname"
640 failed=`expr $failed + 1`
642 printf 'foo b!ar : index' > "$TEST_INDEXSCRIPT"
643 rm -rf "$TEST_DB"
644 rc=0
645 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
646 if [ $rc -eq 0 ] ; then
647 echo "scriptindex didn't exit with non-zero return code on bad fieldname"
648 failed=`expr $failed + 1`
649 elif printf '%s' "$out" \
650 | grep -q ":1:6: error: bad character '!' in fieldname" ; then
651 : # OK
652 else
653 echo "scriptindex didn't give expected error for a bad fieldname"
654 failed=`expr $failed + 1`
657 # Test unwanted action argument.
658 printf 'foo : spell=test index' > "$TEST_INDEXSCRIPT"
659 rm -rf "$TEST_DB"
660 rc=0
661 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
662 if [ $rc -eq 0 ] ; then
663 echo "scriptindex didn't exit with non-zero return code on unwanted action argument"
664 failed=`expr $failed + 1`
665 elif printf '%s' "$out" \
666 | grep -q ":1:12: error: Index action 'spell' doesn't take an argument" ; then
667 : # OK
668 else
669 echo "scriptindex didn't give expected error for unwanted action argument"
670 failed=`expr $failed + 1`
673 # Test missing closing quote.
674 printf 'foo : index="XFOO' > "$TEST_INDEXSCRIPT"
675 rm -rf "$TEST_DB"
676 rc=0
677 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
678 if [ $rc -eq 0 ] ; then
679 echo "scriptindex didn't exit with non-zero return code for missing closing quote"
680 failed=`expr $failed + 1`
681 elif printf '%s' "$out" \
682 | grep -q ":1:18: error: No closing quote" ; then
683 : # OK
684 else
685 echo "scriptindex didn't give expected error for missing closing quote"
686 failed=`expr $failed + 1`
689 # Feature tests for termprefix and unprefix.
690 printf '$termprefix{$cgi{B}}|$unprefix{$cgi{B}}' > "$TEST_TEMPLATE"
691 testcase '|' B=''
692 testcase '|something' B='something'
693 testcase '|42' B='42'
694 testcase '|3bad' B='3bad'
695 testcase '|&something' B='&something'
696 testcase '|:something' B=':something'
697 testcase 'H|example.org' B='Hexample.org'
698 testcase 'K|tag' B='Ktag'
699 testcase 'K|Capital' B='KCapital'
700 testcase 'K|:colon-tag' B='K:colon-tag'
701 testcase 'K|:Capital' B='K:Capital'
702 testcase 'XCOLOUR|red' B='XCOLOURred'
703 testcase 'XPUNC|:colon' B='XPUNC::colon'
704 testcase 'XPUNC|internal:colon' B='XPUNC:internal:colon'
705 testcase 'XPUNC|:Colon' B='XPUNC::Colon'
706 testcase 'XCASE|Upper' B='XCASE:Upper'
707 testcase 'XCASE|TITLE' B='XCASE:TITLE'
708 testcase 'XNUM|42' B='XNUM42'
709 testcase 'XNUM|3bad' B='XNUM3bad'
711 # Test to make sure out generate_sample function in sample.cc
712 # Doesn't run into negative memory access
713 printf '$truncate{$cgi{input},$cgi{maxlen},$cgi{ind},$cgi{ind2}}$seterror{$opt{error}}' > "$TEST_TEMPLATE"
714 testcase 'w...' input='wwwwww' maxlen=4 ind='...' ind2='...'
715 testcase '' input='s' maxlen=0 ind='...' ind2='...'
717 # Simple tests of $subdb and $subid.
718 rm -rf "$TEST_DB"
719 printf 'inmemory' > "$TEST_DB"
720 printf 'inmemory' > "${TEST_DB}2"
721 printf '$subdb{$cgi{ID}}|$subid{$cgi{ID}}' > "$TEST_TEMPLATE"
722 testcase "$TEST_DB|1" ID=1
723 testcase "$TEST_DB|1" ID=1 DB="$TEST_DB/${TEST_DB}2"
724 testcase "${TEST_DB}2|1" ID=2 DB="$TEST_DB/${TEST_DB}2"
725 testcase "${TEST_DB}|2" ID=3 DB="$TEST_DB/${TEST_DB}2"
726 rm -rf "${TEST_DB}2"
728 # Feature tests of scriptindex.
729 printf 'uuid : boolean=Q unique=Q\nguid : boolean=G unique=G' > "$TEST_INDEXSCRIPT"
730 rm -rf "$TEST_DB"
731 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null < /dev/null 2>&1; then
732 echo "scriptindex didn't reject 'unique' action being used more than once"
733 failed=`expr $failed + 1`
736 # Test we check for hash's argument being an integer (new in 1.4.6).
737 printf 'url : hash=37.3 boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
738 rm -rf "$TEST_DB"
739 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
740 | grep -q ":1:14: warning: Index action 'hash' takes an integer argument" ; then
741 : # OK
742 else
743 echo "scriptindex didn't reject 'hash' with a non-integer argument"
744 failed=`expr $failed + 1`
747 # Test we give a helpful error for an action with a digit in (regression
748 # test for fix in 1.4.6).
750 # This used to give the confusing:
751 # Unknown index action ''
752 printf 'url : index4' > "$TEST_INDEXSCRIPT"
753 rm -rf "$TEST_DB"
754 rc=0
755 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
756 if [ $rc -eq 0 ] ; then
757 echo "scriptindex didn't exit with non-zero return code for bad index action with a digit"
758 failed=`expr $failed + 1`
759 elif printf '%s' "$out" \
760 | grep -q ":1:7: error: Unknown index action 'index4'" ; then
761 : # OK
762 else
763 echo "scriptindex didn't give expected error for bad index action with a digit"
764 failed=`expr $failed + 1`
767 # Test we give a helpful error if an = sign is missed out before an optional
768 # numeric argument (regression test for fix in 1.4.6).
770 # This used to give the confusing:
771 # Unknown index action ''
772 printf 'url : hash 42' > "$TEST_INDEXSCRIPT"
773 rm -rf "$TEST_DB"
774 rc=0
775 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
776 if [ $rc -eq 0 ] ; then
777 echo "scriptindex didn't exit with non-zero return code for a missing equals sign"
778 failed=`expr $failed + 1`
779 elif printf '%s' "$out" \
780 | grep -q ":1:12: error: Unknown index action '42'" ; then
781 : # OK
782 else
783 echo "scriptindex didn't give expected error for a missing equals sign"
784 failed=`expr $failed + 1`
787 # Test we warn about spaces before and after '='.
789 # This has never been documented as supported, and was deprecated in 1.4.6
790 # because it resulted in this quietly using hash as the field name, which is
791 # probably not what was intended:
793 # url : field= hash boolean=Q unique=Q
794 printf 'url : field= hash boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
795 rm -rf "$TEST_DB"
796 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
797 | grep -q ":1:13: warning: putting spaces between '=' and the argument is deprecated" ; then
798 : # OK
799 else
800 echo "scriptindex didn't give expected warning for space after '='"
801 failed=`expr $failed + 1`
803 printf 'url : field =link' > "$TEST_INDEXSCRIPT"
804 rm -rf "$TEST_DB"
805 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
806 | grep -q ":1:12: warning: putting spaces between the action and '=' is deprecated" ; then
807 : # OK
808 else
809 echo "scriptindex didn't give expected warning for space before '='"
810 failed=`expr $failed + 1`
813 # Feature tests for datevalue command scriptindex.
814 printf 'DATE : field parsedate=%%Y%%m%%d valuepacked=13\n' > "$TEST_INDEXSCRIPT"
815 rm -rf "$TEST_DB"
816 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
817 DATE=19891204
819 printf '$field{DATE,1}|$unpack{$value{13,1}}|$date{$unpack{$value{13,1}}}' > "$TEST_TEMPLATE"
820 testcase '19891204|628732800|1989-12-04' P=text
822 # Feature tests for datevalue command scriptindex where format contains space.
823 printf 'DATE : field parsedate="%%Y%%m%%d %%T" valuepacked=13\n' > "$TEST_INDEXSCRIPT"
824 rm -rf "$TEST_DB"
825 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null 2>&1 <<'END'
826 DATE=20161202 12:04:22.000000
828 printf '$unpack{$value{13,1}}|$date{$unpack{$value{13,1}}}' > "$TEST_TEMPLATE"
829 testcase '1480680262|2016-12-02' P=text
831 # Feature tests for quoted argument.
832 printf 'DATE : field=" spaces " date="yyyymmdd"\nTEXT: index\n' > "$TEST_INDEXSCRIPT"
833 rm -rf "$TEST_DB"
834 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
835 DATE=19891204
836 TEXT=This is sample text.
837 NEXT=work
839 printf '$freq{D19891204}|$field{ spaces ,1}' > "$TEST_TEMPLATE"
840 testcase '1|19891204' P=text
841 # Use $time to force the match to run.
842 printf '$if{$time,$freq{D19891204}}|$field{ spaces ,1}' > "$TEST_TEMPLATE"
843 testcase '1|19891204' P=
845 # Regression test that a closing " with junk after is flagged.
846 printf 'date : field="test"index' > "$TEST_INDEXSCRIPT"
847 rm -rf "$TEST_DB"
848 rc=0
849 out=`$SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1` || rc=$?
850 if [ $rc -eq 0 ] ; then
851 echo "scriptindex didn't exit with non-zero return code for junk after closing quote"
852 failed=`expr $failed + 1`
853 elif printf '%s' "$out" \
854 | grep -q ":1:20: error: Unexpected character 'i' after closing quote" ; then
855 : # OK
856 else
857 echo "scriptindex didn't give expected error for junk after closing quote"
858 failed=`expr $failed + 1`
861 # Test we warn about useless actions.
862 printf 'date : field parsedate=%%Y%%m%%d' > "$TEST_INDEXSCRIPT"
863 rm -rf "$TEST_DB"
864 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
865 | grep -q ":1:14: warning: Index action 'parsedate' has no effect" ; then
866 : # OK
867 else
868 echo "scriptindex didn't give expected warning for useless 'parsedate'"
869 failed=`expr $failed + 1`
872 # The 'hash' action should require its argument is >= 6, so test 5 is rejected.
873 printf 'url : hash=5 boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
874 rm -rf "$TEST_DB"
875 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null > /dev/null 2>&1 ; then
876 echo "scriptindex didn't reject 'hash=5'"
877 failed=`expr $failed + 1`
880 # And that 6 is accepted.
881 printf 'url : hash=6 boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
882 rm -rf "$TEST_DB"
883 if echo 'url=http://xapian.org' | $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null 2>&1 ; then
884 : # OK
885 else
886 echo "scriptindex rejected 'hash=6'"
887 failed=`expr $failed + 1`
890 # Regression test to check hash works without argument (it was failing with an
891 # assertion in unreleased versions prior to 1.4.6).
892 printf 'url : hash boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
893 rm -rf "$TEST_DB"
894 if echo 'url=http://xapian.org' | $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null 2>&1 ; then
895 : # OK
896 else
897 echo "scriptindex rejected 'hash'"
898 failed=`expr $failed + 1`
901 # Test the same actions for multiple fields works (briefly broken in git master
902 # before 1.5.0).
903 printf 'tag1 tag2 tag3 : boolean=T field' > "$TEST_INDEXSCRIPT"
904 rm -rf "$TEST_DB"
905 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
906 tag1=one
907 tag2=two
908 tag3=three
910 printf '$hitlist{$list{$terms{T},|}/$field{tag1}|$field{tag2}|$field{tag3}}' > "$TEST_TEMPLATE"
911 testcase 'Tone/one|two|three' B=Tone
912 testcase 'Tthree|Ttwo/one|two|three' B=Ttwo B=Tthree
914 rm "$OMEGA_CONFIG_FILE" "$TEST_INDEXSCRIPT" "$TEST_TEMPLATE"
915 rm -rf "$TEST_DB"
916 if [ "$failed" = 0 ] ; then
917 exit 0
919 echo "Failed $failed test(s)"
920 exit 1