Skip to content

Commit a17e710

Browse files
committed
Add code coverage and coveralls support
Patch adds a support of code coverage for Lua source code and Coveralls support, see [1]. 1. https://coveralls.io/github/tarantool/http
1 parent 6172d91 commit a17e710

File tree

6 files changed

+76
-5
lines changed

6 files changed

+76
-5
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
tarantool: ['1.10', '2.5', '2.6', '2.7', '2.8']
12+
tarantool: ['1.10', '2.5', '2.6', '2.7']
13+
coveralls: [false]
14+
include:
15+
- tarantool: '2.8'
16+
coveralls: true
1317
runs-on: [ubuntu-latest]
1418
steps:
1519
- uses: actions/checkout@master
@@ -22,7 +26,7 @@ jobs:
2226
id: cache-rocks
2327
with:
2428
path: .rocks/
25-
key: cache-rocks-${{ matrix.tarantool }}-03
29+
key: cache-rocks-${{ matrix.tarantool }}-05
2630

2731
- run: echo $PWD/.rocks/bin >> $GITHUB_PATH
2832

@@ -32,6 +36,12 @@ jobs:
3236
run: |
3337
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -S . -B build
3438
make -C build
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3541

36-
- name: Run tests
37-
run: make -C build luatest
42+
- name: Run tests and code coverage analysis
43+
run: make -C build coverage
44+
45+
- name: Send code coverage to coveralls.io
46+
run: make -C build coveralls
47+
if: ${{ matrix.coveralls }}

CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
88

99
find_package(LuaTest)
1010
find_package(LuaCheck)
11+
find_package(LuaCov)
12+
find_package(LuaCovCoveralls)
13+
14+
set(CODE_COVERAGE_REPORT "${PROJECT_SOURCE_DIR}/luacov.report.out")
15+
set(CODE_COVERAGE_STATS "${PROJECT_SOURCE_DIR}/luacov.stats.out")
1116

1217
# Find Tarantool and Lua dependecies
1318
set(Tarantool_FIND_REQUIRED ON)
@@ -26,11 +31,36 @@ add_custom_target(luacheck
2631
)
2732

2833
add_custom_target(luatest
29-
COMMAND ${LUATEST} -v
34+
COMMAND ${LUATEST} -v --coverage
35+
BYPRODUCTS ${CODE_COVERAGE_STATS}
3036
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
3137
COMMENT "Run regression tests"
3238
)
3339

40+
add_custom_target(coverage
41+
COMMAND ${LUACOV} ${PROJECT_SOURCE_DIR} && grep -A999 '^Summary' ${CODE_COVERAGE_REPORT}
42+
DEPENDS ${CODE_COVERAGE_STATS}
43+
BYPRODUCTS ${CODE_COVERAGE_REPORT}
44+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
45+
COMMENT "Generate code coverage stats"
46+
)
47+
48+
if(DEFINED ENV{GITHUB_TOKEN})
49+
set(COVERALLS_COMMAND ${LUACOVCOVERALLS} --include ^http --verbose --repo-token $ENV{GITHUB_TOKEN})
50+
else()
51+
set(COVERALLS_COMMAND ${CMAKE_COMMAND} -E echo "Skipped uploading to coveralls.io: no token.")
52+
endif()
53+
54+
add_custom_target(coveralls
55+
# Replace absolute paths with relative ones.
56+
# In command line: sed -i -e 's@'"$(realpath .)"'/@@'.
57+
COMMAND sed -i -e "\"s@\"'${PROJECT_SOURCE_DIR}'\"/@@\"" ${CODE_COVERAGE_STATS}
58+
COMMAND ${COVERALLS_COMMAND}
59+
DEPENDS ${CODE_COVERAGE_STATS}
60+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
61+
COMMENT "Send code coverage data to the coveralls.io service"
62+
)
63+
3464
set (LUA_PATH "LUA_PATH=${PROJECT_SOURCE_DIR}/?.lua\\;${PROJECT_SOURCE_DIR}/?/init.lua\\;\\;")
3565
set (LUA_SOURCE_DIR "LUA_SOURCE_DIR=${PROJECT_SOURCE_DIR}")
3666
set_target_properties(luatest PROPERTIES ENVIRONMENT "${LUA_PATH};${LUA_SOURCE_DIR}")

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ align="right">
77

88
[![Static analysis](https://github.com/tarantool/http/actions/workflows/check_on_push.yaml/badge.svg)](https://github.com/tarantool/http/actions/workflows/check_on_push.yaml)
99
[![Test](https://github.com/tarantool/http/actions/workflows/test.yml/badge.svg)](https://github.com/tarantool/http/actions/workflows/test.yml)
10+
[![Coverage Status](https://coveralls.io/repos/github/tarantool/http/badge.svg?branch=master)](https://coveralls.io/github/tarantool/http?branch=master)
1011

1112
> **Note:** In Tarantool 1.7.5+, a full-featured HTTP client is available aboard.
1213
> For Tarantool 1.6.5+, both HTTP server and client are available

cmake/FindLuaCov.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
find_program(LUACOV luacov
2+
HINTS .rocks/
3+
PATH_SUFFIXES bin
4+
DOC "Lua test coverage analysis"
5+
)
6+
7+
include(FindPackageHandleStandardArgs)
8+
find_package_handle_standard_args(LuaCov
9+
REQUIRED_VARS LUACOV
10+
)
11+
12+
mark_as_advanced(LUACOV)

cmake/FindLuaCovCoveralls.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
find_program(LUACOVCOVERALLS luacov-coveralls
2+
HINTS .rocks/
3+
PATH_SUFFIXES bin
4+
DOC "LuaCov reporter for coveralls.io service"
5+
)
6+
7+
include(FindPackageHandleStandardArgs)
8+
find_package_handle_standard_args(LuaCovCoveralls
9+
REQUIRED_VARS LUACOVCOVERALLS
10+
)
11+
12+
mark_as_advanced(LUACOVCOVERALLS)

deps.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ set -e
66

77
# Test dependencies:
88
tarantoolctl rocks install luatest 0.5.5
9+
tarantoolctl rocks install luacheck 0.25.0
10+
tarantoolctl rocks install luacov 0.13.0
11+
12+
# cluacov, luacov-coveralls and dependencies
13+
tarantoolctl rocks install luacov-coveralls 0.2.3-1 --server=https://luarocks.org
14+
tarantoolctl rocks install cluacov 0.1.2-1 --server=https://luarocks.org
915

1016
tarantoolctl rocks make

0 commit comments

Comments
 (0)