From 1b5260b48cb3ea0db618905b22e6d9dbfa939c28 Mon Sep 17 00:00:00 2001 From: "Karsten A. M. Guenther" Date: Thu, 12 Oct 2023 14:54:49 +0200 Subject: [PATCH] feat: GCOVR output is a report, too --- cmake/common.cmake | 14 +++++++------- .../{{cookiecutter.name}}/test/test_unittests.py | 2 +- tests/test_integration.py | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index bd810df..0bba666 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -121,14 +121,15 @@ macro(spl_create_component) _spl_add_test_suite("${SOURCES}" ${TEST_SOURCES}) endif() - # Create component docs target if there is an index.rst file in the component doc directory set(_component_dir ${CMAKE_CURRENT_LIST_DIR}) set(_component_doc_dir ${_component_dir}/doc) set(_component_doc_file ${_component_doc_dir}/index.rst) set(_component_test_junit_xml ${CMAKE_CURRENT_BINARY_DIR}/junit.xml) - set(_component_test_coverage_html ${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html) + set(_component_reports_dir ${CMAKE_CURRENT_BINARY_DIR}/reports) + set(_component_coverage_html ${_component_reports_dir}/coverage/index.html) set(_autoconf_json_file ${AUTOCONF_JSON}) + # Create component docs target if there is an index.rst file in the component's doc directory if(EXISTS ${_component_doc_file}) # The Sphinx source directory is always the project root set(SPHINX_SOURCE_DIR ${PROJECT_SOURCE_DIR}) @@ -158,7 +159,7 @@ macro(spl_create_component) add_dependencies(docs ${component_name}_docs) if(TEST_SOURCES) - set(SPHINX_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/reports) + set(SPHINX_OUTPUT_DIR ${_component_reports_dir}) file(RELATIVE_PATH _rel_sphinx_output_dir ${SPHINX_SOURCE_DIR} ${SPHINX_OUTPUT_DIR}) set(SPHINX_OUTPUT_HTML_DIR ${SPHINX_OUTPUT_DIR}/html) set(SPHINX_OUTPUT_INDEX_HTML ${SPHINX_OUTPUT_HTML_DIR}/index.html) @@ -191,7 +192,7 @@ Unit Test Results :id: TEST_RESULT :file: {{ component_test_junit_xml }} -`Coverage report <{{ component_test_coverage_html }}>`_ +`Coverage report <{{ _component_coverage_html }}>`_ ") set(_component_doxyfile ${SPHINX_OUTPUT_DIR}/Doxyfile) @@ -212,7 +213,6 @@ Unit Test Results \"generated_rst_content\": \".. toctree::\\n :maxdepth: 2\\n\\n /${_rel_component_doc_dir}/index\\n /${_rel_unit_test_spec_rst}\\n /${_rel_unit_test_results_rst}\\n ${_rel_component_doxysphinx_index_rst}\", \"component_doc_dir\": \"${_rel_component_doc_dir}\", \"component_test_junit_xml\": \"${_component_test_junit_xml}\", - \"component_test_coverage_html\": \"${_component_test_coverage_html}\", \"include_patterns\": [\"${_rel_component_doc_dir}/**\",\"${_rel_sphinx_output_dir}/**\"] }") @@ -247,7 +247,7 @@ endmacro(_spl_set_coverage_create_overall_report_is_necessary) function(_spl_coverage_create_overall_report) if(_SPL_COVERAGE_CREATE_OVERALL_REPORT_IS_NECESSARY) - set(COV_OUT_VARIANT_HTML coverage/index.html) + set(COV_OUT_VARIANT_HTML reports/coverage/index.html) add_custom_command( OUTPUT ${COV_OUT_VARIANT_HTML} COMMAND gcovr --root ${CMAKE_SOURCE_DIR} --add-tracefile \"${CMAKE_CURRENT_BINARY_DIR}/**/coverage.json\" --html --html-details --output ${COV_OUT_VARIANT_HTML} @@ -314,7 +314,7 @@ macro(_spl_add_test_suite PROD_SRC TEST_SOURCES) DEPENDS ${TEST_OUT_JUNIT} ) - set(COV_OUT_HTML coverage/index.html) + set(COV_OUT_HTML reports/coverage/index.html) add_custom_command( OUTPUT ${COV_OUT_HTML} COMMAND gcovr --root ${CMAKE_SOURCE_DIR} --add-tracefile ${COV_OUT_JSON} --html --html-details --output ${COV_OUT_HTML} ${GCOVR_ADDITIONAL_OPTIONS} diff --git a/src/project_creator/templates/project/{{cookiecutter.name}}/test/test_unittests.py b/src/project_creator/templates/project/{{cookiecutter.name}}/test/test_unittests.py index 4935be0..651fe36 100644 --- a/src/project_creator/templates/project/{{cookiecutter.name}}/test/test_unittests.py +++ b/src/project_creator/templates/project/{{cookiecutter.name}}/test/test_unittests.py @@ -24,5 +24,5 @@ def build_unittests_and_expect_files(self, variant): self.assertEqual(0, exit_code) """Coverage report shall be created""" - expected_file = f"build/{variant}/test/coverage/index.html" + expected_file = f"build/{variant}/test/reports/coverage/index.html" self.assertTrue(os.path.isfile(expected_file), f"File {expected_file} shall exist.") diff --git a/tests/test_integration.py b/tests/test_integration.py index 939fabc..f96c1ca 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -82,6 +82,7 @@ def test_build_test(self): assert 0 == self.workspace.run_cmake_build(build_kit="test", target="unittests").returncode "Expected test results for kit test shall exist" + assert build_dir_test.joinpath("components/component/reports/coverage/index.html").exists() junitxml = build_dir_test.joinpath("components/component/junit.xml") assert junitxml.exists() testsuite = ET.parse(junitxml).getroot()