Merge lp:~marcustomlinson/unity-js-scopes/add-coverage into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 126
Merged at revision: 126
Proposed branch: lp:~marcustomlinson/unity-js-scopes/add-coverage
Merge into: lp:unity-js-scopes
Prerequisite: lp:~marcustomlinson/unity-js-scopes/lp-1527622
Diff against target: 438 lines (+323/-22)
8 files modified
CMakeLists.txt (+40/-17)
cmake/EnableCoverageReport.cmake (+166/-0)
cmake/FindLcov.cmake (+29/-0)
cmake/Findgcovr.cmake (+31/-0)
cmake/ParseArguments.cmake (+52/-0)
src/bindings/CMakeLists.txt (+2/-2)
src/common/CMakeLists.txt (+1/-1)
src/launcher/CMakeLists.txt (+2/-2)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/add-coverage
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+280964@code.launchpad.net

Commit message

Added test coverage report

To post a comment you must log in.
124. By Marcus Tomlinson

Merged SIGTERM fix

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
125. By Marcus Tomlinson

Added cmake modules dir to root CMakeLists.txt

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
126. By Marcus Tomlinson

Exclude headers from coverage report as they are never hit via our Node boundaries

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

+1

review: Approve
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Top approving

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-11-13 08:28:39 +0000
3+++ CMakeLists.txt 2015-12-23 08:26:29 +0000
4@@ -20,13 +20,7 @@
5
6 project(js-scopes)
7
8-include(CheckCXXCompilerFlag)
9-include(CheckIncludeFileCXX)
10-
11-# Standard install paths
12-include(GNUInstallDirs)
13-
14-set(CMAKE_INCLUDE_CURRENT_DIR TRUE CACHE INTERNAL "")
15+# Retrieve dependencies
16
17 message(STATUS "Retrieving deps")
18
19@@ -40,6 +34,29 @@
20 message(FATAL_ERROR "Retriving deps failed")
21 endif()
22
23+# Configure CMake environment
24+
25+string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
26+
27+set(CMAKE_INCLUDE_CURRENT_DIR TRUE CACHE INTERNAL "")
28+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
29+
30+include(CheckCXXCompilerFlag)
31+include(CheckIncludeFileCXX)
32+include(EnableCoverageReport)
33+include(GNUInstallDirs)
34+
35+# Enable testing
36+
37+enable_testing()
38+
39+add_custom_target(
40+ check
41+ ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure
42+)
43+
44+# Add includes
45+
46 include_directories(
47 ${CMAKE_CURRENT_SOURCE_DIR}/deps/node.js/deps/uv/include
48 ${CMAKE_CURRENT_SOURCE_DIR}/deps/node.js/deps/v8/include
49@@ -48,8 +65,7 @@
50 ${CMAKE_CURRENT_SOURCE_DIR}/src
51 )
52
53-string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
54-if(cmake_build_type_tolower STREQUAL "debug")
55+if(cmake_build_type_lower MATCHES debug)
56 link_directories(
57 ${CMAKE_CURRENT_SOURCE_DIR}/deps/node.js/out/Debug
58 )
59@@ -59,8 +75,11 @@
60 )
61 endif()
62
63+# Add sources
64+
65+add_subdirectory(doc)
66 add_subdirectory(src)
67-add_subdirectory(doc)
68+add_subdirectory(tests)
69
70 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples
71 DESTINATION ${CMAKE_INSTALL_DATADIR}/unity-js-scopes)
72@@ -70,11 +89,15 @@
73 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/qtc-templates/scope-js
74 DESTINATION /usr/ubuntu-sdk-ide/share/qtcreator/templates/wizards/ubuntu)
75
76-# Set up the tests
77-enable_testing()
78-add_subdirectory(tests)
79+# Enable coverage report
80
81-add_custom_target(
82- check
83- ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure
84-)
85+if (cmake_build_type_lower MATCHES coverage)
86+ ENABLE_COVERAGE_REPORT(TARGETS unity_js_scopes_bindings
87+ FILTER /usr/include
88+ ${CMAKE_CURRENT_SOURCE_DIR}/deps/*
89+ ${CMAKE_CURRENT_SOURCE_DIR}/examples/*
90+ ${CMAKE_CURRENT_SOURCE_DIR}/qtc-templates/*
91+ ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
92+ ${CMAKE_CURRENT_SOURCE_DIR}/tests/*
93+ ${CMAKE_BINARY_DIR}/*)
94+endif()
95
96=== added directory 'cmake'
97=== added file 'cmake/EnableCoverageReport.cmake'
98--- cmake/EnableCoverageReport.cmake 1970-01-01 00:00:00 +0000
99+++ cmake/EnableCoverageReport.cmake 2015-12-23 08:26:29 +0000
100@@ -0,0 +1,166 @@
101+# - Creates a special coverage build type and target on GCC.
102+#
103+# Defines a function ENABLE_COVERAGE_REPORT which generates the coverage target
104+# for selected targets. Optional arguments to this function are used to filter
105+# unwanted results using globbing expressions. Moreover targets with tests for
106+# the source code can be specified to trigger regenerating the report if the
107+# test has changed
108+#
109+# ENABLE_COVERAGE_REPORT(TARGETS target... [FILTER filter...] [TESTS test targets...])
110+#
111+# To generate a coverage report first build the project with
112+# CMAKE_BUILD_TYPE=coverage, then call make test and afterwards make coverage.
113+#
114+# The coverage report is based on gcov. Depending on the availability of lcov
115+# a HTML report will be generated and/or an XML report of gcovr is found.
116+# The generated coverage target executes all found solutions. Special targets
117+# exist to create e.g. only the xml report: coverage-xml.
118+#
119+# Copyright (C) 2010 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
120+#
121+# This program is free software; you can redistribute it
122+# and/or modify it under the terms of the GNU General
123+# Public License as published by the Free Software Foundation;
124+# either version 2, or (at your option)
125+# any later version.
126+#
127+# This program is distributed in the hope that it will be useful,
128+# but WITHOUT ANY WARRANTY; without even the implied warranty of
129+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130+# GNU General Public License for more details.
131+#
132+
133+INCLUDE(ParseArguments)
134+
135+FIND_PACKAGE(Lcov)
136+FIND_PACKAGE(gcovr)
137+
138+FUNCTION(ENABLE_COVERAGE_REPORT)
139+
140+ # argument parsing
141+ PARSE_ARGUMENTS(ARG "FILTER;TARGETS;TESTS" "" ${ARGN})
142+
143+ SET(COVERAGE_RAW_FILE "${CMAKE_BINARY_DIR}/coverage.raw.info")
144+ SET(COVERAGE_FILTERED_FILE "${CMAKE_BINARY_DIR}/coverage.info")
145+ SET(COVERAGE_REPORT_DIR "${CMAKE_BINARY_DIR}/coveragereport")
146+ SET(COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")
147+ SET(COVERAGE_XML_COMMAND_FILE "${CMAKE_BINARY_DIR}/coverage-xml.cmake")
148+
149+ # decide if there is any tool to create coverage data
150+ SET(TOOL_FOUND FALSE)
151+ IF(LCOV_FOUND OR GCOVR_FOUND)
152+ SET(TOOL_FOUND TRUE)
153+ ENDIF()
154+ IF(NOT TOOL_FOUND)
155+ MESSAGE(STATUS "Cannot enable coverage targets because neither lcov nor gcovr are found.")
156+ ENDIF()
157+
158+ STRING(TOLOWER "${CMAKE_BUILD_TYPE}" COVERAGE_BUILD_TYPE)
159+ IF(CMAKE_COMPILER_IS_GNUCXX AND TOOL_FOUND AND "${COVERAGE_BUILD_TYPE}" MATCHES "coverage")
160+
161+ MESSAGE(STATUS "Coverage support enabled for targets: ${ARG_TARGETS}")
162+
163+ # create coverage build type
164+ SET(CMAKE_CXX_FLAGS_COVERAGE ${CMAKE_CXX_FLAGS_DEBUG} PARENT_SCOPE)
165+ SET(CMAKE_C_FLAGS_COVERAGE ${CMAKE_C_FLAGS_DEBUG} PARENT_SCOPE)
166+ SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} coverage PARENT_SCOPE)
167+
168+ # instrument targets
169+ SET_TARGET_PROPERTIES(${ARG_TARGETS} PROPERTIES COMPILE_FLAGS --coverage
170+ LINK_FLAGS --coverage)
171+
172+ # html report
173+ IF (LCOV_FOUND)
174+
175+ MESSAGE(STATUS "Enabling HTML coverage report")
176+
177+ # set up coverage target
178+
179+ ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_RAW_FILE}
180+ COMMAND ${LCOV_EXECUTABLE} -c -d ${CMAKE_BINARY_DIR} -o ${COVERAGE_RAW_FILE}
181+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
182+ COMMENT "Collecting coverage data"
183+ DEPENDS ${ARG_TARGETS} ${ARG_TESTS}
184+ VERBATIM)
185+
186+ # filter unwanted stuff
187+ LIST(LENGTH ARG_FILTER FILTER_LENGTH)
188+ IF(${FILTER_LENGTH} GREATER 0)
189+ SET(FILTER COMMAND ${LCOV_EXECUTABLE})
190+ FOREACH(F ${ARG_FILTER})
191+ SET(FILTER ${FILTER} -r ${COVERAGE_FILTERED_FILE} ${F})
192+ ENDFOREACH()
193+ SET(FILTER ${FILTER} -o ${COVERAGE_FILTERED_FILE})
194+ ELSE()
195+ SET(FILTER "")
196+ ENDIF()
197+
198+ ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_FILTERED_FILE}
199+ COMMAND ${LCOV_EXECUTABLE} -e ${COVERAGE_RAW_FILE} "${CMAKE_SOURCE_DIR}*" -o ${COVERAGE_FILTERED_FILE}
200+ ${FILTER}
201+ DEPENDS ${COVERAGE_RAW_FILE}
202+ COMMENT "Filtering recorded coverage data for project-relevant entries"
203+ VERBATIM)
204+ ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_REPORT_DIR}
205+ COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_REPORT_DIR}
206+ COMMAND ${GENHTML_EXECUTABLE} --legend --show-details -t "${PROJECT_NAME} test coverage" -o ${COVERAGE_REPORT_DIR} ${COVERAGE_FILTERED_FILE}
207+ DEPENDS ${COVERAGE_FILTERED_FILE}
208+ COMMENT "Generating HTML coverage report in ${COVERAGE_REPORT_DIR}"
209+ VERBATIM)
210+
211+ ADD_CUSTOM_TARGET(coverage-html
212+ DEPENDS ${COVERAGE_REPORT_DIR})
213+
214+ ENDIF()
215+
216+ # xml coverage report
217+ IF(GCOVR_FOUND)
218+
219+ MESSAGE(STATUS "Enabling XML coverage report")
220+
221+ # filter unwanted stuff
222+ SET(GCOV_FILTER "")
223+ LIST(LENGTH ARG_FILTER FILTER_LENGTH)
224+ IF(${FILTER_LENGTH} GREATER 0)
225+ FOREACH(F ${ARG_FILTER})
226+ SET(GCOV_FILTER "${GCOV_FILTER} -e \"${F}\"")
227+ ENDFOREACH()
228+ ENDIF()
229+
230+ # gcovr cannot write directly to a file so the execution needs to
231+ # be wrapped in a cmake file that generates the file output
232+ FILE(WRITE ${COVERAGE_XML_COMMAND_FILE}
233+ "SET(ENV{LANG} en)\n")
234+ FILE(APPEND ${COVERAGE_XML_COMMAND_FILE}
235+ "EXECUTE_PROCESS(COMMAND \"${GCOVR_EXECUTABLE}\" -x -r \"${CMAKE_SOURCE_DIR}\" ${GCOV_FILTER} OUTPUT_FILE \"${COVERAGE_XML_FILE}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")\n")
236+
237+ ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_XML_FILE}
238+ COMMAND ${CMAKE_COMMAND} ARGS -P ${COVERAGE_XML_COMMAND_FILE}
239+ COMMENT "Generating coverage XML report"
240+ VERBATIM)
241+
242+ ADD_CUSTOM_TARGET(coverage-xml
243+ DEPENDS ${COVERAGE_XML_FILE})
244+
245+ ENDIF()
246+
247+ # provide a global coverage target executing both steps if available
248+ SET(GLOBAL_DEPENDS "")
249+ IF(LCOV_FOUND)
250+ LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_REPORT_DIR})
251+ ENDIF()
252+ IF(GCOVR_FOUND)
253+ LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_XML_FILE})
254+ ENDIF()
255+ IF(LCOV_FOUND OR GCOVR_FOUND)
256+ ADD_CUSTOM_TARGET(coverage
257+ DEPENDS ${GLOBAL_DEPENDS})
258+ ENDIF()
259+
260+ ENDIF()
261+
262+ # This gets rid of any stale .gcda files. Run this if a running a binary causes lots of messages about
263+ # about a "merge mismatch for summaries".
264+ ADD_CUSTOM_TARGET(clean-coverage COMMAND find ${CMAKE_BINARY_DIR} -name '*.gcda' | xargs rm -f)
265+
266+ENDFUNCTION()
267
268=== added file 'cmake/FindLcov.cmake'
269--- cmake/FindLcov.cmake 1970-01-01 00:00:00 +0000
270+++ cmake/FindLcov.cmake 2015-12-23 08:26:29 +0000
271@@ -0,0 +1,29 @@
272+# - Find lcov
273+# Will define:
274+#
275+# LCOV_EXECUTABLE - the lcov binary
276+# GENHTML_EXECUTABLE - the genhtml executable
277+#
278+# Copyright (C) 2010 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
279+#
280+# This program is free software; you can redistribute it
281+# and/or modify it under the terms of the GNU General
282+# Public License as published by the Free Software Foundation;
283+# either version 2, or (at your option)
284+# any later version.
285+#
286+# This program is distributed in the hope that it will be useful,
287+# but WITHOUT ANY WARRANTY; without even the implied warranty of
288+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
289+# GNU General Public License for more details.
290+#
291+
292+INCLUDE(FindPackageHandleStandardArgs)
293+
294+FIND_PROGRAM(LCOV_EXECUTABLE lcov)
295+FIND_PROGRAM(GENHTML_EXECUTABLE genhtml)
296+
297+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lcov DEFAULT_MSG LCOV_EXECUTABLE GENHTML_EXECUTABLE)
298+
299+# only visible in advanced view
300+MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE)
301
302=== added file 'cmake/Findgcovr.cmake'
303--- cmake/Findgcovr.cmake 1970-01-01 00:00:00 +0000
304+++ cmake/Findgcovr.cmake 2015-12-23 08:26:29 +0000
305@@ -0,0 +1,31 @@
306+# - Find gcovr scrip
307+# Will define:
308+#
309+# GCOVR_EXECUTABLE - the gcovr script
310+#
311+# Uses:
312+#
313+# GCOVR_ROOT - root to search for the script
314+#
315+# Copyright (C) 2011 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
316+#
317+# This program is free software; you can redistribute it
318+# and/or modify it under the terms of the GNU General
319+# Public License as published by the Free Software Foundation;
320+# either version 2, or (at your option)
321+# any later version.
322+#
323+# This program is distributed in the hope that it will be useful,
324+# but WITHOUT ANY WARRANTY; without even the implied warranty of
325+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
326+# GNU General Public License for more details.
327+#
328+
329+INCLUDE(FindPackageHandleStandardArgs)
330+
331+FIND_PROGRAM(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
332+
333+FIND_PACKAGE_HANDLE_STANDARD_ARGS(gcovr DEFAULT_MSG GCOVR_EXECUTABLE)
334+
335+# only visible in advanced view
336+MARK_AS_ADVANCED(GCOVR_EXECUTABLE)
337
338=== added file 'cmake/ParseArguments.cmake'
339--- cmake/ParseArguments.cmake 1970-01-01 00:00:00 +0000
340+++ cmake/ParseArguments.cmake 2015-12-23 08:26:29 +0000
341@@ -0,0 +1,52 @@
342+# Parse arguments passed to a function into several lists separated by
343+# upper-case identifiers and options that do not have an associated list e.g.:
344+#
345+# SET(arguments
346+# hello OPTION3 world
347+# LIST3 foo bar
348+# OPTION2
349+# LIST1 fuz baz
350+# )
351+# PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments})
352+#
353+# results in 7 distinct variables:
354+# * ARG_DEFAULT_ARGS: hello;world
355+# * ARG_LIST1: fuz;baz
356+# * ARG_LIST2:
357+# * ARG_LIST3: foo;bar
358+# * ARG_OPTION1: FALSE
359+# * ARG_OPTION2: TRUE
360+# * ARG_OPTION3: TRUE
361+#
362+# taken from http://www.cmake.org/Wiki/CMakeMacroParseArguments
363+
364+MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
365+ SET(DEFAULT_ARGS)
366+ FOREACH(arg_name ${arg_names})
367+ SET(${prefix}_${arg_name})
368+ ENDFOREACH(arg_name)
369+ FOREACH(option ${option_names})
370+ SET(${prefix}_${option} FALSE)
371+ ENDFOREACH(option)
372+
373+ SET(current_arg_name DEFAULT_ARGS)
374+ SET(current_arg_list)
375+ FOREACH(arg ${ARGN})
376+ SET(larg_names ${arg_names})
377+ LIST(FIND larg_names "${arg}" is_arg_name)
378+ IF (is_arg_name GREATER -1)
379+ SET(${prefix}_${current_arg_name} ${current_arg_list})
380+ SET(current_arg_name ${arg})
381+ SET(current_arg_list)
382+ ELSE (is_arg_name GREATER -1)
383+ SET(loption_names ${option_names})
384+ LIST(FIND loption_names "${arg}" is_option)
385+ IF (is_option GREATER -1)
386+ SET(${prefix}_${arg} TRUE)
387+ ELSE (is_option GREATER -1)
388+ SET(current_arg_list ${current_arg_list} ${arg})
389+ ENDIF (is_option GREATER -1)
390+ ENDIF (is_arg_name GREATER -1)
391+ ENDFOREACH(arg)
392+ SET(${prefix}_${current_arg_name} ${current_arg_list})
393+ENDMACRO(PARSE_ARGUMENTS)
394
395=== modified file 'src/bindings/CMakeLists.txt'
396--- src/bindings/CMakeLists.txt 2015-12-23 08:26:29 +0000
397+++ src/bindings/CMakeLists.txt 2015-12-23 08:26:29 +0000
398@@ -93,9 +93,9 @@
399 COMMAND ${CMAKE_COMMAND} -E make_directory
400 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/lib"
401
402- COMMAND ${CMAKE_COMMAND} -E copy_if_different
403+ COMMAND ${CMAKE_COMMAND} -E create_symlink
404 "${CMAKE_CURRENT_BINARY_DIR}/unity_js_scopes_bindings.node"
405- "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes"
406+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/unity_js_scopes_bindings.node"
407 COMMAND ${CMAKE_COMMAND} -E copy_if_different
408 "${CMAKE_CURRENT_SOURCE_DIR}/index.js"
409 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes"
410
411=== modified file 'src/common/CMakeLists.txt'
412--- src/common/CMakeLists.txt 2015-11-13 08:28:39 +0000
413+++ src/common/CMakeLists.txt 2015-12-23 08:26:29 +0000
414@@ -45,7 +45,7 @@
415 dl
416 )
417
418-if(cmake_build_type_tolower STREQUAL "debug")
419+if(cmake_build_type_lower MATCHES debug)
420 add_custom_command(
421 TARGET nodejs-static PRE_LINK
422 COMMAND ${CMAKE_SOURCE_DIR}/deps/build-debug.sh
423
424=== modified file 'src/launcher/CMakeLists.txt'
425--- src/launcher/CMakeLists.txt 2015-11-13 08:28:39 +0000
426+++ src/launcher/CMakeLists.txt 2015-12-23 08:26:29 +0000
427@@ -73,9 +73,9 @@
428 COMMAND ${CMAKE_COMMAND} -E make_directory
429 "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin"
430
431- COMMAND ${CMAKE_COMMAND} -E copy_if_different
432+ COMMAND ${CMAKE_COMMAND} -E create_symlink
433 "${CMAKE_CURRENT_BINARY_DIR}/unity-js-scopes-launcher"
434- "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin"
435+ "${CMAKE_BINARY_DIR}/tests/node_modules/unity-js-scopes/bin/unity-js-scopes-launcher"
436 )
437
438 install(TARGETS ${LAUNCHER_EXECUTABLE_NAME}

Subscribers

People subscribed via source and target branches

to all changes: