Skip to content

Commit 363f4a3

Browse files
committed
Added code coverage to tests
1 parent 47ebda8 commit 363f4a3

15 files changed

+197
-105
lines changed

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ test: all
1818
PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH TEST_NGINX_NO_SHUFFLE=1 prove -I../test-nginx/lib -r $(TEST_FILE)
1919
util/lua-releng
2020

21+
coverage: all
22+
-@echo "Cleaning stats"
23+
@rm -f luacov.stats.out
24+
PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH TEST_NGINX_NO_SHUFFLE=1 TEST_COVERAGE=1 prove -I../test-nginx/lib -r $(TEST_FILE)
25+
@luacov
26+
@tail -10 luacov.report.out

t/01-basic.t

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
# vim:set ft= ts=4 sw=4 et:
2-
31
use Test::Nginx::Socket;
42
use Cwd qw(cwd);
53

64
plan tests => repeat_each() * (blocks() * 4) + 1;
75

86
my $pwd = cwd();
97

8+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
9+
$ENV{TEST_COVERAGE} ||= 0;
10+
1011
our $HttpConfig = qq{
11-
lua_package_path "$pwd/lib/?.lua;;";
12+
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
1213
error_log logs/error.log debug;
13-
};
1414
15-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
15+
init_by_lua_block {
16+
if $ENV{TEST_COVERAGE} == 1 then
17+
jit.off()
18+
require("luacov.runner").init()
19+
end
20+
}
21+
};
1622

1723
no_long_string();
1824
#no_diff();
@@ -35,7 +41,7 @@ __DATA__
3541
3642
ngx.status = res.status
3743
ngx.print(res:read_body())
38-
44+
3945
httpc:close()
4046
';
4147
}
@@ -67,7 +73,7 @@ OK
6773
6874
ngx.status = res.status
6975
ngx.print(res:read_body())
70-
76+
7177
httpc:close()
7278
';
7379
}
@@ -91,15 +97,15 @@ OK
9197
local http = require "resty.http"
9298
local httpc = http.new()
9399
httpc:connect("127.0.0.1", ngx.var.server_port)
94-
100+
95101
local res, err = httpc:request{
96102
path = "/b"
97103
}
98104
99105
ngx.status = res.status
100106
ngx.say(res.reason)
101107
ngx.print(res:read_body())
102-
108+
103109
httpc:close()
104110
';
105111
}
@@ -128,14 +134,14 @@ OK
128134
local http = require "resty.http"
129135
local httpc = http.new()
130136
httpc:connect("127.0.0.1", ngx.var.server_port)
131-
137+
132138
local res, err = httpc:request{
133139
path = "/b"
134140
}
135141
136142
ngx.status = res.status
137143
ngx.say(res.headers["X-Test"])
138-
144+
139145
httpc:close()
140146
';
141147
}
@@ -162,7 +168,7 @@ x-value
162168
local http = require "resty.http"
163169
local httpc = http.new()
164170
httpc:connect("127.0.0.1", ngx.var.server_port)
165-
171+
166172
local res, err = httpc:request{
167173
query = {
168174
a = 1,
@@ -178,7 +184,7 @@ x-value
178184
end
179185
180186
ngx.print(res:read_body())
181-
187+
182188
httpc:close()
183189
';
184190
}
@@ -207,7 +213,7 @@ X-Header-B: 2
207213
local http = require "resty.http"
208214
local httpc = http.new()
209215
httpc:connect("127.0.0.1", ngx.var.server_port)
210-
216+
211217
local res, err = httpc:request{
212218
method = "HEAD",
213219
path = "/b"
@@ -230,4 +236,3 @@ GET /a
230236
--- no_error_log
231237
[error]
232238
[warn]
233-

t/02-chunked.t

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
# vim:set ft= ts=4 sw=4 et:
2-
31
use Test::Nginx::Socket;
42
use Cwd qw(cwd);
53

64
plan tests => repeat_each() * (blocks() * 4);
75

86
my $pwd = cwd();
97

8+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
9+
$ENV{TEST_COVERAGE} ||= 0;
10+
1011
our $HttpConfig = qq{
11-
lua_package_path "$pwd/lib/?.lua;;";
12+
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
13+
error_log logs/error.log debug;
14+
15+
init_by_lua_block {
16+
if $ENV{TEST_COVERAGE} == 1 then
17+
jit.off()
18+
require("luacov.runner").init()
19+
end
20+
}
1221
};
1322

14-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
15-
1623
no_long_string();
1724
#no_diff();
1825

@@ -27,7 +34,7 @@ __DATA__
2734
local http = require "resty.http"
2835
local httpc = http.new()
2936
httpc:connect("127.0.0.1", ngx.var.server_port)
30-
37+
3138
local res, err = httpc:request{
3239
path = "/b"
3340
}
@@ -66,7 +73,7 @@ GET /a
6673
local http = require "resty.http"
6774
local httpc = http.new()
6875
httpc:connect("127.0.0.1", ngx.var.server_port)
69-
76+
7077
local res, err = httpc:request{
7178
path = "/b"
7279
}
@@ -122,7 +129,7 @@ GET /a
122129
local http = require "resty.http"
123130
local httpc = http.new()
124131
httpc:connect("127.0.0.1", ngx.var.server_port)
125-
132+
126133
local res, err = httpc:request{
127134
path = "/b"
128135
}

t/03-requestbody.t

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
# vim:set ft= ts=4 sw=4 et:
2-
31
use Test::Nginx::Socket;
42
use Cwd qw(cwd);
53

64
plan tests => repeat_each() * (blocks() * 4);
75

86
my $pwd = cwd();
97

8+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
9+
$ENV{TEST_COVERAGE} ||= 0;
10+
1011
our $HttpConfig = qq{
11-
lua_package_path "$pwd/lib/?.lua;;";
12+
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
13+
error_log logs/error.log debug;
14+
15+
init_by_lua_block {
16+
if $ENV{TEST_COVERAGE} == 1 then
17+
jit.off()
18+
require("luacov.runner").init()
19+
end
20+
}
1221
};
1322

14-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
15-
1623
no_long_string();
1724
#no_diff();
1825

@@ -27,7 +34,7 @@ __DATA__
2734
local http = require "resty.http"
2835
local httpc = http.new()
2936
httpc:connect("127.0.0.1", ngx.var.server_port)
30-
37+
3138
local res, err = httpc:request{
3239
body = "a=1&b=2&c=3",
3340
path = "/b",
@@ -68,7 +75,7 @@ c: 3
6875
local http = require "resty.http"
6976
local httpc = http.new()
7077
httpc:connect("127.0.0.1", ngx.var.server_port)
71-
78+
7279
local res, err = httpc:request{
7380
method = "POST",
7481
body = "a=1&b=2&c=3",
@@ -182,4 +189,3 @@ Expectation Failed
182189
--- no_error_log
183190
[error]
184191
[warn]
185-

t/04-trailers.t

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
# vim:set ft= ts=4 sw=4 et:
2-
31
use Test::Nginx::Socket;
42
use Cwd qw(cwd);
53

64
plan tests => repeat_each() * (blocks() * 4);
75

86
my $pwd = cwd();
97

8+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
9+
$ENV{TEST_COVERAGE} ||= 0;
10+
1011
our $HttpConfig = qq{
11-
lua_package_path "$pwd/lib/?.lua;;";
12+
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
13+
error_log logs/error.log debug;
14+
15+
init_by_lua_block {
16+
if $ENV{TEST_COVERAGE} == 1 then
17+
jit.off()
18+
require("luacov.runner").init()
19+
end
20+
}
1221
};
1322

14-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
15-
1623
no_long_string();
1724
#no_diff();
1825

@@ -27,7 +34,7 @@ __DATA__
2734
local http = require "resty.http"
2835
local httpc = http.new()
2936
httpc:connect("127.0.0.1", ngx.var.server_port)
30-
37+
3138
local res, err = httpc:request{
3239
path = "/b",
3340
headers = {
@@ -70,7 +77,7 @@ __DATA__
7077
table.insert(res, body)
7178
table.insert(res, "0")
7279
table.insert(res, "")
73-
80+
7481
table.insert(res, "Content-MD5: " .. ngx.md5(body))
7582
7683
table.insert(res, "")
@@ -95,7 +102,7 @@ OK
95102
local http = require "resty.http"
96103
local httpc = http.new()
97104
httpc:connect("127.0.0.1", ngx.var.server_port)
98-
105+
99106
local res, err = httpc:request{
100107
path = "/b",
101108
headers = {
@@ -134,7 +141,7 @@ OK
134141
table.insert(res, string.format("%x", #body))
135142
table.insert(res, body)
136143
table.insert(res, "0")
137-
144+
138145
table.insert(res, "")
139146
table.insert(res, "")
140147
sock:send(table.concat(res, "\\r\\n"))
@@ -147,5 +154,3 @@ OK
147154
--- no_error_log
148155
[error]
149156
[warn]
150-
151-

t/05-stream.t

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
# vim:set ft= ts=4 sw=4 et:
2-
31
use Test::Nginx::Socket;
42
use Cwd qw(cwd);
53

64
plan tests => repeat_each() * (blocks() * 4) - 1;
75

86
my $pwd = cwd();
97

8+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
9+
$ENV{TEST_COVERAGE} ||= 0;
10+
1011
our $HttpConfig = qq{
11-
lua_package_path "$pwd/lib/?.lua;;";
12+
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
13+
error_log logs/error.log debug;
14+
15+
init_by_lua_block {
16+
if $ENV{TEST_COVERAGE} == 1 then
17+
jit.off()
18+
require("luacov.runner").init()
19+
end
20+
}
1221
};
1322

14-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
15-
1623
no_long_string();
1724
#no_diff();
1825

0 commit comments

Comments
 (0)