From ae63f89f35246927c1805e67f53e507fe982d2ee Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 17 Mar 2017 09:15:49 +0100 Subject: [PATCH] AutoTest: Reduce auto test wizard to useful parts This patch reduces the former wizard to the test project part. The wizard appeared more or less useless as there was no easy way to add test cases later on and you normally do not need to have the full skeleton of the project including a test sub project - except when starting a TDD project. Change-Id: I404d843b29f058876ea9696b7881f2e5e11b6af2 Reviewed-by: Tobias Hunger --- .../templates/wizards/autotest/files/auto.pro | 3 - .../templates/wizards/autotest/files/auto.qbs | 26 ----- .../templates/wizards/autotest/files/main.cpp | 31 ------ .../templates/wizards/autotest/files/src.pro | 18 ---- .../templates/wizards/autotest/files/src.qbs | 27 ------ .../wizards/autotest/files/tests.pro | 3 - .../wizards/autotest/files/tests.qbs | 8 -- .../templates/wizards/autotest/files/tmp.pro | 12 --- .../templates/wizards/autotest/files/tmp.qbs | 8 -- .../templates/wizards/autotest/files/tst.pro | 2 +- .../templates/wizards/autotest/files/tst.qbs | 24 ++++- .../templates/wizards/autotest/wizard.json | 97 +++---------------- 12 files changed, 33 insertions(+), 226 deletions(-) delete mode 100644 share/qtcreator/templates/wizards/autotest/files/auto.pro delete mode 100644 share/qtcreator/templates/wizards/autotest/files/auto.qbs delete mode 100644 share/qtcreator/templates/wizards/autotest/files/main.cpp delete mode 100644 share/qtcreator/templates/wizards/autotest/files/src.pro delete mode 100644 share/qtcreator/templates/wizards/autotest/files/src.qbs delete mode 100644 share/qtcreator/templates/wizards/autotest/files/tests.pro delete mode 100644 share/qtcreator/templates/wizards/autotest/files/tests.qbs delete mode 100644 share/qtcreator/templates/wizards/autotest/files/tmp.pro delete mode 100644 share/qtcreator/templates/wizards/autotest/files/tmp.qbs diff --git a/share/qtcreator/templates/wizards/autotest/files/auto.pro b/share/qtcreator/templates/wizards/autotest/files/auto.pro deleted file mode 100644 index 510a3710068..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/auto.pro +++ /dev/null @@ -1,3 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += %{JS: '%{TestCaseName}'.toLowerCase()} diff --git a/share/qtcreator/templates/wizards/autotest/files/auto.qbs b/share/qtcreator/templates/wizards/autotest/files/auto.qbs deleted file mode 100644 index 319bfbd1d46..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/auto.qbs +++ /dev/null @@ -1,26 +0,0 @@ -import qbs -@if "%{TestFrameWork}" == "GTest" -import qbs.Environment -@endif - -Project { - name: "auto tests" - -@if "%{TestFrameWork}" == "GTest" - property string googletestDir: { - if (typeof Environment.getEnv("GOOGLETEST_DIR") === 'undefined') { - console.warn("Using googletest src dir specified at Qt Creator wizard") - console.log("set GOOGLETEST_DIR as environment variable or Qbs property to get rid of this message") - return "%{GTestRepository}" - } else { - return Environment.getEnv("GOOGLETEST_DIR") - } - } -@endif -@if "%{BuildAutoTests}" == "debug" - condition: qbs.buildVariant === "debug" -@endif - references: [ - "%{JS: '%{TestCaseName}'.toLowerCase()}/%{JS: '%{TestCaseName}'.toLowerCase()}.qbs" - ] -} diff --git a/share/qtcreator/templates/wizards/autotest/files/main.cpp b/share/qtcreator/templates/wizards/autotest/files/main.cpp deleted file mode 100644 index 8a4a5671fc3..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/main.cpp +++ /dev/null @@ -1,31 +0,0 @@ -%{Cpp:LicenseTemplate}\ -@if "%{TestFrameWork}" == "QtTest" -@if "%{RequireGUI}" == "true" -%{JS: QtSupport.qtIncludes([ 'QtGui/QApplication' ], - [ 'QtWidgets/QApplication' ]) }\ -@else -%{JS: QtSupport.qtIncludes([ 'QtCore/QCoreApplication' ], - [ 'QtCore/QCoreApplication' ]) }\ -@endif -// add necessary includes here - -int main(int argc, char *argv[]) -{ -@if "%{RequireGUI}" == "true" - QApplication a(argc, argv); -@else - QCoreApplication a(argc, argv); -@endif - - return a.exec(); -} -@else -#include - -int main(int , char **) -{ - std::cout << "Hello World!\\n"; - - return 0; -} -@endif diff --git a/share/qtcreator/templates/wizards/autotest/files/src.pro b/share/qtcreator/templates/wizards/autotest/files/src.pro deleted file mode 100644 index 8d664760666..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/src.pro +++ /dev/null @@ -1,18 +0,0 @@ -@if "%{TestFrameWork}" == "QtTest" -@if "%{RequireGUI}" == "true" -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -@else -QT -= gui -@endif -@else -CONFIG -= qt -@endif -CONFIG += console c++11 -CONFIG -= app_bundle - -TEMPLATE = app - -TARGET = %{ProjectName} - -SOURCES += %{MainCppName} diff --git a/share/qtcreator/templates/wizards/autotest/files/src.qbs b/share/qtcreator/templates/wizards/autotest/files/src.qbs deleted file mode 100644 index 36e44e774b3..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/src.qbs +++ /dev/null @@ -1,27 +0,0 @@ -import qbs - -CppApplication { - type: "application" - consoleApplication: true - name: "%{ProjectName}" -@if "%{TestFrameWork}" == "QtTest" -@if "%{RequireGUI}" == "true" - - Depends { name: "Qt.core" } - Depends { name: "Qt.gui" } - Depends { - name: "Qt.widgets" - condition: Qt.core.versionMajor > 4 - } -@else - - Depends { name: "Qt.core" } -@endif -@endif - - cpp.cxxLanguageVersion: "c++11" - - files: [ - "%{MainCppName}" - ] -} diff --git a/share/qtcreator/templates/wizards/autotest/files/tests.pro b/share/qtcreator/templates/wizards/autotest/files/tests.pro deleted file mode 100644 index f9277000081..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/tests.pro +++ /dev/null @@ -1,3 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += auto diff --git a/share/qtcreator/templates/wizards/autotest/files/tests.qbs b/share/qtcreator/templates/wizards/autotest/files/tests.qbs deleted file mode 100644 index 6a83cf65ef1..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/tests.qbs +++ /dev/null @@ -1,8 +0,0 @@ -import qbs - -Project { - name: "%{ProjectName} tests" - references: [ - "auto/auto.qbs" - ] -} diff --git a/share/qtcreator/templates/wizards/autotest/files/tmp.pro b/share/qtcreator/templates/wizards/autotest/files/tmp.pro deleted file mode 100644 index 4832797c026..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/tmp.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = subdirs - -@if "%{BuildAutoTests}" == "always" -SUBDIRS += src \ - tests -@else -SUBDIRS += src - -CONFIG(debug, debug|release) { - SUBDIRS += tests -} -@endif diff --git a/share/qtcreator/templates/wizards/autotest/files/tmp.qbs b/share/qtcreator/templates/wizards/autotest/files/tmp.qbs deleted file mode 100644 index dfc99c15df3..00000000000 --- a/share/qtcreator/templates/wizards/autotest/files/tmp.qbs +++ /dev/null @@ -1,8 +0,0 @@ -import qbs - -Project { - references: [ - "src/src.qbs", - "tests/tests.qbs" - ] -} diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.pro b/share/qtcreator/templates/wizards/autotest/files/tst.pro index 5f0f7455f47..695f0f7ffd2 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.pro +++ b/share/qtcreator/templates/wizards/autotest/files/tst.pro @@ -14,7 +14,7 @@ TEMPLATE = app SOURCES += %{TestCaseFileWithCppSuffix} @else -include(../gtest_dependency.pri) +include(gtest_dependency.pri) TEMPLATE = app @if "%{GTestCXX11}" == "true" diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.qbs b/share/qtcreator/templates/wizards/autotest/files/tst.qbs index 1000451bc63..58a647df861 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.qbs +++ b/share/qtcreator/templates/wizards/autotest/files/tst.qbs @@ -1,6 +1,7 @@ import qbs @if "%{TestFrameWork}" == "GTest" -import "../googlecommon.js" as googleCommon +import qbs.Environment +import "googlecommon.js" as googleCommon @endif CppApplication { @@ -16,6 +17,19 @@ CppApplication { ] @else consoleApplication: true + +@if "%{TestFrameWork}" == "GTest" + property string googletestDir: { + if (typeof Environment.getEnv("GOOGLETEST_DIR") === 'undefined') { + console.warn("Using googletest src dir specified at Qt Creator wizard") + console.log("set GOOGLETEST_DIR as environment variable or Qbs property to get rid of this message") + return "%{GTestRepository}" + } else { + return Environment.getEnv("GOOGLETEST_DIR") + } + } +@endif + @if "%{GTestCXX11}" == "true" cpp.cxxLanguageVersion: "c++11" cpp.defines: [ "GTEST_LANG_CXX11" ] @@ -23,13 +37,13 @@ CppApplication { cpp.dynamicLibraries: [ "pthread" ] - cpp.includePaths: [].concat(googleCommon.getGTestIncludes(project.googletestDir)) - .concat(googleCommon.getGMockIncludes(project.googletestDir)) + cpp.includePaths: [].concat(googleCommon.getGTestIncludes(googletestDir)) + .concat(googleCommon.getGMockIncludes(googletestDir)) files: [ "%{MainCppName}", "%{TestCaseFileWithHeaderSuffix}", - ].concat(googleCommon.getGTestAll(project.googletestDir)) - .concat(googleCommon.getGMockAll(project.googletestDir)) + ].concat(googleCommon.getGTestAll(googletestDir)) + .concat(googleCommon.getGMockAll(googletestDir)) @endif } diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json index 1f0d9cf5b5b..f1490a1dc9a 100644 --- a/share/qtcreator/templates/wizards/autotest/wizard.json +++ b/share/qtcreator/templates/wizards/autotest/wizard.json @@ -3,7 +3,7 @@ "supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ], "id": "R.AutoTest", "category": "H.Project", - "trDescription": "Creates a new project including an auto test skeleton.", + "trDescription": "Creates a new unit test project. Unit tests allow you to verify that the code is fit for use and that there are no regressions.", "trDisplayName": "Auto Test Project", "trDisplayCategory": "Other Project", "icon": "autotest_24.png", @@ -46,7 +46,7 @@ "typeId": "Project", "data": { - "trDescription": "This wizard creates a simple project with an additional auto test skeleton." + "trDescription": "This wizard creates a simple unit test project." } }, { @@ -133,26 +133,6 @@ "uncheckedValue": "false" } }, - { - "name": "BuildAutoTests", - "trDisplayName": "Build auto tests", - "type": "ComboBox", - "data": - { - "index": 0, - "items": - [ - { - "trKey": "always", - "value": "always" - }, - { - "trKey": "debug only", - "value": "debug" - } - ] - } - }, { "name": "GTestRepository", "trDisplayName": "Googletest repository:", @@ -206,98 +186,47 @@ "typeId": "File", "data": [ - { - "source": "files/tmp.pro", - "target": "%{ProFileName}", - "condition": "%{JS: '%{BuildSystem}' == 'qmake'}", - "openAsProject": true - }, - { - "source": "files/tmp.qbs", - "target": "%{QbsFileName}", - "condition": "%{JS: '%{BuildSystem}' == 'qbs'}", - "openAsProject": true - }, - { - "source": "files/src.pro", - "target": "src/src.pro", - "condition": "%{JS: '%{BuildSystem}' == 'qmake'}", - "openInEditor": false - }, - { - "source": "files/src.qbs", - "target": "src/src.qbs", - "condition": "%{JS: '%{BuildSystem}' == 'qbs'}", - "openInEditor": false - }, - { - "source": "files/main.cpp", - "target": "src/%{MainCppName}", - "openInEditor": true - }, - { - "source": "files/tests.pro", - "target": "tests/tests.pro", - "condition": "%{JS: '%{BuildSystem}' == 'qmake'}", - "openInEditor": false - }, - { - "source": "files/tests.qbs", - "target": "tests/tests.qbs", - "condition": "%{JS: '%{BuildSystem}' == 'qbs'}", - "openInEditor": false - }, - { - "source": "files/auto.pro", - "target": "tests/auto/auto.pro", - "condition": "%{JS: '%{BuildSystem}' == 'qmake'}", - "openInEditor": false - }, - { - "source": "files/auto.qbs", - "target": "tests/auto/auto.qbs", - "condition": "%{JS: '%{BuildSystem}' == 'qbs'}", - "openInEditor": false - }, { "source": "files/gtest_dependency.pri", - "target": "tests/auto/gtest_dependency.pri", + "target": "gtest_dependency.pri", "condition": "%{JS: '%{TestFrameWork}' == 'GTest' && '%{BuildSystem}' == 'qmake'}", "openInEditor": false }, { "source": "files/googlecommon.js", - "target": "tests/auto/googlecommon.js", + "target": "googlecommon.js", "condition": "%{JS: '%{TestFrameWork}' == 'GTest' && '%{BuildSystem}' == 'qbs'}", "openInEditor": false }, { "source": "files/tst.pro", - "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.pro' }", + "target": "%{ProjectFilePath}", "condition": "%{JS: '%{BuildSystem}' == 'qmake'}", - "openInEditor": false + "openInEditor": false, + "openAsProject": true }, { "source": "files/tst.qbs", - "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.qbs' }", + "target": "%{ProjectFilePath}", "condition": "%{JS: '%{BuildSystem}' == 'qbs'}", - "openInEditor": false + "openInEditor": false, + "openAsProject": true }, { "source": "files/tst_src.h", - "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/'.toLowerCase() + '%{TestCaseFileWithHeaderSuffix}' }", + "target": "%{TestCaseFileWithHeaderSuffix}", "condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", "openInEditor": true }, { "source": "files/tst_src.cpp", - "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/'.toLowerCase() + '%{TestCaseFileWithCppSuffix}' }", + "target": "%{TestCaseFileWithCppSuffix}", "condition": "%{JS: '%{TestFrameWork}' == 'QtTest'}", "openInEditor": true }, { "source": "files/tst_main.cpp", - "target": "%{JS: 'tests/auto/' + '%{TestCaseName}'.toLowerCase() + '/%{MainCppName}' }", + "target": "%{MainCppName}", "condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", "openInEditor": true },