From 659780c31b8e0507e5feab675076984e225fe9b3 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Fri, 27 Feb 2026 11:21:05 -0600 Subject: [PATCH] Tests: Add QtTests run to CI --- .../runCPPTests/runAllTests/action.yml | 6 ++ .../actions/runCPPTests/runQtTests/action.yml | 55 ++++++++++++++++ .../runCPPTests/runSingleQtTest/action.yml | 62 +++++++++++++++++++ tests/CMakeLists.txt | 9 +++ 4 files changed, 132 insertions(+) create mode 100644 .github/workflows/actions/runCPPTests/runQtTests/action.yml create mode 100644 .github/workflows/actions/runCPPTests/runSingleQtTest/action.yml diff --git a/.github/workflows/actions/runCPPTests/runAllTests/action.yml b/.github/workflows/actions/runCPPTests/runAllTests/action.yml index 937b364e4a..28b26d50f4 100644 --- a/.github/workflows/actions/runCPPTests/runAllTests/action.yml +++ b/.github/workflows/actions/runCPPTests/runAllTests/action.yml @@ -68,6 +68,12 @@ runs: testCommand: ${{ inputs.builddir }}/tests/Gui_tests_run --gtest_output=json:${{ inputs.reportdir }}gui_gtest_results.json testLogFile: ${{ inputs.reportdir }}gui_gtest_test_log.txt testName: Gui + - name: C++ Qt tests + id: qttests + uses: ./.github/workflows/actions/runCPPTests/runQtTests + with: + builddir: ${{ inputs.builddir }} + testLogFile: ${{ inputs.reportdir }}qt_ctest_log.txt - name: C++ Material tests id: material uses: ./.github/workflows/actions/runCPPTests/runSingleTest diff --git a/.github/workflows/actions/runCPPTests/runQtTests/action.yml b/.github/workflows/actions/runCPPTests/runQtTests/action.yml new file mode 100644 index 0000000000..2bfa9b3df6 --- /dev/null +++ b/.github/workflows/actions/runCPPTests/runQtTests/action.yml @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileNotice: Part of the FreeCAD project. + +name: runQtTests +description: "Run all QtTest-based C++ tests (those labelled 'Qt' in CTest), generate log and report" + +inputs: + builddir: + description: "Build directory containing CTestTestfile.cmake" + required: true + testLogFile: + description: "Path for the command-line output of the tests" + required: true +outputs: + reportText: + description: "Report text" + value: ${{ steps.report.outputs.reportText }} + +runs: + using: "composite" + steps: + - name: Run Qt tests via CTest + shell: bash -l {0} + env: + BUILD_DIR: ${{ inputs.builddir }} + TEST_LOG_FILE: ${{ inputs.testLogFile }} + run: | + set -o pipefail + ctest --test-dir "$BUILD_DIR" -L Qt --output-on-failure | tee -a "$TEST_LOG_FILE" + - name: Parse test results + if: always() + id: report + shell: bash -l {0} + env: + TEST_LOG_FILE: ${{ inputs.testLogFile }} + run: | + result=$(grep -E "(Test #|tests passed|tests failed|Total Test time)" "$TEST_LOG_FILE" || true) + if grep -qE "[1-9][0-9]* tests failed" "$TEST_LOG_FILE" + then + reportText="
:fire: QtTest C++ tests failed\n" + else + reportText="
:heavy_check_mark: QtTest C++ tests succeeded\n" + fi + reportText+="\n" + reportText+="Results\n" + reportText+="\n" + reportText+='```\n' + reportText+="$result\n" + reportText+='```\n' + reportText+="
\n" + reportText+="\n" + echo "reportText<> $GITHUB_OUTPUT + echo -e "$reportText" >> $GITHUB_OUTPUT + echo "EOD" >> $GITHUB_OUTPUT + echo -e "$reportText" diff --git a/.github/workflows/actions/runCPPTests/runSingleQtTest/action.yml b/.github/workflows/actions/runCPPTests/runSingleQtTest/action.yml new file mode 100644 index 0000000000..46d5f4e656 --- /dev/null +++ b/.github/workflows/actions/runCPPTests/runSingleQtTest/action.yml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileNotice: Part of the FreeCAD project. + +name: runSingleQtTest +description: "Run a single QtTest-based C++ test executable, generate log and report" + +inputs: + testCommand: + description: "Test executable path" + required: true + testLogFile: + description: "Path for the command-line output of the tests" + required: true + testName: + description: "A descriptive name for the test suite" + required: true +outputs: + reportText: + description: "Report text" + value: ${{ steps.report.outputs.reportText }} + +runs: + using: "composite" + steps: + - name: Run QtTest tests + shell: bash -l {0} + env: + QT_QPA_PLATFORM: offscreen + TEST_COMMAND: ${{ inputs.testCommand }} + TEST_LOG_FILE: ${{ inputs.testLogFile }} + run: | + set -o pipefail + $TEST_COMMAND | tee -a "$TEST_LOG_FILE" + - name: Parse test results + if: always() + id: report + shell: bash -l {0} + env: + TEST_LOG_FILE: ${{ inputs.testLogFile }} + TEST_NAME: ${{ inputs.testName }} + run: | + # This bonkers sed regex is to try to find the start and end of the QtTest output block, which is not really + # designed to be machine-readable. Why did they have to choose asterisks?!?! + result=$(sed -n '/^\*\*\*\*\*\*\*\*\* Start/,/^\*\*\*\*\*\*\*\*\* Finished/p' "$TEST_LOG_FILE" || true) + if grep -qE "^FAIL!" "$TEST_LOG_FILE" + then + reportText="
:fire: QtTest C++ test suite '${TEST_NAME}' failed\n" + else + reportText="
:heavy_check_mark: QtTest C++ test suite '${TEST_NAME}' succeeded\n" + fi + reportText+="\n" + reportText+="Results\n" + reportText+="\n" + reportText+='```\n' + reportText+="$result\n" + reportText+='```\n' + reportText+="
\n" + reportText+="\n" + echo "reportText<> $GITHUB_OUTPUT + echo -e "$reportText" >> $GITHUB_OUTPUT + echo "EOD" >> $GITHUB_OUTPUT + echo -e "$reportText" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index da69d6f09c..6f1f158e9b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -77,6 +77,15 @@ function(setup_qt_test) FreeCADGui ${QtTest_LIBRARIES} ${${_testname}_LIBS}) + + if(NOT WIN32) + set_target_properties(${_testname}_Tests_run PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests) + endif() + + set_tests_properties(${_testname}_Tests_run PROPERTIES + LABELS "Qt" + ENVIRONMENT "QT_QPA_PLATFORM=offscreen") endforeach() endfunction()