1CTEST_COVERAGE_COMMAND 2---------------------- 3 4.. versionadded:: 3.1 5 6Specify the CTest ``CoverageCommand`` setting 7in a :manual:`ctest(1)` dashboard client script. 8 9Cobertura 10''''''''' 11 12Using `Cobertura`_ as the coverage generation within your multi-module 13Java project can generate a series of XML files. 14 15The Cobertura Coverage parser expects to read the coverage data from a 16single XML file which contains the coverage data for all modules. 17Cobertura has a program with the ability to merge given ``cobertura.ser`` files 18and then another program to generate a combined XML file from the previous 19merged file. For command line testing, this can be done by hand prior to 20CTest looking for the coverage files. For script builds, 21set the ``CTEST_COVERAGE_COMMAND`` variable to point to a file which will 22perform these same steps, such as a ``.sh`` or ``.bat`` file. 23 24.. code-block:: cmake 25 26 set(CTEST_COVERAGE_COMMAND .../run-coverage-and-consolidate.sh) 27 28where the ``run-coverage-and-consolidate.sh`` script is perhaps created by 29the :command:`configure_file` command and might contain the following code: 30 31.. code-block:: bash 32 33 #!/usr/bin/env bash 34 CoberturaFiles="$(find "/path/to/source" -name "cobertura.ser")" 35 SourceDirs="$(find "/path/to/source" -name "java" -type d)" 36 cobertura-merge --datafile coberturamerge.ser $CoberturaFiles 37 cobertura-report --datafile coberturamerge.ser --destination . \ 38 --format xml $SourceDirs 39 40The script uses ``find`` to capture the paths to all of the ``cobertura.ser`` 41files found below the project's source directory. It keeps the list of files 42and supplies it as an argument to the ``cobertura-merge`` program. The 43``--datafile`` argument signifies where the result of the merge will be kept. 44 45The combined ``coberturamerge.ser`` file is then used to generate the XML report 46using the ``cobertura-report`` program. The call to the cobertura-report 47program requires some named arguments. 48 49``--datafila`` 50 path to the merged ``.ser`` file 51 52``--destination`` 53 path to put the output files(s) 54 55``--format`` 56 file format to write output in: xml or html 57 58The rest of the supplied arguments consist of the full paths to the 59``/src/main/java`` directories of each module within the source tree. These 60directories are needed and should not be forgotten. 61 62.. _`Cobertura`: http://cobertura.github.io/cobertura/ 63