AutoTest: Tweak wizard a bit

Provide a version for creating Boost tests using the
shared library approach.
Add second variant for creating Boost tests.
The former version is the header only variant and can
not get extended with further cpp files without
modifying project files and the existing cpp file.

Task-number: QTCREATORBUG-28846
Change-Id: Ie7ecc339dcbe11804ce19bdba20e8db36b893a50
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-03-30 14:22:32 +02:00
parent 5b220e3a49
commit 0bb8cd2d68
6 changed files with 140 additions and 4 deletions

View File

@@ -70,6 +70,35 @@ isEmpty(BOOST_INCLUDE_DIR): {
SOURCES += \\
%{MainCppName}
@endif
@if "%{TestFrameWork}" == "BoostTest_dyn"
TEMPLATE = app
CONFIG -= qt
CONFIG -= app_bundle
CONFIG += console
isEmpty(BOOST_INSTALL_DIR): BOOST_INSTALL_DIR=$$(BOOST_INSTALL_DIR)
@if "%{BoostInstallDir}" != ""
# set by Qt Creator wizard
isEmpty(BOOST_INSTALL_DIR): BOOST_INSTALL_DIR="%{BoostInstallDir}"
@endif
!isEmpty(BOOST_INSTALL_DIR) {
win32: INCLUDEPATH *= $${BOOST_INSTALL_DIR}
else: INCLUDEPATH *= $${BOOST_INSTALL_DIR}/include
}
# Windows: adapt to name scheme, e.g. lib64-msvc-14.2
!isEmpty(BOOST_INSTALL_DIR): LIBS *= -L$${BOOST_INSTALL_DIR}/lib
# Windows: adapt to name scheme, e.g. boost_unit_test_framework-vc142-mt-gd-x64-1_80
LIBS *= -lboost_unit_test_framework
DEFINES *= BOOST_UNIT_TEST_FRAMEWORK_DYN_LINK
isEmpty(BOOST_INSTALL_DIR): {
message("BOOST_INSTALL_DIR is not set, assuming Boost can be found automatically in your system")
}
SOURCES += \\
%{MainCppName} \\
%{TestCaseFileWithCppSuffix}
@endif
@if "%{TestFrameWork}" == "Catch2"
TEMPLATE = app
@if "%{Catch2NeedsQt}" == "true"

View File

@@ -7,6 +7,11 @@ import "googlecommon.js" as googleCommon
import qbs.Environment
import qbs.File
@endif
@if "%{TestFrameWork}" == "BoostTest_dyn"
import qbs.Environment
import qbs.File
import qbs.FileInfo
@endif
@if "%{TestFrameWork}" == "Catch2"
import qbs.Environment
import qbs.File
@@ -116,6 +121,40 @@ CppApplication {
files: [ "%{MainCppName}" ]
@endif
@if "%{TestFrameWork}" == "BoostTest_dyn"
type: "application"
property string boostInstallDir: {
if (typeof Environment.getEnv("BOOST_INSTALL_DIR") !== 'undefined')
return Environment.getEnv("BOOST_INSTALL_DIR");
return "%{BoostInstallDir}"; // set by Qt Creator wizard
}
Properties {
condition: boostInstallDir && File.exists(boostInstallDir)
cpp.includePaths: base.concat([qbs.hostOS.contains("windows")
? boostInstallDir
: FileInfo.joinPaths(boostInstallDir, "include")])
// Windows: adapt to different directory layout, e.g. "lib64-msvc-14.2"
cpp.libraryPaths: base.concat([FileInfo.joinPaths(boostInstallDir, "lib")])
}
cpp.defines: base.concat("BOOST_UNIT_TEST_FRAMEWORK_DYN_LINK")
// Windows: adapt to name scheme, e.g. "boost_unit_test_framework-vc142-mt-gd-x64-1_80"
cpp.dynamicLibraries: ["boost_unit_test_framework"]
condition: {
if (!boostInstallDir)
console.log("BOOST_INSTALL_DIR is not set, assuming Boost can be "
+ "found automatically in your system");
return true;
}
files: [
"%{MainCppName}",
"%{TestCaseFileWithCppSuffix}",
]
@endif
@if "%{TestFrameWork}" == "Catch2"
type: "application"

View File

@@ -133,6 +133,33 @@ elseif (EXISTS ${BOOST_INCLUDE_DIR})
include_directories(${BOOST_INCLUDE_DIR})
endif ()
@endif
@if "%{TestFrameWork}" == "BoostTest_dyn"
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
if (DEFINED ENV{BOOST_INSTALL_DIR})
set(BOOST_INSTALL_DIR $ENV{BOOST_INSTALL_DIR})
else ()
set(BOOST_INSTALL_DIR "%{BoostInstallDir}") # set by Qt Creator wizard
endif ()
if (BOOST_INSTALL_DIR STREQUAL "")
message("BOOST_INSTALL_DIR not set, assuming Boost can be found automatically in your system")
elseif (EXISTS ${BOOST_INSTALL_DIR})
set(BOOST_ROOT ${BOOST_INSTALL_DIR})
endif ()
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(%{TestCaseName} %{MainCppName} %{TestCaseFileGTestWithCppSuffix})
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(%{TestCaseName} PUBLIC ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
endif ()
@endif
@if "%{TestFrameWork}" == "Catch2"
SET(CMAKE_CXX_STANDARD 11)

View File

@@ -21,13 +21,22 @@ int main(int argc, char *argv[])
}
@endif
@if "%{TestFrameWork}" == "BoostTest"
#define BOOST_TEST_MODULE %{TestSuiteName}
#define BOOST_TEST_MODULE My test module
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_SUITE( %{TestSuiteName} )
BOOST_AUTO_TEST_CASE( %{TestCaseName} )
{
BOOST_TEST( true /* test assertion */ );
}
BOOST_AUTO_TEST_SUITE_END()
@endif
@if "%{TestFrameWork}" == "BoostTest_dyn"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE My test module
#include <boost/test/unit_test.hpp>
@endif
@if "%{TestFrameWork}" == "Catch2"
@if "%{Catch2NeedsQt}" == "true"

View File

@@ -0,0 +1,13 @@
%{Cpp:LicenseTemplate}\
@if "%{TestFrameWork}" == "BoostTest_dyn"
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE( %{TestSuiteName} )
BOOST_AUTO_TEST_CASE( %{TestCaseName} )
{
BOOST_TEST( true /* test assertion */ );
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -90,9 +90,13 @@
"value": "QtQuickTest"
},
{
"trKey": "Boost Test",
"trKey": "Boost Test (header only)",
"value": "BoostTest"
},
{
"trKey": "Boost Test (shared libraries)",
"value": "BoostTest_dyn"
},
{
"trKey": "Catch2",
"value": "Catch2"
@@ -113,7 +117,7 @@
{
"name": "TestSuiteName",
"trDisplayName": "Test suite name:",
"visible": "%{JS: ['BoostTest', 'GTest'].indexOf(value('TestFrameWork')) >= 0}",
"visible": "%{JS: ['BoostTest', 'BoostTest_dyn', 'GTest'].indexOf(value('TestFrameWork')) >= 0}",
"mandatory": true,
"type": "LineEdit",
"data": { "validator": "^[a-zA-Z_0-9]+$" }
@@ -181,6 +185,16 @@
"kind": "existingDirectory"
}
},
{
"name": "BoostInstallDir",
"trDisplayName": "Boost install directory (optional):",
"visible": "%{JS: value('TestFrameWork') == 'BoostTest_dyn'}",
"mandatory": false,
"type": "PathChooser",
"data": {
"kind": "existingDirectory"
}
},
{
"name": "CatchIncDir",
"trDisplayName": "Catch2 include directory (optional):",
@@ -300,9 +314,14 @@
{
"source": "files/tst_main.cpp",
"target": "%{MainCppName}",
"condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest', 'Catch2'].indexOf(value('TestFrameWork')) >= 0}",
"condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest', 'BoostTest_dyn', 'Catch2'].indexOf(value('TestFrameWork')) >= 0}",
"openInEditor": true
},
{
"source": "files/tst_src_boost.cpp",
"target": "%{TestCaseFileWithCppSuffix}",
"condition": "%{JS: value('TestFrameWork') === 'BoostTest_dyn'}"
},
{
"source": "files/tst_qml.tmpl",
"target": "%{TestCaseFileWithQmlSuffix}",