Skip to content

Commit 55e1a7b

Browse files
committed
Tests: Move ngx.re.opt into init_by_lua
1 parent 65a92be commit 55e1a7b

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

t/re-find.t

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,31 @@ plan tests => repeat_each() * (blocks() * 5);
1313

1414
my $pwd = cwd();
1515

16-
our $HttpConfig = <<_EOC_;
17-
lua_package_path "$pwd/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
18-
init_by_lua '
19-
-- local verbose = true
20-
local verbose = false
21-
local outfile = "$Test::Nginx::Util::ErrLogFile"
22-
-- local outfile = "/tmp/v.log"
23-
if verbose then
24-
local dump = require "jit.dump"
25-
dump.on(nil, outfile)
26-
else
27-
local v = require "jit.v"
28-
v.on(outfile)
29-
end
30-
31-
require "resty.core"
32-
-- jit.opt.start("hotloop=1")
33-
-- jit.opt.start("loopunroll=1000000")
34-
-- jit.off()
35-
';
36-
_EOC_
16+
sub HttpConfig {
17+
return <<_EOC_;
18+
lua_package_path "$pwd/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
19+
init_by_lua '
20+
-- local verbose = true
21+
local verbose = false
22+
local outfile = "$Test::Nginx::Util::ErrLogFile"
23+
-- local outfile = "/tmp/v.log"
24+
if verbose then
25+
local dump = require "jit.dump"
26+
dump.on(nil, outfile)
27+
else
28+
local v = require "jit.v"
29+
v.on(outfile)
30+
end
31+
32+
require "resty.core"
33+
-- jit.opt.start("hotloop=1")
34+
-- jit.opt.start("loopunroll=1000000")
35+
-- jit.off()
36+
37+
$_[0]
38+
';
39+
_EOC_
40+
}
3741

3842
#no_diff();
3943
no_long_string();
@@ -43,7 +47,7 @@ run_tests();
4347
__DATA__
4448

4549
=== TEST 1: matched, no submatch, no jit compile, no regex cache
46-
--- http_config eval: $::HttpConfig
50+
--- http_config eval: $::HttpConfig()
4751
--- config
4852
location = /re {
4953
access_log off;
@@ -82,7 +86,7 @@ bad argument type
8286

8387

8488
=== TEST 2: matched, no submatch, jit compile, regex cache
85-
--- http_config eval: $::HttpConfig
89+
--- http_config eval: $::HttpConfig()
8690
--- config
8791
location = /re {
8892
access_log off;
@@ -121,7 +125,7 @@ NYI
121125

122126

123127
=== TEST 3: not matched, no submatch, jit compile, regex cache
124-
--- http_config eval: $::HttpConfig
128+
--- http_config eval: $::HttpConfig()
125129
--- config
126130
location = /re {
127131
access_log off;
@@ -158,7 +162,7 @@ NYI
158162

159163

160164
=== TEST 4: nil submatch (2nd)
161-
--- http_config eval: $::HttpConfig
165+
--- http_config eval: $::HttpConfig()
162166
--- config
163167
location /re {
164168
content_by_lua '
@@ -193,7 +197,7 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/
193197

194198

195199
=== TEST 5: nil submatch (1st)
196-
--- http_config eval: $::HttpConfig
200+
--- http_config eval: $::HttpConfig()
197201
--- config
198202
location /re {
199203
content_by_lua '
@@ -228,7 +232,7 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/
228232

229233

230234
=== TEST 6: specify the group (2)
231-
--- http_config eval: $::HttpConfig
235+
--- http_config eval: $::HttpConfig()
232236
--- config
233237
location /re {
234238
content_by_lua '
@@ -264,12 +268,11 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/
264268

265269

266270
=== TEST 7: matched, no submatch, no jit compile, no regex cache, large jit_stack_size
267-
--- http_config eval: $::HttpConfig
271+
--- http_config eval: $::HttpConfig('ngx.re.opt("jit_stack_size", 128 * 1024)')
268272
--- config
269273
location = /re {
270274
access_log off;
271275
content_by_lua '
272-
ngx.re.opt("jit_stack_size", 128 * 1024)
273276
local from, to, err
274277
local find = ngx.re.find
275278
local s = "a"
@@ -304,12 +307,11 @@ bad argument type
304307

305308

306309
=== TEST 8: matched, no submatch, jit compile, regex cache, large jit_stack_size
307-
--- http_config eval: $::HttpConfig
310+
--- http_config eval: $::HttpConfig('ngx.re.opt("jit_stack_size", 128 * 1024)')
308311
--- config
309312
location = /re {
310313
access_log off;
311314
content_by_lua '
312-
ngx.re.opt("jit_stack_size", 128 * 1024)
313315
local from, to, err
314316
local find = ngx.re.find
315317
local s = "a"

0 commit comments

Comments
 (0)