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 <tobias.hunger@qt.io>
This commit is contained in:
Christian Stenger
2017-03-17 09:15:49 +01:00
parent 16d2a10a1b
commit ae63f89f35
12 changed files with 33 additions and 226 deletions

View File

@@ -1,3 +0,0 @@
TEMPLATE = subdirs
SUBDIRS += %{JS: '%{TestCaseName}'.toLowerCase()}

View File

@@ -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"
]
}

View File

@@ -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 <iostream>
int main(int , char **)
{
std::cout << "Hello World!\\n";
return 0;
}
@endif

View File

@@ -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}

View File

@@ -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}"
]
}

View File

@@ -1,3 +0,0 @@
TEMPLATE = subdirs
SUBDIRS += auto

View File

@@ -1,8 +0,0 @@
import qbs
Project {
name: "%{ProjectName} tests"
references: [
"auto/auto.qbs"
]
}

View File

@@ -1,12 +0,0 @@
TEMPLATE = subdirs
@if "%{BuildAutoTests}" == "always"
SUBDIRS += src \
tests
@else
SUBDIRS += src
CONFIG(debug, debug|release) {
SUBDIRS += tests
}
@endif

View File

@@ -1,8 +0,0 @@
import qbs
Project {
references: [
"src/src.qbs",
"tests/tests.qbs"
]
}

View File

@@ -14,7 +14,7 @@ TEMPLATE = app
SOURCES += %{TestCaseFileWithCppSuffix}
@else
include(../gtest_dependency.pri)
include(gtest_dependency.pri)
TEMPLATE = app
@if "%{GTestCXX11}" == "true"

View File

@@ -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
}

View File

@@ -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
},