AutoTest: Wizard: Add Support for Catch2

Done-with: Christian Stenger <christian.stenger@qt.io>
Change-Id: Idc59cf962e54845746a645efb5e931502deae38e
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Jochen Seemann
2019-05-09 19:36:49 +02:00
committed by Christian Stenger
parent ae3bb43dd1
commit 9f981e7e23
6 changed files with 139 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
#include <catch2/catch.hpp>
TEST_CASE("My first test with Catch2", "[fancy]")
{
REQUIRE(0 == 0);
}

View File

@@ -64,3 +64,30 @@ isEmpty(BOOST_INCLUDE_DIR): {
SOURCES += \\
%{MainCppName}
@endif
@if "%{TestFrameWork}" == "Catch2"
TEMPLATE = app
@if "%{Catch2NeedsQt}" == "true"
QT += gui
@else
CONFIG -= qt
CONFIG -= app_bundle
CONFIG += console
@endif
CONFIG += c++11
isEmpty(CATCH_INCLUDE_DIR): CATCH_INCLUDE_DIR=$$(CATCH_INCLUDE_DIR)
@if "%{CatchIncDir}" != ""
# set by Qt Creator wizard
isEmpty(CATCH_INCLUDE_DIR): CATCH_INCLUDE_DIR="%{CatchIncDir}"
@endif
!isEmpty(CATCH_INCLUDE_DIR): INCLUDEPATH *= $${CATCH_INCLUDE_DIR}
isEmpty(CATCH_INCLUDE_DIR): {
message("CATCH_INCLUDE_DIR is not set, assuming Catch2 can be found automatically in your system")
}
SOURCES += \
main.cpp \
%{TestCaseFileWithCppSuffix}
@endif

View File

@@ -7,6 +7,10 @@ import "googlecommon.js" as googleCommon
import qbs.Environment
import qbs.File
@endif
@if "%{TestFrameWork}" == "Catch2"
import qbs.Environment
import qbs.File
@endif
CppApplication {
@if "%{TestFrameWork}" == "QtTest"
@@ -104,4 +108,35 @@ CppApplication {
files: [ "%{MainCppName}" ]
@endif
@if "%{TestFrameWork}" == "Catch2"
type: "application"
@if "%{Catch2NeedsQt}" == "true"
Depends { name: "Qt.gui" }
@endif
property string catchIncDir: {
if (typeof Environment.getEnv("CATCH_INCLUDE_DIR") !== 'undefined')
return Environment.getEnv("CATCH_INCLUDE_DIR");
return "%{CatchIncDir}"; // set by Qt Creator wizard
}
Properties {
condition: catchIncDir && File.exists(catchIncDir)
cpp.includePaths: [catchIncDir];
}
condition: {
if (!catchIncDir)
console.log("CATCH_INCLUDE_DIR is not set, assuming Catch2 can be "
+ "found automatically in your system");
return true;
}
files: [
"%{MainCppName}",
"%{TestCaseFileWithCppSuffix}",
]
@endif
}

View File

@@ -116,3 +116,27 @@ elseif (EXISTS ${BOOST_INCLUDE_DIR})
include_directories(${BOOST_INCLUDE_DIR})
endif ()
@endif
@if "%{TestFrameWork}" == "Catch2"
SET(CMAKE_CXX_STANDARD 11)
@if "%{Catch2NeedsQt}" == "true"
find_package(Qt5Gui REQUIRED)
@endif
add_executable(${PROJECT_NAME} %{TestCaseFileWithCppSuffix} main.cpp)
@if "%{Catch2NeedsQt}" == "true"
target_link_libraries(%{TestCaseName} PRIVATE Qt5::Gui)
@endif
if (DEFINED ENV{CATCH_INCLUDE_DIR})
set(CATCH_INCLUDE_DIR $ENV{CATCH_INCLUDE_DIR})
else ()
set(CATCH_INCLUDE_DIR "%{CatchIncDir}") # set by Qt Creator wizard
endif ()
if (CATCH_INCLUDE_DIR STREQUAL "")
message("CATCH_INCLUDE_DIR is not set, assuming Catch2 can be found automatically in your system")
elseif (EXISTS ${CATCH_INCLUDE_DIR})
include_directories(${CATCH_INCLUDE_DIR})
endif ()
@endif

View File

@@ -24,3 +24,20 @@ BOOST_AUTO_TEST_CASE( %{TestCaseName} )
BOOST_TEST( true /* test assertion */ );
}
@endif
@if "%{TestFrameWork}" == "Catch2"
@if "%{Catch2NeedsQt}" == "true"
#define CATCH_CONFIG_RUNNER
@else
#define CATCH_CONFIG_MAIN
@endif
#include <catch2/catch.hpp>
@if "%{Catch2NeedsQt}" == "true"
#include <QtGui/QGuiApplication>
int main(int argc, char** argv)
{
QGuiApplication app(argc, argv);
return Catch::Session().run(argc, argv);
}
@endif
@endif

View File

@@ -91,6 +91,10 @@
{
"trKey": "Boost Test",
"value": "BoostTest"
},
{
"trKey": "Catch2",
"value": "Catch2"
}
]
@@ -167,6 +171,25 @@
"kind": "existingDirectory"
}
},
{
"name": "CatchIncDir",
"trDisplayName": "Catch2 include directory (optional):",
"visible": "%{JS: value('TestFrameWork') === 'Catch2'}",
"mandatory": false,
"type": "PathChooser",
"data": {
"kind": "existingDirectory"
}
},
{
"name": "Catch2NeedsQt",
"trDisplayName": "Use Qt libraries",
"visible": "%{JS: '%{TestFrameWork}' === 'Catch2'}",
"type": "CheckBox",
"data": {
"checked": true
}
},
{
"name": "BuildSystem",
"trDisplayName": "Build system:",
@@ -267,7 +290,7 @@
{
"source": "files/tst_main.cpp",
"target": "%{MainCppName}",
"condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest'].indexOf(value('TestFrameWork')) >= 0}",
"condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest', 'Catch2'].indexOf(value('TestFrameWork')) >= 0}",
"openInEditor": true
},
{
@@ -276,6 +299,12 @@
"condition": "%{JS: value('TestFrameWork') === 'QtQuickTest'}",
"openInEditor": true
},
{
"source": "files/catch2_tst.cpp",
"target": "%{TestCaseFileWithCppSuffix}",
"condition": "%{JS: '%{TestFrameWork}' === 'Catch2'}",
"openInEditor": true
},
{
"source": "../projects/git.ignore",
"target": ".gitignore",