authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-23 09:57:38-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-23 09:57:38-07:00
logda406cb11287e2961ad5aaa6ca857efd57fb9d03
treef369334843e5ad121f2c1dc5a2f5213548559caf
parent97fae8cc85352cceabbf84bcc7481c138eb8b666

build: add test coverage target


2 files changed, 38 insertions(+), 1 deletions(-)

CMakeLists.txt+24-1
......@@ -20,6 +20,8 @@ set(ZIG_LIBC_INCLUDE_DIR "/usr/include" CACHE STRING "Default native target libc
2020set(ZIG_LD_PATH "ld" CACHE STRING "Path to ld for the native target")
2121set(ZIG_DYNAMIC_LINKER "" CACHE STRING "Override dynamic linker for native target")
2222
23option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF)
24
2325
2426
2527find_package(llvm)
......@@ -175,10 +177,17 @@ if(MINGW)
175177endif()
176178
177179set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes")
180set(EXE_LDFLAGS " ")
181if(ZIG_TEST_COVERAGE)
182 set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")
183 set(EXE_LDFLAGS "-fprofile-arcs -ftest-coverage")
184endif()
178185
179186add_executable(zig ${ZIG_SOURCES})
180187set_target_properties(zig PROPERTIES
181 COMPILE_FLAGS ${EXE_CFLAGS})
188 COMPILE_FLAGS ${EXE_CFLAGS}
189 LINK_FLAGS ${EXE_LDFLAGS}
190)
182191target_link_libraries(zig LINK_PUBLIC
183192 ${CLANG_LIBRARIES}
184193 ${LLVM_LIBRARIES}
......@@ -208,4 +217,18 @@ add_executable(run_tests ${TEST_SOURCES})
208217target_link_libraries(run_tests)
209218set_target_properties(run_tests PROPERTIES
210219 COMPILE_FLAGS ${EXE_CFLAGS}
220 LINK_FLAGS ${EXE_LDFLAGS}
211221)
222
223if (ZIG_TEST_COVERAGE)
224 add_custom_target(coverage
225 DEPENDS run_tests
226 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
227 COMMAND lcov --directory . --zerocounters --rc lcov_branch_coverage=1
228 COMMAND ./run_tests
229 COMMAND lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1
230 COMMAND lcov --remove coverage.info '/usr/*' --output-file coverage.info.cleaned --rc lcov_branch_coverage=1
231 COMMAND genhtml -o coverage coverage.info.cleaned --rc lcov_branch_coverage=1
232 COMMAND rm coverage.info coverage.info.cleaned
233 )
234endif()
README.md+14
......@@ -101,6 +101,20 @@ make
101101sudo make install
102102```
103103
104### Test Coverage
105
106To see test coverage in Zig, configure with `-DZIG_TEST_COVERAGE=ON` as an
107additional parameter to the Debug build.
108
109You must have `lcov` installed and available.
110
111Then `make coverage`.
112
113With GCC you will get a nice HTML view of the coverage data. With clang,
114the last step will fail, but you can execute
115`llvm-cov gcov $(find CMakeFiles/ -name "*.gcda")` and then inspect the
116produced .gcov files.
117
104118### Troubleshooting
105119
106120If you get one of these: