forked from qt-creator/qt-creator
AutoTest: Fix generated files for gtest
When using gtest as test framework the wizard generated a header file containing the test code which had been included inside the main. As this works generally it is on the one hand not recommended and on the other hand it lets us fail when using cmake as build system. Create a cpp file instead and use this accordingly. Fixes: QTCREATORBUG-26253 Change-Id: Ibec8489258de0def27ee116eacbfc1bb22d3206b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -38,11 +38,9 @@ CONFIG -= app_bundle
|
||||
CONFIG += thread
|
||||
CONFIG -= qt
|
||||
|
||||
HEADERS += \\
|
||||
%{TestCaseFileWithHeaderSuffix}
|
||||
|
||||
SOURCES += \\
|
||||
%{MainCppName}
|
||||
%{MainCppName} \
|
||||
%{TestCaseFileGTestWithCppSuffix}
|
||||
@endif
|
||||
@if "%{TestFrameWork}" == "BoostTest"
|
||||
TEMPLATE = app
|
||||
|
@@ -60,7 +60,7 @@ CppApplication {
|
||||
|
||||
files: [
|
||||
"%{MainCppName}",
|
||||
"%{TestCaseFileWithHeaderSuffix}",
|
||||
"%{TestCaseFileGTestWithCppSuffix}",
|
||||
].concat(googleCommon.getGTestAll(qbs, googletestDir))
|
||||
.concat(googleCommon.getGMockAll(qbs, googletestDir))
|
||||
@endif
|
||||
|
@@ -57,6 +57,8 @@ target_link_libraries(%{TestCaseName} PRIVATE Qt${QT_VERSION_MAJOR}::QuickTest)
|
||||
@if "%{TestFrameWork}" == "GTest"
|
||||
|
||||
@if "%{GTestCXX11}" == "true"
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
add_definitions(-DGTEST_LANGUAGE_CXX11)
|
||||
@endif
|
||||
|
||||
@@ -92,7 +94,7 @@ endif ()
|
||||
|
||||
include_directories(${GTestIncludes})
|
||||
|
||||
add_executable(%{TestCaseName} %{MainCppName} %{TestCaseFileWithHeaderSuffix}
|
||||
add_executable(%{TestCaseName} %{MainCppName} %{TestCaseFileGTestWithCppSuffix}
|
||||
${GTestFiles})
|
||||
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})
|
||||
target_link_libraries(%{TestCaseName} PRIVATE Threads::Threads)
|
||||
|
@@ -5,7 +5,6 @@ QUICK_TEST_MAIN(example)
|
||||
@endif
|
||||
@if "%{TestFrameWork}" == "GTest"
|
||||
%{Cpp:LicenseTemplate}\
|
||||
#include "%{TestCaseFileWithHeaderSuffix}"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
@@ -1,10 +1,4 @@
|
||||
%{Cpp:LicenseTemplate}\
|
||||
@if '%{Cpp:PragmaOnce}'
|
||||
#pragma once
|
||||
@else
|
||||
#ifndef %{GUARD}
|
||||
#define %{GUARD}
|
||||
@endif
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
@@ -17,6 +11,3 @@ TEST(%{TestSuiteName}, %{TestCaseName})
|
||||
ASSERT_THAT(0, Eq(0));
|
||||
}
|
||||
|
||||
@if ! '%{Cpp:PragmaOnce}'
|
||||
#endif // %{GUARD}
|
||||
@endif
|
@@ -33,8 +33,8 @@
|
||||
"value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src') }"
|
||||
},
|
||||
{
|
||||
"key": "TestCaseFileWithHeaderSuffix",
|
||||
"value": "%{JS: 'tst_' + value('TestCaseName').toLowerCase() + '.' + Util.preferredSuffix('text/x-c++hdr') }"
|
||||
"key": "TestCaseFileGTestWithCppSuffix",
|
||||
"value": "%{JS: 'tst_' + value('TestCaseName').toLowerCase() + '.' + Util.preferredSuffix('text/x-c++src') }"
|
||||
},
|
||||
{
|
||||
"key": "GUARD",
|
||||
@@ -276,8 +276,8 @@
|
||||
"openAsProject": true
|
||||
},
|
||||
{
|
||||
"source": "files/tst_src.h",
|
||||
"target": "%{TestCaseFileWithHeaderSuffix}",
|
||||
"source": "files/tst_src_gt.cpp",
|
||||
"target": "%{TestCaseFileGTestWithCppSuffix}",
|
||||
"condition": "%{JS: value('TestFrameWork') == 'GTest'}",
|
||||
"openInEditor": true
|
||||
},
|
||||
|
Reference in New Issue
Block a user