Skip to content

Commit 18ac184

Browse files
authored
Code coverage support on coveralls.io (#13)
* Coverage testing * Initial check in of coveralls setup * Move coverage to linux * Fix action name * Fix warnings * Added badge to readme
1 parent ce0d631 commit 18ac184

File tree

7 files changed

+121
-6
lines changed

7 files changed

+121
-6
lines changed

.coveralls.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: amVxRIVnLlAXJBJo02AKMkxVHN0IeBArV

.github/workflows/build_linux.yml

-3
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,12 @@ jobs:
5151

5252
- name: Test Lua 5.4
5353
working-directory: ${{runner.workspace}}/build/Tests
54-
shell: bash
5554
run: ./LuaBridgeTests54
5655

5756
- name: Test Lua 5.4 - No Exceptions
5857
working-directory: ${{runner.workspace}}/build/Tests
59-
shell: bash
6058
run: ./LuaBridgeTests54Noexcept
6159

6260
- name: Test Luau
6361
working-directory: ${{runner.workspace}}/build/Tests
64-
shell: bash
6562
run: ./LuaBridgeTestsLuau

.github/workflows/coverage.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Code Coverage
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
10+
- uses: actions/checkout@v2
11+
with:
12+
submodules: true
13+
14+
- name: Install lcov
15+
run: sudo apt-get install -y lcov
16+
17+
- name: Create Build Environment
18+
run: cmake -E make_directory ${{runner.workspace}}/build
19+
20+
- name: Configure
21+
working-directory: ${{runner.workspace}}/build
22+
run: cmake $GITHUB_WORKSPACE
23+
24+
- name: Build
25+
working-directory: ${{runner.workspace}}/build
26+
run: cmake --build . --target LuaBridgeTestsCoverage -- -j4
27+
28+
- name: Coveralls
29+
uses: coverallsapp/github-action@master
30+
with:
31+
path-to-lcov: ${{runner.workspace}}/build/coverage/Merged.info
32+
github-token: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ set (CMAKE_CXX_STANDARD 17)
88
set (CMAKE_CXX_STANDARD_REQUIRED ON)
99
set (CMAKE_CXX_EXTENSIONS OFF)
1010

11-
cmake_dependent_option (LUABRIDGE_TESTING "Build tests" ON
12-
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
11+
find_program (FIND_EXECUTABLE find)
12+
find_program (LCOV_EXECUTABLE lcov)
13+
find_program (GENHTML_EXECUTABLE genhtml)
14+
15+
cmake_dependent_option (LUABRIDGE_TESTING "Build tests" ON "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
16+
cmake_dependent_option (LUABRIDGE_COVERAGE "Enable coverage" ON "LUABRIDGE_TESTING;FIND_EXECUTABLE;LCOV_EXECUTABLE;GENHTML_EXECUTABLE" OFF)
1317

1418
add_subdirectory (Source)
1519

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ LuaBridge is usable from a compliant C++17 compiler and offers the following fea
3535
![Build MacOS](https://github.com/kunitoki/LuaBridge3/workflows/Build%20MacOS/badge.svg?branch=master)
3636
![Build Windows](https://github.com/kunitoki/LuaBridge3/workflows/Build%20Windows/badge.svg?branch=master)
3737
![Build Linux](https://github.com/kunitoki/LuaBridge3/workflows/Build%20Linux/badge.svg?branch=master)
38+
[![Coverage Status](https://coveralls.io/repos/github/kunitoki/LuaBridge3/badge.svg?branch=master)](https://coveralls.io/github/kunitoki/LuaBridge3?branch=master)
3839

3940
## Documentation
4041

Tests/CMakeLists.txt

+73
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,70 @@ file (GLOB_RECURSE LUABRIDGE_TEST_LUAU_FILES
7272
Lua/LuauSplit.cpp
7373
)
7474

75+
# ====================================================== Coverage
76+
77+
function (setup_target_for_coverage TARGET_NAME SOURCE_LOCATION SOURCE_PACKAGE)
78+
if ("${CMAKE_GENERATOR}" STREQUAL "Xcode")
79+
set_target_properties (${TARGET_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS "YES")
80+
set_target_properties (${TARGET_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_INSTRUMENT_PROGRAM_FLOW_ARCS "YES")
81+
set_target_properties (${TARGET_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_GENERATE_TEST_COVERAGE_FILES "YES")
82+
else ()
83+
target_compile_options (${TARGET_NAME} PRIVATE -fprofile-arcs -ftest-coverage)
84+
target_link_options (${TARGET_NAME} PRIVATE -fprofile-arcs)
85+
endif()
86+
87+
add_custom_command (
88+
OUTPUT "${CMAKE_BINARY_DIR}/coverage/${TARGET_NAME}.info"
89+
COMMAND ${FIND_EXECUTABLE} . -iname "*.gcda" -delete
90+
COMMAND ${TARGET_NAME} ${ARGV3}
91+
COMMAND ${CMAKE_COMMAND} -E make_directory coverage
92+
COMMAND ${CMAKE_COMMAND} -E rm -f coverage_html/${TARGET_NAME}.info
93+
COMMAND ${LCOV_EXECUTABLE}
94+
-c -d "${CMAKE_BINARY_DIR}"
95+
--include "*/${SOURCE_PACKAGE}/*"
96+
--exclude "*/Tests/*"
97+
--exclude "*/Distribution/*"
98+
--exclude "*/coverage_html/*"
99+
-o "${CMAKE_BINARY_DIR}/coverage/${TARGET_NAME}.info"
100+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
101+
VERBATIM)
102+
103+
# Message status
104+
message (STATUS "Luabridge3 -- Enabled code coverage reporting for ${TARGET_NAME}")
105+
endfunction ()
106+
107+
function (setup_coverage_single_target)
108+
add_custom_target (LuaBridgeTestsCoverage
109+
COMMAND ${CMAKE_COMMAND} -E make_directory coverage_html
110+
COMMAND ${CMAKE_COMMAND} -E rm -Rf coverage_html/*
111+
COMMAND ${LCOV_EXECUTABLE}
112+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests51.info"
113+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests51Noexcept.info"
114+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests52.info"
115+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests52Noexcept.info"
116+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests53.info"
117+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests53Noexcept.info"
118+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests54.info"
119+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests54Noexcept.info"
120+
-a "${CMAKE_BINARY_DIR}/coverage/LuaBridgeTestsLuau.info"
121+
-o "${CMAKE_BINARY_DIR}/coverage/Merged.info"
122+
COMMAND ${GENHTML_EXECUTABLE}
123+
"${CMAKE_BINARY_DIR}/coverage/Merged.info" -o "${CMAKE_BINARY_DIR}/coverage_html"
124+
DEPENDS
125+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests51.info"
126+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests51Noexcept.info"
127+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests52.info"
128+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests52Noexcept.info"
129+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests53.info"
130+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests53Noexcept.info"
131+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests54.info"
132+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTests54Noexcept.info"
133+
"${CMAKE_BINARY_DIR}/coverage/LuaBridgeTestsLuau.info"
134+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
135+
VERBATIM)
136+
137+
endfunction ()
138+
75139
# ====================================================== Macro
76140

77141
macro (add_test_app LUABRIDGE_TEST_NAME LUA_VERSION LUABRIDGE_TEST_LUA_LIBRARY_FILES LUABRIDGE_EXCEPTIONS)
@@ -81,6 +145,11 @@ macro (add_test_app LUABRIDGE_TEST_NAME LUA_VERSION LUABRIDGE_TEST_LUA_LIBRARY_F
81145
${LUABRIDGE_TEST_LUA_LIBRARY_FILES}
82146
)
83147

148+
if (LUABRIDGE_COVERAGE)
149+
get_filename_component (SOURCE_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../Source" ABSOLUTE)
150+
setup_target_for_coverage (${LUABRIDGE_TEST_NAME} ${SOURCE_LOCATION} LuaBridge)
151+
endif ()
152+
84153
target_include_directories (${LUABRIDGE_TEST_NAME} PRIVATE . Source)
85154
if (${LUA_VERSION} STREQUAL "LUAU")
86155
target_include_directories (${LUABRIDGE_TEST_NAME} PRIVATE "${LUABRIDGE_LUAU_LOCATION}/VM/include")
@@ -133,3 +202,7 @@ add_test_app (LuaBridgeTests54Noexcept 504 "${LUABRIDGE_TEST_LUA54_FILES}" 0)
133202

134203
add_test_app (LuaBridgeTestsLuau "LUAU" "${LUABRIDGE_TEST_LUAU_FILES}" 1)
135204
#add_test_app (LuaBridgeTestsLuauNoexcept "LUAU" "${LUABRIDGE_TEST_LUAU_FILES}" 0)
205+
206+
if (LUABRIDGE_COVERAGE)
207+
setup_coverage_single_target ()
208+
endif ()

Tests/Lua/LuaLibrary5.1.5.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//==============================================================================
22
/*
33
https://github.com/kunitoki/LuaBridge3
4-
4+
55
Copyright (C) 2020, Lucio Asnaghi <[email protected]>
66
Copyright (C) 2012, Vinnie Falco <[email protected]>
77
@@ -60,8 +60,13 @@ extern "C"
6060
#pragma warning (disable: 4297) /* Function assumed not to throw an exception but does */
6161
#pragma warning (disable: 4334) /* Result of 32-bit shift implicitly converted to 64 bits */
6262
#pragma warning (disable: 4702) /* Unreachable code */
63+
#elif __GNUC__
64+
#pragma GCC diagnostic push
65+
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
6366
#endif
6467

68+
#if GNUC
69+
6570
/* Include this early to prevent the conflict with luai_hashnum
6671
and supress the warning caused by #define lua_assert
6772
*/
@@ -102,6 +107,8 @@ extern "C"
102107

103108
#if _MSC_VER
104109
#pragma warning (pop)
110+
#elif __GNUC__
111+
#pragma GCC diagnostic pop
105112
#endif
106113

107114
#ifdef __cplusplus

0 commit comments

Comments
 (0)