forked from qt-creator/qt-creator
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:
committed by
Christian Stenger
parent
ae3bb43dd1
commit
9f981e7e23
@@ -0,0 +1,6 @@
|
|||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
TEST_CASE("My first test with Catch2", "[fancy]")
|
||||||
|
{
|
||||||
|
REQUIRE(0 == 0);
|
||||||
|
}
|
@@ -64,3 +64,30 @@ isEmpty(BOOST_INCLUDE_DIR): {
|
|||||||
SOURCES += \\
|
SOURCES += \\
|
||||||
%{MainCppName}
|
%{MainCppName}
|
||||||
@endif
|
@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
|
||||||
|
@@ -7,6 +7,10 @@ import "googlecommon.js" as googleCommon
|
|||||||
import qbs.Environment
|
import qbs.Environment
|
||||||
import qbs.File
|
import qbs.File
|
||||||
@endif
|
@endif
|
||||||
|
@if "%{TestFrameWork}" == "Catch2"
|
||||||
|
import qbs.Environment
|
||||||
|
import qbs.File
|
||||||
|
@endif
|
||||||
|
|
||||||
CppApplication {
|
CppApplication {
|
||||||
@if "%{TestFrameWork}" == "QtTest"
|
@if "%{TestFrameWork}" == "QtTest"
|
||||||
@@ -104,4 +108,35 @@ CppApplication {
|
|||||||
files: [ "%{MainCppName}" ]
|
files: [ "%{MainCppName}" ]
|
||||||
|
|
||||||
@endif
|
@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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -116,3 +116,27 @@ elseif (EXISTS ${BOOST_INCLUDE_DIR})
|
|||||||
include_directories(${BOOST_INCLUDE_DIR})
|
include_directories(${BOOST_INCLUDE_DIR})
|
||||||
endif ()
|
endif ()
|
||||||
@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
|
||||||
|
@@ -24,3 +24,20 @@ BOOST_AUTO_TEST_CASE( %{TestCaseName} )
|
|||||||
BOOST_TEST( true /* test assertion */ );
|
BOOST_TEST( true /* test assertion */ );
|
||||||
}
|
}
|
||||||
@endif
|
@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
|
||||||
|
@@ -91,6 +91,10 @@
|
|||||||
{
|
{
|
||||||
"trKey": "Boost Test",
|
"trKey": "Boost Test",
|
||||||
"value": "BoostTest"
|
"value": "BoostTest"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"trKey": "Catch2",
|
||||||
|
"value": "Catch2"
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -167,6 +171,25 @@
|
|||||||
"kind": "existingDirectory"
|
"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",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
@@ -267,7 +290,7 @@
|
|||||||
{
|
{
|
||||||
"source": "files/tst_main.cpp",
|
"source": "files/tst_main.cpp",
|
||||||
"target": "%{MainCppName}",
|
"target": "%{MainCppName}",
|
||||||
"condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest'].indexOf(value('TestFrameWork')) >= 0}",
|
"condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest', 'Catch2'].indexOf(value('TestFrameWork')) >= 0}",
|
||||||
"openInEditor": true
|
"openInEditor": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -276,6 +299,12 @@
|
|||||||
"condition": "%{JS: value('TestFrameWork') === 'QtQuickTest'}",
|
"condition": "%{JS: value('TestFrameWork') === 'QtQuickTest'}",
|
||||||
"openInEditor": true
|
"openInEditor": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"source": "files/catch2_tst.cpp",
|
||||||
|
"target": "%{TestCaseFileWithCppSuffix}",
|
||||||
|
"condition": "%{JS: '%{TestFrameWork}' === 'Catch2'}",
|
||||||
|
"openInEditor": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"source": "../projects/git.ignore",
|
"source": "../projects/git.ignore",
|
||||||
"target": ".gitignore",
|
"target": ".gitignore",
|
||||||
|
Reference in New Issue
Block a user