diff --git a/README.md b/README.md index 625ecbfd71b938eae7e375614a10752b25551083..bdd23ed0c1b4633ee60430b02bdae2c825b5fd0c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ Please visit the [official Parasoft website](http://www.parasoft.com) for more i - [Quick start](#quick-start-sa) - [Example Pipelines](#example-pipelines-sa) - [Reviewing Analysis Results](#reviewing-analysis-results-sa) +- [Unit Tests](#unit-tests) + - [Quick start](#quick-start-ut) + - [Example Pipelines](#example-pipelines-ut) + - [Reviewing Test Results](#reviewing-test-results-ut) - [Code Coverage](#code-coverage) - [Quick start](#quick-start-cc) - [Example Pipelines](#example-pipelines-cc) @@ -226,12 +230,166 @@ You can define a merge request policy for your integration branch that will bloc 1. In the **Policy details** section, define a rule for Static Application Security Testing (select “IF SAST…”). Configure additional options, if needed. +## Unit Tests +### Quick start +To collect test executions results for your code with Parasoft C/C++test and review test results in GitLab, you need to customize your pipeline to include a job that will: + - build your project with unit tests instrumentation enabled. + - execute the instrumented application. + - generate C/C++test unit tests reports. + - convert C/C++test unit tests report to xUnit format (using Saxon). + - upload the xUnit report. + +#### Prerequisites +* This extension requires Parasoft C/C++test 2020.2 (or newer) with a valid Parasoft license. +* We recommend that you execute the pipeline on a GitLab runner with the following components installed and configured on the runner: + - C/C++ build toolchain + - Parasoft C/C++test 2020.2 (or newer) + - On Windows, we recommend that you use PowerShell Core 6 or later. If you use Windows PowerShell 5.1, you must ensure the correct file encoding - see the example pipelines for details. + +* To support xUnit format, you need the following files to be accessible on a GitLab runner: + - Saxon-HE, which you can copy the folder from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). + - [XSLT file](xsl/cpptest-standard-xunit/xunit.xsl) for transforming C/C++test Standard unit tests report to xUnit report. + - [XSLT file](xsl/cpptest-professional-xunit/xunit.xsl) for transforming C/C++test Professional unit tests report to xUnit report. + +### Example Pipelines +The following examples show simple pipelines for Make and CMake-based projects. The examples assume that C/C++test is run on a GitLab runner and the path to the `cpptestcli` executable is available on `$PATH`. + + +##### Run C/C++test Standard with CMake project +For details on how to configure project for unit tests, see [Integrating with CppUnit and CppUtest](https://docs.parasoft.com/display/CPPTEST20232/Integrating+with+CppUnit+and+CppUtest). +See also the example [.gitlab-ci.yml](pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml) file. +```yaml +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a CMake-based project. + +# Be sure to configure variables below. +variables: + CMAKE_APP_NAME: "app-executable" + CPPTEST_UT_LOG_FILE: "path/to/cpptest-ut-log-file" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs unit tests with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + + stage: test + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Configures your CMake project. + - echo "Configuring project..." + - cmake -S . -B build + + # Builds your CMake project. + - echo "Building project" + - cmake --build build + + # Run the instrumented application to generate unit tests log file (.utlog). + - echo "Run the instrumented application" + - build/$CMAKE_APP_NAME + + # Generate unit tests report + - echo "Generating unit tests report" + - cpptestcli -config "builtin://Unit Testing" -input $CPPTEST_UT_LOG_FILE -report $CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` + +##### Run C/C++test Professional with Make project +For details on how to configure project for unit tests, see [Testing from the Command Line Interface](https://docs.parasoft.com/display/CPPTESTPROVS20232/Testing+from+the+Command+Line+Interface). +See also the example [.gitlab-ci.yml](pipelines/unit/cpptest-professional-make/.gitlab-ci.yml) file. + +```yaml +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + +stages: + - build + - test + +build-make: + stage: build + script: + # Builds your Make project using 'cpptesttrace' to collect input data for handle test executions results. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + artifacts: + # Archives cpptestscan.bdf so that it can be used in the 'test' stage. + paths: + - cpptestscan.bdf + +# Runs unit test with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + RESOURCE_PROJECT_FOLDER_NAME: "resource project folder name" + LOCALSETTINGS_FILE_PATH: "path/to/localsettings/properties/file" + + stage: test + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Launches C/C++test. + - echo "Running C/C++test..." + # Generate unit tests + - echo "Generate unit tests" + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + # Run unit tests + - echo "Run unit tests" + # Use the following command line when using cpptest professional prior to v2024.1 + # - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -report $CPPTEST_REPORTS_DIR + + # Use the following command line when using cpptest professional v2024.1 + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -property report.additional.report.dir=$CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` + +### Reviewing Test Results +When the pipeline completes, you can review the test results collected by C/C++test in the *Tests* tab of the GitLab pipeline. + + ## Code Coverage ### Quick start -To collect code coverage with Parasoft C/C++test Standard and review coverage results in GitLab, you need to: -* Integrate C/C++test with your C/C++ build to enable code coverage instrumentation. See also [Collecting Code Coverage](https://docs.parasoft.com/display/CPPTEST20231/Collecting+Code+Coverage). -* Customize your pipeline to include a job that will: +To collect code coverage with Parasoft C/C++test and review coverage results in GitLab, you need to customize your pipeline to include a job that will: - build your project with code coverage instrumentation enabled. - execute the instrumented application. - generate C/C++test coverage reports. @@ -239,14 +397,15 @@ To collect code coverage with Parasoft C/C++test Standard and review coverage re - upload the coverage reports. #### Prerequisites -* This extension requires Parasoft C/C++test Standard 2021.2 (or newer) with a valid Parasoft license. +* This extension requires Parasoft C/C++test 2020.2 (or newer) with a valid Parasoft license. * We recommend that you execute the pipeline on a GitLab runner with the following components installed and configured on the runner: - C/C++ build toolchain - - Parasoft C/C++test Standard 2021.2 (or newer) + - Parasoft C/C++test 2020.2 (or newer) - On Windows, we recommend that you use PowerShell Core 6 or later. If you use Windows PowerShell 5.1, you must ensure the correct file encoding - see the example pipelines for details. * To support Cobertura format, you need the following files to be accessible on a GitLab runner: - - Saxon-HE, which you can copy from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). - - [XSLT file](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/cpptest-standard-cobertura/cobertura.xsl) for transforming C/C++test coverage report to Cobertura report. + - Saxon-HE, which you can copy the folder from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). + - [XSLT file](xsl/cpptest-standard-cobertura/cobertura.xsl) for transforming C/C++test Standard coverage report to Cobertura report. + - [XSLT file](xsl/cpptest-professional-cobertura/cobertura.xsl) for transforming C/C++test Professional coverage report to Cobertura report. ### Example Pipelines ##### Run code coverage analysis with C/C++test Standard for CMake project @@ -322,6 +481,71 @@ cpptest-coverage: paths: - $CPPTEST_REPORTS_DIR/* ``` +##### Run code coverage analysis with C/C++test Professional for Make project +See also the example [.gitlab-ci.yml](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/pipelines/coverage/cpptest-professional-make/.gitlab-ci.yml) file. + +```yaml +# This is a basic pipeline to help you get started with C/C++test Professional integration to collect code coverage for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs code coverage analysis with C/C++test. +cpptest-coverage: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + + stage: test + + # See: https://docs.gitlab.com/ee/ci/testing/code_coverage.html#add-test-coverage-results-using-coverage-keyword + coverage: '/ lines \(\d+% covered\)/' + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Builds your Make project using 'cpptesttrace' to collect input data for code coverage analysis. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + + # Launches C/C++test. + - echo "Running C/C++test..." + - echo "Generating Unit Tests..." + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + - echo "Running Unit Tests..." + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -property report.additional.report.dir=$CPPTEST_REPORTS_DIR + + # Converts the coverage report to Cobertura format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + # + # When running on Windows, be sure to replace backslashes: + # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") + - echo "Generating Cobertura report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. + reports: + coverage_report: + coverage_format: cobertura + path: $CPPTEST_REPORTS_DIR/cobertura.xml + # Uploads all report files (.xml, .html) as build artifacts. + paths: + - $CPPTEST_REPORTS_DIR/* +``` ### Reviewing Analysis Results When the pipeline triggered by a merge request completes, you can review the code coverage data collected by C/C++test in the file diff view of the GitLab Merge requests. diff --git a/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml b/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..5ef07f6729a43b0ca852a4cec3464e3f9e53fa4f --- /dev/null +++ b/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml @@ -0,0 +1,60 @@ +# This is a basic pipeline to help you get started with C/C++test Professional integration to collect code coverage for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs code coverage analysis with C/C++test. +cpptest-coverage: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + + stage: test + + # See: https://docs.gitlab.com/ee/ci/testing/code_coverage.html#add-test-coverage-results-using-coverage-keyword + coverage: '/ lines \(\d+% covered\)/' + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Builds your Make project using 'cpptesttrace' to collect input data for code coverage analysis. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + + # Launches C/C++test. + - echo "Running C/C++test..." + - echo "Generating Unit Tests..." + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + - echo "Running Unit Tests..." + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -property report.additional.report.dir=$CPPTEST_REPORTS_DIR + + # Converts the coverage report to Cobertura format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + # + # When running on Windows, be sure to replace backslashes: + # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") + - echo "Generating Cobertura report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. + reports: + coverage_report: + coverage_format: cobertura + path: $CPPTEST_REPORTS_DIR/cobertura.xml + # Uploads all report files (.xml, .html) as build artifacts. + paths: + - $CPPTEST_REPORTS_DIR/* diff --git a/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml b/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..8a283fd122b96e1356036bcd4914436e673e7b45 --- /dev/null +++ b/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml @@ -0,0 +1,59 @@ +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + +stages: + - build + - test + +build-make: + stage: build + script: + # Builds your Make project using 'cpptesttrace' to collect input data for handle test executions results. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + artifacts: + # Archives cpptestscan.bdf so that it can be used in the 'test' stage. + paths: + - cpptestscan.bdf + +# Runs unit test with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + RESOURCE_PROJECT_FOLDER_NAME: "resource project folder name" + LOCALSETTINGS_FILE_PATH: "path/to/localsettings/properties/file" + + stage: test + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Launches C/C++test. + - echo "Running C/C++test..." + # Generate unit tests + - echo "Generate unit tests" + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + # Run unit tests + - echo "Run unit tests" + # Use the following command line when using cpptest professional prior to v2024.1 + # - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -report $CPPTEST_REPORTS_DIR + # Use the following command line when using cpptest professional v2024.1 + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -property report.additional.report.dir=$CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml \ No newline at end of file diff --git a/pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml b/pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..b431df68b246fb1ca1d686cf29fa62db9e1e95ff --- /dev/null +++ b/pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml @@ -0,0 +1,51 @@ +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a CMake-based project. + +# Be sure to configure variables below. +variables: + CMAKE_APP_NAME: "app-executable" + CPPTEST_UT_LOG_FILE: "path/to/cpptest-ut-log-file" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs unit tests with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + + stage: test + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Configures your CMake project. + - echo "Configuring project..." + - cmake -S . -B build + + # Builds your CMake project. + - echo "Building project" + - cmake --build build + + # Run the instrumented application to generate unit tests log file (.utlog). + - echo "Run the instrumented application" + - build/$CMAKE_APP_NAME + + # Generate unit tests report + - echo "Generating unit tests report" + - cpptestcli -config "builtin://Unit Testing" -input $CPPTEST_UT_LOG_FILE -report $CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml \ No newline at end of file diff --git a/xsl/cpptest-professional-cobertura/README.md b/xsl/cpptest-professional-cobertura/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b387a6013ad5e7ee9f9fcd6cd5ca27f6a5728f3b --- /dev/null +++ b/xsl/cpptest-professional-cobertura/README.md @@ -0,0 +1,29 @@ +# Generating a Cobertura report with C/C++test Professional + +To report Code Coverage results using Cobertura format: + +1. Copy the [`cobertura.xsl`](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/cpptest-professional-cobertura/cobertura.xsl) file into a local directory (``). +2. Copy [`Saxon`](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) files into a local directory (``). +3. Update your GitLab pipeline to convert `/coverage.xml` report into `/cobertura.xml`: + +```yaml + ... + # Converts the coverage report to Cobertura format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + # + # When running on Windows, be sure to replace backslashes: + # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") + - echo "Generating Cobertura report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + + artifacts: + # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. + reports: + coverage_report: + coverage_format: cobertura + path: $CPPTEST_REPORTS_DIR/cobertura.xml + ... +``` +4. Run your GitLab pipeline. diff --git a/xsl/cpptest-professional-cobertura/cobertura.xsl b/xsl/cpptest-professional-cobertura/cobertura.xsl new file mode 100644 index 0000000000000000000000000000000000000000..086b5f84452b374935c2418ea24c0810c429cb8f --- /dev/null +++ b/xsl/cpptest-professional-cobertura/cobertura.xsl @@ -0,0 +1,451 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xsl/cpptest-professional-xunit/README.md b/xsl/cpptest-professional-xunit/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4cc3a16c7f344f8a4f41d48836951f6c68590f3b --- /dev/null +++ b/xsl/cpptest-professional-xunit/README.md @@ -0,0 +1,23 @@ +# Generating a xUnit report with C/C++test Professional + +To report unit tests results using xUnit format: + +1. Copy the [`xunit.xsl`](xunit.xsl) file into a local directory (``). +2. Copy [`Saxon`](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) files into a local directory (``). +3. Update your GitLab pipeline to convert `/report.xml` report into `/report-xunit.xml`: + +```yaml + ... + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` +4. Run your GitLab pipeline. diff --git a/xsl/cpptest-professional-xunit/xunit.xsl b/xsl/cpptest-professional-xunit/xunit.xsl new file mode 100644 index 0000000000000000000000000000000000000000..50993c2f602711387187b3843e5bb192194dc355 --- /dev/null +++ b/xsl/cpptest-professional-xunit/xunit.xsl @@ -0,0 +1,590 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + Multiple errors reported + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + err + fail + pass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + . + + + / + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xsl/cpptest-standard-cobertura/README.md b/xsl/cpptest-standard-cobertura/README.md index c80314c16a9f6f5315ad76f37f4911851c694d7d..fc79db3342868346c0e88dabc3f818005da8d6a0 100644 --- a/xsl/cpptest-standard-cobertura/README.md +++ b/xsl/cpptest-standard-cobertura/README.md @@ -8,23 +8,22 @@ To report Code Coverage results using Cobertura format: ```yaml ... - # Converts a coverage report to Cobertura format. + # Converts the coverage report to Cobertura format. # # To use Saxon for report transformation, a Java executable is required. - # C/C++test includes Java which can be used for this purpose: - # /bin/jre/bin/java + # C/C++test includes Java which can be used for this purpose. # # When running on Windows, be sure to replace backslashes: # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") - echo "Generating Cobertura report..." - - java -jar "/saxon-he-12.2.jar" -xsl:"/cobertura.xsl" -s:"/coverage.xml" -o:"/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR artifacts: # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. reports: coverage_report: coverage_format: cobertura - path: /cobertura.xml + path: $CPPTEST_REPORTS_DIR/cobertura.xml ... ``` 4. Run your GitLab pipeline. diff --git a/xsl/cpptest-standard-cobertura/cobertura.xsl b/xsl/cpptest-standard-cobertura/cobertura.xsl index da2414aad9012218341ecf6071df8812abcfb33a..086b5f84452b374935c2418ea24c0810c429cb8f 100644 --- a/xsl/cpptest-standard-cobertura/cobertura.xsl +++ b/xsl/cpptest-standard-cobertura/cobertura.xsl @@ -1,362 +1,451 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xsl/cpptest-standard-xunit/README.md b/xsl/cpptest-standard-xunit/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1dd30127a46c426a8c3e3b52a675533d13086a71 --- /dev/null +++ b/xsl/cpptest-standard-xunit/README.md @@ -0,0 +1,23 @@ +# Generating a xUnit report with C/C++test Standard + +To report unit tests results using xUnit format: + +1. Copy the [`xunit.xsl`](xunit.xsl) file into a local directory (``). +2. Copy [`Saxon`](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) files into a local directory (``). +3. Update your GitLab pipeline to convert `/report.xml` report into `/report-xunit.xml`: + +```yaml + ... + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` +4. Run your GitLab pipeline. diff --git a/xsl/cpptest-standard-xunit/xunit.xsl b/xsl/cpptest-standard-xunit/xunit.xsl new file mode 100644 index 0000000000000000000000000000000000000000..50993c2f602711387187b3843e5bb192194dc355 --- /dev/null +++ b/xsl/cpptest-standard-xunit/xunit.xsl @@ -0,0 +1,590 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + Multiple errors reported + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + err + fail + pass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + . + + + / + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file