aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2021-09-10 11:12:20 +0200
committerChristian Stenger <christian.stenger@qt.io>2021-09-13 08:54:48 +0000
commitf6f2ffde4e4c49834266210d8f9778660fca28f9 (patch)
tree8bc905f7c1261d9c2f79286b6b7c72d3e1f418e8
parent9d1cb4211abc54dc0eccafe5e41df8bbf9b95a3f (diff)
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>
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst.pro6
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst.qbs2
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst.txt4
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst_main.cpp1
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst_src_gt.cpp (renamed from share/qtcreator/templates/wizards/autotest/files/tst_src.h)9
-rw-r--r--share/qtcreator/templates/wizards/autotest/wizard.json8
6 files changed, 10 insertions, 20 deletions
diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.pro b/share/qtcreator/templates/wizards/autotest/files/tst.pro
index a92e58f06eb..87e6159c462 100644
--- a/share/qtcreator/templates/wizards/autotest/files/tst.pro
+++ b/share/qtcreator/templates/wizards/autotest/files/tst.pro
@@ -38,11 +38,9 @@ CONFIG -= app_bundle
CONFIG += thread
CONFIG -= qt
-HEADERS += \\
- %{TestCaseFileWithHeaderSuffix}
-
SOURCES += \\
- %{MainCppName}
+ %{MainCppName} \
+ %{TestCaseFileGTestWithCppSuffix}
@endif
@if "%{TestFrameWork}" == "BoostTest"
TEMPLATE = app
diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.qbs b/share/qtcreator/templates/wizards/autotest/files/tst.qbs
index a33cecd5990..26876461540 100644
--- a/share/qtcreator/templates/wizards/autotest/files/tst.qbs
+++ b/share/qtcreator/templates/wizards/autotest/files/tst.qbs
@@ -60,7 +60,7 @@ CppApplication {
files: [
"%{MainCppName}",
- "%{TestCaseFileWithHeaderSuffix}",
+ "%{TestCaseFileGTestWithCppSuffix}",
].concat(googleCommon.getGTestAll(qbs, googletestDir))
.concat(googleCommon.getGMockAll(qbs, googletestDir))
@endif
diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.txt b/share/qtcreator/templates/wizards/autotest/files/tst.txt
index fe8e30e789d..516567cc633 100644
--- a/share/qtcreator/templates/wizards/autotest/files/tst.txt
+++ b/share/qtcreator/templates/wizards/autotest/files/tst.txt
@@ -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)
diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp
index e4f33d27164..2d12cccea15 100644
--- a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp
+++ b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp
@@ -5,7 +5,6 @@ QUICK_TEST_MAIN(example)
@endif
@if "%{TestFrameWork}" == "GTest"
%{Cpp:LicenseTemplate}\
-#include "%{TestCaseFileWithHeaderSuffix}"
#include <gtest/gtest.h>
diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_src.h b/share/qtcreator/templates/wizards/autotest/files/tst_src_gt.cpp
index ef29240cd5e..749ff06f0ac 100644
--- a/share/qtcreator/templates/wizards/autotest/files/tst_src.h
+++ b/share/qtcreator/templates/wizards/autotest/files/tst_src_gt.cpp
@@ -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
diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json
index 1ba0101a092..8f32cec145c 100644
--- a/share/qtcreator/templates/wizards/autotest/wizard.json
+++ b/share/qtcreator/templates/wizards/autotest/wizard.json
@@ -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
},