Add support for options to $sort
[xapian.git] / xapian-applications / omega / omegatest
blob3751eebdb83c3f96d3a2fdd1c2f599fb88645ff7
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 set +e
248 out=`faketime -f '1980-12-08 00:00:00' date +%Y 2>&1`
249 rc=$?
250 set -e
251 if [ "$rc:$out" = "0:1980" ] ; then
252 TZ=UTC
253 export TZ
254 FAKETIME='faketime -f'
255 FAKE_NOW='2015-11-28 06:07:08'
256 qtestcase 'VALUE_RANGE 0 20151127060709 20151128060708' DATEVALUE=0 SPAN=1
258 # Tests of term-based date range filtering:
259 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
260 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
261 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
262 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
263 # Date range with start after end:
264 qtestcase 'Dlatest' START=201512
265 qtestcase 'Dlatest' START=20151201
266 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
267 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
268 FAKETIME=
269 unset FAKE_NOW
270 else
271 if [ "$rc" = 127 ] ; then
272 echo "Skipping testcases which need 'faketime' tool installed"
273 else
274 echo "Skipping testcases which need 'faketime' tool - it's installed but doesn't work"
278 # Feature tests for $contains.
279 printf '$contains{$cgi{a},$cgi{b}}' > "$TEST_TEMPLATE"
280 testcase '6' P=text a=fish b="Hello fish"
281 testcase '' P=text a="Example" b="random"
283 NEWLINE='
286 # Feature tests for boolprefix and prefix maps.
287 printf '$set{stemmer,}$setmap{boolprefix,lang,L,host,H}$setmap{prefix,,XDEFAULT}$querydescription' > "$TEST_TEMPLATE"
288 qtestcase '((XDEFAULTfoo@1 AND XDEFAULTbar@2) FILTER (Hexample.org AND Lzh))' P='host:example.org foo bar lang:zh'
290 # Feature tests for $cond.
291 printf '$cond{$cgi{one},1,$cgi{two},2,$cgi{three},3}' > "$TEST_TEMPLATE"
292 testcase '1' one=true
293 testcase '2' two=true
294 testcase '3' three=true
295 testcase '' nothing=true
296 testcase '1' one=true two=true three=true
297 testcase '2' two=true three=true
298 printf '$cond{$cgi{one},1,$cgi{two},2,$cgi{alt}}' > "$TEST_TEMPLATE"
299 testcase '1' one=true
300 testcase '2' two=true
301 testcase 'none' alt=none
302 # Check evaluation is lazy.
303 printf '$cond{$cgi{one},$seterror{err1},$cgi{two},2,$cgi{alt}}$error' > "$TEST_TEMPLATE"
304 testcase 'err1' one=true
305 testcase '2' two=true
306 testcase 'none' alt=none
307 printf '$cond{$cgi{one},1,$cgi{two},$seterror{err2},$cgi{alt}}$error' > "$TEST_TEMPLATE"
308 testcase '1' one=true
309 testcase 'err2' two=true
310 testcase 'none' alt=none
311 printf '$cond{$cgi{one},1,$cgi{two},2,$seterror{erralt}}$error' > "$TEST_TEMPLATE"
312 testcase '1' one=true
313 testcase '2' two=true
314 testcase 'erralt' alt=none
316 # Feature tests for $switch.
317 printf '$switch{$cgi{x},1,one,2,two}' > "$TEST_TEMPLATE"
318 testcase 'one' x=1
319 testcase 'two' x=2
320 testcase '' x=3
321 printf '$switch{$cgi{x},1,one,2,two,default}' > "$TEST_TEMPLATE"
322 testcase 'one' x=1
323 testcase 'two' x=2
324 testcase 'default' x=3
325 # Check evaluation is lazy.
326 printf '$switch{$cgi{x},1,$seterror{err1},2,two}$error' > "$TEST_TEMPLATE"
327 testcase 'err1' x=1
328 testcase 'two' x=2
329 testcase '' x=3
330 printf '$switch{$cgi{x},1,one,2,$seterror{err2},default}$error' > "$TEST_TEMPLATE"
331 testcase 'one' x=1
332 testcase 'err2' x=2
333 testcase 'default' x=3
334 printf '$switch{$cgi{x},1,one,2,two,$seterror{errdefault}}$error' > "$TEST_TEMPLATE"
335 testcase 'one' x=1
336 testcase 'two' x=2
337 testcase 'errdefault' x=3
339 # Feature tests for $map.
340 printf '$list{$map{$split{-,$cgi{a}},$list{$map{$split{,$cgi{b}},$_},-}},|}' > "$TEST_TEMPLATE"
341 testcase '1-2-3|1-2-3' P=text a=ab-cd b=123
342 printf '$list{$map{$split{-,$cgi{a}},$set{__,$_}$list{$map{$split{,$cgi{b}},$opt{__}$_},-}},|}' > "$TEST_TEMPLATE"
343 testcase 'a1-a2-a3|b1-b2-b3' P=text a=a-b b=123
344 printf '$list{$map{$split{-,$cgi{a}},$list{$map{$split{$_,$cgi{b}},$_},-}},|}' > "$TEST_TEMPLATE"
345 testcase '1-2,3|1:2-3' P=text a=':-,' b='1:2,3'
346 # Check that the outer $_ is restored after the inner $map.
347 printf '$list{$map{$split{-,$cgi{a}},$list{$map{$split{,$cgi{b}},$_},-}$_},|}' > "$TEST_TEMPLATE"
348 testcase '1-2-3a|1-2-3b' P=text a='a-b' b='123'
350 # Feature tests for $match.
351 printf '$match{$cgi{a},$cgi{b},$cgi{c}}' > "$TEST_TEMPLATE"
352 testcase 'true' P=text a="ab*c+" b="ac"
353 testcase '' P=text a="acb" b="abc"
354 testcase 'true' P=text a="[A-Z]bcD" b="abcd" c="i"
355 testcase '' P=text a="[A-Z]bcD" b="abcd"
356 testcase 'true' P=text a="^abc$" b="${NEWLINE}abc${NEWLINE}def" c="m"
357 testcase '' P=text a="^abc$" b="${NEWLINE}abc${NEWLINE}def"
358 testcase 'true' P=text a="abc." b="abc${NEWLINE}" c="s"
359 testcase '' P=text a="abc." b="abc${NEWLINE}"
360 testcase 'true' P=text a=" ABC #test_comment " b="ABC" c="x"
361 testcase '' P=text a=" ABC #test_comment " b="ABC"
363 # Feature tests for $sort.
364 printf '$list{$sort{$split{|,$cgi{input}}},|}' > "$TEST_TEMPLATE"
365 testcase 'pineapple' input="pineapple"
366 testcase 'apple|banana|coconut' input="coconut|banana|apple"
367 testcase '1|b|b|c' input="b|c|b|1"
368 printf '$list{$sort{$split{|,$cgi{input}},$cgi{opt}},|}' > "$TEST_TEMPLATE"
369 testcase 'pineapple' input="pineapple" opt=
370 testcase 'pineapple' input="pineapple" opt=r
371 testcase 'pineapple' input="pineapple" opt=ru
372 testcase '1|b|c' input="b|c|b|1" opt=u
373 testcase 'c|b|b|1' input="b|c|b|1" opt=r
374 testcase 'c|b|1' input="b|c|b|1" opt=ur
375 testcase 'Exception: Unknown $sort option: x' input="b|c|b|1" opt=urx
377 # Feature tests for $terms.
378 printf 'text : index\nhost : boolean=H\nfoo : boolean=XFOO' > "$TEST_INDEXSCRIPT"
379 rm -rf "$TEST_DB"
380 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
381 text=This is some text.
382 host=example.org
383 foo=bar
385 printf '$hitlist{$list{$if{$eq{$cgi{prefix},null},$terms,$terms{$cgi{prefix}}},|}}' > "$TEST_TEMPLATE"
386 testcase 'Ztext' P=text B=Hexample.org B=Hexample.com prefix=null
387 testcase 'Hexample.org|Ztext' P=text B=Hexample.org B=Hexample.com prefix=
388 testcase 'Hexample.org' P=text B=Hexample.org B=Hexample.com prefix=H
389 testcase 'Ztext' P=text B=Hexample.org B=Hexample.com prefix=Z
390 testcase '' P=text B=Hexample.org B=Hexample.com prefix=E
392 printf '$msizelower $msize $msizeupper $msizeexact' > "$TEST_TEMPLATE"
393 testcase '1 1 1 true' P=this
394 testcase '1 1 1 true' P='Some text'
395 testcase '0 0 0 true' P=potato
397 printf '$set{weighting,coord}$hitlist{$weight.}' > "$TEST_TEMPLATE"
398 testcase '' P=aardvark
399 testcase '1.000000.' P=texting
400 testcase '' P='texting while driving'
401 testcase '' P='texting while driving' DEFAULTOP=AND
402 testcase '1.000000.' P='texting while driving' DEFAULTOP=OR
403 testcase '2.000000.' P='Some text'
404 # "this" and "is" are stopwords.
405 testcase '2.000000.' P='This is some text'
406 testcase '4.000000.' P='"This" "is" some text'
407 testcase '4.000000.' P='+This +is some text'
408 testcase '4.000000.' P='"This is some text"'
410 printf '$set{weightingpurefilter,coord}$hitlist{$weight.}' > "$TEST_TEMPLATE"
411 testcase '' B=XFOOfoo
412 testcase '1.000000.' B=Hexample.org
413 testcase '' B=Hexample.org B=XFOOfoo
414 testcase '1.000000.' B=Hexample.org B=Hexample.net
415 testcase '2.000000.' B=Hexample.org B=XFOObar
416 testcase '3.000000.' B=Hexample.org B=XFOObar B=XFOObar
418 printf '$filters' > "$TEST_TEMPLATE"
419 testcase 'Hexample.net~Hexample.org~.~~' B=Hexample.org B=Hexample.net
420 testcase '!Gmisc.test~.~~' N=Gmisc.test
421 testcase 'Hexample.net~Hexample.org~!Gmisc.test~.~~' B=Hexample.org B=Hexample.net N=Gmisc.test
422 testcase '.20040612~~~1~' DATEVALUE=1 START=20040612
423 testcase '.20040612~~~1~2' DATEVALUE=1 START=20040612 COLLAPSE=2
424 testcase '.20040612~~30~2' START=20040612 SPAN=30 COLLAPSE=2
425 testcase '.20040612~20160412~' START=20040612 END=20160412
426 testcase '.~~~2' COLLAPSE=2
427 testcase '.~~'
428 testcase '.~~1' SORT=1
429 testcase '.~~1f' SORT=+1
430 testcase '.~~1' SORT=-1
431 testcase '.~~1-2+3-27' SORT=+1-2+03,-27
432 testcase '.~~' SORTREVERSE=1
433 testcase '.~~1f' SORT=1 SORTREVERSE=1
434 testcase '.~~1' SORT=+1 SORTREVERSE=1
435 testcase '.~~1f' SORT=-1 SORTREVERSE=1
436 testcase '.~~1-2+3-27f' SORT=+1-2+03,-27 SORTREVERSE=1
437 testcase '.~~' SORTAFTER=1
438 testcase '.~~1R' SORT=1 SORTAFTER=1
439 testcase '.~~1F' SORT=+1 SORTAFTER=1
440 testcase '.~~1R' SORT=-1 SORTAFTER=1
441 testcase '.~~1-2+3-27R' SORT=+1-2+03,-27 SORTAFTER=1
442 testcase '.~~' SORTREVERSE=1 SORTAFTER=1
443 testcase '.~~1F' SORT=1 SORTREVERSE=1 SORTAFTER=1
444 testcase '.~~1R' SORT=+1 SORTREVERSE=1 SORTAFTER=1
445 testcase '.~~1F' SORT=-1 SORTREVERSE=1 SORTAFTER=1
446 testcase '.~~1-2+3-27F' SORT=+1-2+03,-27 SORTREVERSE=1 SORTAFTER=1
447 testcase '.~~X' DOCIDORDER=A # Buggy, but kept for compatibility.
448 testcase '.~~D' DOCIDORDER=D
449 testcase '.~~' DOCIDORDER=X # Buggy, but kept for compatibility.
450 testcase '.~~' DOCIDORDER=x # Buggy, but kept for compatibility.
452 tab=`printf '\t'`
453 printf '$cgi{AZ}|$cgi{AZ B}|$cgi{AZ.x}|$cgi{AZ.y}|$cgi{[}|$cgi{#}' > "$TEST_TEMPLATE"
454 testcase 'AZ|||||' AZ.x=3 AZ.y=4
455 testcase 'B|||||' 'AZ B.x=5' 'AZ B.y=12'
456 testcase 'B|||||' "AZ${tab}B.x=5" "AZ${tab}B.y=12"
457 testcase '||||2 ]|' '[ 2 ].x=123'
458 testcase '||||2 ]|' "[${tab}2 ].x=123"
459 testcase "||||2${tab}]|" "[ 2${tab}].x=123"
460 testcase "||||2${tab}]|" "[${tab}2${tab}].x=123"
461 testcase '|||||12' '12.x=37'
462 testcase 'DE|||||' 'AZ BC=DE'
463 testcase 'DE|||||' 'AZ B C=DE'
464 testcase 'DE|||||' "AZ${tab}BC=DE"
465 testcase 'DE|||||' "AZ B${tab}C=DE"
466 testcase 'DE|||||' "AZ${tab}B C=DE"
467 testcase 'DE|||||' "AZ${tab}B${tab}C=DE"
469 printf '$cgi{Search}|$cgi{Type}|$cgi{Search Type}' > "$TEST_TEMPLATE"
470 testcase 'Discover-List||' 'Search Type=Discover-List'
472 printf '$cgiparams' > "$TEST_TEMPLATE"
473 # We can't test the "no cgi parameters" case via testcase, as it passes a
474 # "dummy" parameter if there aren't any real ones.
475 #testcase ""
476 testcase "" =1
477 testcase "ABC" ABC=1
478 testcase "ABC" ABC=1 ABC=2
479 testcase "A${tab}AZ${tab}Z" A=1 A=2 A=3 AZ=1 AZ=2 Z=xxx
480 testcase "${tab}abc" =1 abc=1
481 testcase "${tab}abc${tab}def" =1 abc=1 def=7
483 # Feature tests for $highlight{}.
484 printf '$highlight{$cgi{text},$cgi{list}}' > "$TEST_TEMPLATE"
485 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"
487 printf '$highlight{$cgi{text},$cgi{list},$cgi{open}}' > "$TEST_TEMPLATE"
488 testcase 'A list of <b>words</b>' list="words" text="A list of words" open="<b>"
489 testcase 'A list of <span>words</span>' list="words" text="A list of words" open="<span>"
491 printf '$highlight{$cgi{text},$cgi{list},$cgi{open},$cgi{close}}' > "$TEST_TEMPLATE"
492 testcase 'A list of <b>words</b>' list="words" text="A list of words" open="<b>" close="</b>"
493 testcase 'A *list* of *words*' list="words${tab}list" text="A list of words" open="*" close="*"
495 # Test setting seterror and mset size, should not run the query after setting error.
496 printf '$if{$cgi{ERR},$seterror{$cgi{ERR}}}$msize$if{$error,!$error!}' > "$TEST_TEMPLATE"
497 testcase '1' P=text
498 testcase '0!boo!' P=text ERR=boo
500 # Test arguments inside seterror are evaluated
501 printf '$set{error,sample error}$seterror{$opt{error}}$msize$if{$error,!$error!}' > "$TEST_TEMPLATE"
502 testcase '0!sample error!' P=text
504 # Test error message doesn't get sent through HTML entity encoding.
505 printf '$seterror{{ "error": true, "error_message": "Parameter cannot be > 9" }}$if{$error,$error}' > "$TEST_TEMPLATE"
506 testcase '{ "error": true, "error_message": "Parameter cannot be > 9" }' P=text
508 # Test msize when error set after running query, should not affect running of query.
509 printf '$last$if{$cgi{ERR},$seterror{$cgi{ERR}}}$msize$if{$error,!$error!}' > "$TEST_TEMPLATE"
510 testcase '11' P=text
511 testcase '11!boo!' P=text ERR=boo
513 # Feature tests for $hash{}
514 printf '$hash{$cgi{text},md5}' > "$TEST_TEMPLATE"
515 testcase '098f6bcd4621d373cade4e832627b4f6' text="test"
516 testcase 'b4c216e4da73d1d01277ef46d0514821' text="simple query"
517 testcase 'd41d8cd98f00b204e9800998ecf8427e' text=""
518 testcase '3302c94d3500c3f695b7e09b7acd420d' text=" test "
520 # Regression test - original implementation truncated data at first zero byte.
521 printf '$hash{$cgi{text}$chr{0},md5}' > "$TEST_TEMPLATE"
522 testcase 'e2a3e68d23ce348b8f68b3079de3d4c9' text="test"
524 printf '$hash{$cgi{text},invalidhash}' > "$TEST_TEMPLATE"
525 testcase 'Exception: Unknown hash function: invalidhash' text="test"
527 # Feature tests for scriptindex hextobin action.
528 printf 'hex : hextobin value=0' > "$TEST_INDEXSCRIPT"
529 rm -rf "$TEST_DB"
530 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
531 hex=
533 hex=41
535 hex=54657374
537 hex=4b696C6c
539 printf '$list{$map{$split{$cgi{DOCIDS}},$value{0,$_}},|}' > "$TEST_TEMPLATE"
540 testcase '|A|Test|Kill' DOCIDS='1 2 3 4'
542 # Feature test error cases for scriptindex hextobin action.
543 rm -rf "$TEST_DB"
544 echo hex=7g |\
545 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" 2>&1 > /dev/null |\
546 grep -q "hextobin: input must be all hex digits" ||\
547 { echo "scriptindex hextobin didn't give error for bad hex digit";\
548 failed=`expr $failed + 1`; }
549 echo hex=404 |\
550 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" 2>&1 > /dev/null |\
551 grep -q "hextobin: input must have even length" ||\
552 { echo "scriptindex hextobin didn't give error for odd length hex string";\
553 failed=`expr $failed + 1`; }
554 testcase '7g|404' DOCIDS='1 2'
556 # Feature tests for termprefix and unprefix.
557 printf '$termprefix{$cgi{B}}|$unprefix{$cgi{B}}' > "$TEST_TEMPLATE"
558 testcase '|' B=''
559 testcase '|something' B='something'
560 testcase '|42' B='42'
561 testcase '|3bad' B='3bad'
562 testcase '|&something' B='&something'
563 testcase '|:something' B=':something'
564 testcase 'H|example.org' B='Hexample.org'
565 testcase 'K|tag' B='Ktag'
566 testcase 'K|Capital' B='KCapital'
567 testcase 'K|:colon-tag' B='K:colon-tag'
568 testcase 'K|:Capital' B='K:Capital'
569 testcase 'XCOLOUR|red' B='XCOLOURred'
570 testcase 'XPUNC|:colon' B='XPUNC::colon'
571 testcase 'XPUNC|internal:colon' B='XPUNC:internal:colon'
572 testcase 'XPUNC|:Colon' B='XPUNC::Colon'
573 testcase 'XCASE|Upper' B='XCASE:Upper'
574 testcase 'XCASE|TITLE' B='XCASE:TITLE'
575 testcase 'XNUM|42' B='XNUM42'
576 testcase 'XNUM|3bad' B='XNUM3bad'
578 # Test to make sure out generate_sample function in sample.cc
579 # Doesn't run into negative memory access
580 printf '$truncate{$cgi{input},$cgi{maxlen},$cgi{ind},$cgi{ind2}}$seterror{$opt{error}}' > "$TEST_TEMPLATE"
581 testcase 'w...' input='wwwwww' maxlen=4 ind='...' ind2='...'
582 testcase '' input='s' maxlen=0 ind='...' ind2='...'
584 # Simple tests of $subdb and $subid.
585 rm -rf "$TEST_DB"
586 printf 'inmemory' > "$TEST_DB"
587 printf 'inmemory' > "${TEST_DB}2"
588 printf '$subdb{$cgi{ID}}|$subid{$cgi{ID}}' > "$TEST_TEMPLATE"
589 testcase "$TEST_DB|1" ID=1
590 testcase "$TEST_DB|1" ID=1 DB="$TEST_DB/${TEST_DB}2"
591 testcase "${TEST_DB}2|1" ID=2 DB="$TEST_DB/${TEST_DB}2"
592 testcase "${TEST_DB}|2" ID=3 DB="$TEST_DB/${TEST_DB}2"
593 rm -rf "${TEST_DB}2"
595 # Feature tests of scriptindex.
596 printf 'uuid : boolean=Q unique=Q\nguid : boolean=G unique=G' > "$TEST_INDEXSCRIPT"
597 rm -rf "$TEST_DB"
598 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null < /dev/null 2>&1; then
599 echo "scriptindex didn't reject 'unique' action being used more than once"
600 failed=`expr $failed + 1`
603 # Test we check for hash's argument being an integer (new in 1.4.6).
604 printf 'url : hash=37.3 boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
605 rm -rf "$TEST_DB"
606 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
607 | grep -q "Index action 'hash' takes an integer argument" ; then
608 : # OK
609 else
610 echo "scriptindex didn't reject 'hash' with a non-integer argument"
611 failed=`expr $failed + 1`
614 # Test we give a helpful error for an action with a digit in (regression
615 # test for fix in 1.4.6).
617 # This used to give the confusing:
618 # Unknown index action ''
619 printf 'url : index4' > "$TEST_INDEXSCRIPT"
620 rm -rf "$TEST_DB"
621 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
622 | grep -q "Unknown index action 'index4'" ; then
623 : # OK
624 else
625 echo "scriptindex didn't give expected error for bad index action with a digit"
626 failed=`expr $failed + 1`
629 # Test we give a helpful error if an = sign is missed out before an optional
630 # numeric argument (regression test for fix in 1.4.6).
632 # This used to give the confusing:
633 # Unknown index action ''
634 printf 'url : hash 42' > "$TEST_INDEXSCRIPT"
635 rm -rf "$TEST_DB"
636 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
637 | grep -q "Unknown index action '42'" ; then
638 : # OK
639 else
640 echo "scriptindex didn't give expected error for a missing equals sign"
641 failed=`expr $failed + 1`
644 # Test we warn about spaces before and after '='.
646 # This has never been documented as supported, and was deprecated in 1.4.6
647 # because it resulted in this quietly using hash as the field name, which is
648 # probably not what was intended:
650 # url : field= hash boolean=Q unique=Q
651 printf 'url : field= hash boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
652 rm -rf "$TEST_DB"
653 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
654 | grep -q "warning: putting spaces between '=' and the argument is deprecated" ; then
655 : # OK
656 else
657 echo "scriptindex didn't give expected warning for space after '='"
658 failed=`expr $failed + 1`
660 printf 'url : field =link' > "$TEST_INDEXSCRIPT"
661 rm -rf "$TEST_DB"
662 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
663 | grep -q "warning: putting spaces between the action and '=' is deprecated" ; then
664 : # OK
665 else
666 echo "scriptindex didn't give expected warning for space before '='"
667 failed=`expr $failed + 1`
670 # Feature tests for datevalue command scriptindex.
671 printf 'DATE : field parsedate=%%Y%%m%%d valuepacked=13\n' > "$TEST_INDEXSCRIPT"
672 rm -rf "$TEST_DB"
673 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
674 DATE=19891204
676 printf '$field{DATE,1}|$unpack{$value{13,1}}|$date{$unpack{$value{13,1}}}' > "$TEST_TEMPLATE"
677 testcase '19891204|628732800|1989-12-04' P=text
679 # Feature tests for datevalue command scriptindex where format contains space.
680 printf 'DATE : field parsedate="%%Y%%m%%d %%T" valuepacked=13\n' > "$TEST_INDEXSCRIPT"
681 rm -rf "$TEST_DB"
682 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null 2>&1 <<'END'
683 DATE=20161202 12:04:22.000000
685 printf '$unpack{$value{13,1}}|$date{$unpack{$value{13,1}}}' > "$TEST_TEMPLATE"
686 testcase '1480680262|2016-12-02' P=text
688 # Feature tests for quoted argument.
689 printf 'DATE : field=" spaces " date="yyyymmdd"\nTEXT: index\n' > "$TEST_INDEXSCRIPT"
690 rm -rf "$TEST_DB"
691 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
692 DATE=19891204
693 TEXT=This is sample text.
694 NEXT=work
696 printf '$freq{D19891204}|$field{ spaces ,1}' > "$TEST_TEMPLATE"
697 testcase '1|19891204' P=text
698 # Use $time to force the match to run.
699 printf '$if{$time,$freq{D19891204}}|$field{ spaces ,1}' > "$TEST_TEMPLATE"
700 testcase '1|19891204' P=
702 # Test we warn about useless actions.
703 printf 'date : field parsedate=%%Y%%m%%d' > "$TEST_INDEXSCRIPT"
704 rm -rf "$TEST_DB"
705 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null 2>&1 \
706 | grep -q "Warning: Index action 'parsedate' has no effect" ; then
707 : # OK
708 else
709 echo "scriptindex didn't give expected warning for useless 'parsedate'"
710 failed=`expr $failed + 1`
713 # The 'hash' action should require its argument is >= 6, so test 5 is rejected.
714 printf 'url : hash=5 boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
715 rm -rf "$TEST_DB"
716 if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null > /dev/null 2>&1 ; then
717 echo "scriptindex didn't reject 'hash=5'"
718 failed=`expr $failed + 1`
721 # And that 6 is accepted.
722 printf 'url : hash=6 boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
723 rm -rf "$TEST_DB"
724 if echo 'url=http://xapian.org' | $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null 2>&1 ; then
725 : # OK
726 else
727 echo "scriptindex rejected 'hash=6'"
728 failed=`expr $failed + 1`
731 # Regression test to check hash works without argument (it was failing with an
732 # assertion in unreleased versions prior to 1.4.6).
733 printf 'url : hash boolean=Q unique=Q' > "$TEST_INDEXSCRIPT"
734 rm -rf "$TEST_DB"
735 if echo 'url=http://xapian.org' | $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null 2>&1 ; then
736 : # OK
737 else
738 echo "scriptindex rejected 'hash'"
739 failed=`expr $failed + 1`
742 # Test the same actions for multiple fields works (briefly broken in git master
743 # before 1.5.0).
744 printf 'tag1 tag2 tag3 : boolean=T field' > "$TEST_INDEXSCRIPT"
745 rm -rf "$TEST_DB"
746 $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" > /dev/null <<'END'
747 tag1=one
748 tag2=two
749 tag3=three
751 printf '$hitlist{$list{$terms{T},|}/$field{tag1}|$field{tag2}|$field{tag3}}' > "$TEST_TEMPLATE"
752 testcase 'Tone/one|two|three' B=Tone
753 testcase 'Tthree|Ttwo/one|two|three' B=Ttwo B=Tthree
755 rm "$OMEGA_CONFIG_FILE" "$TEST_INDEXSCRIPT" "$TEST_TEMPLATE"
756 rm -rf "$TEST_DB"
757 if [ "$failed" = 0 ] ; then
758 exit 0
760 echo "Failed $failed test(s)"
761 exit 1