AutoTest: Enhance wizard to support Qbs

Task-number: QTCREATORBUG-16916
Change-Id: I9f77dc2d4601ca8ff8db6847ee23d7f49e3bce81
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Stenger
2017-01-25 09:06:46 +01:00
parent f00e629227
commit ae98cd6f2b
7 changed files with 241 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
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

@@ -0,0 +1,64 @@
/*
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
**/
var FileInfo = loadExtension("qbs.FileInfo")
function getGTestDir(str) {
if (!str) {
if (qbs.hostOS.contains("linux"))
return "/usr/include/gtest";
} else {
return FileInfo.joinPaths(str, "googletest");
}
return "";
}
function getGMockDir(str) {
if (!str) {
if (qbs.hostOS.contains("linux"))
return "/usr/include/gmock";
} else {
return FileInfo.joinPaths(str, "googlemock");
}
return "";
}
function getGTestAll(str) {
var gtest = getGTestDir(str);
if (!gtest)
return [];
return [FileInfo.joinPaths(gtest, "src/gtest-all.cc")];
}
function getGMockAll(str) {
var gmock = getGMockDir(str);
if (!gmock)
return [];
return [FileInfo.joinPaths(gmock, "src/gmock-all.cc")];
}
function getGTestIncludes(str) {
var gtest = getGTestDir(str);
if (!gtest)
return [];
return [gtest, FileInfo.joinPaths(gtest, "include")];
}
function getGMockIncludes(str) {
var mock = getGMockDir(str);
if (!mock)
return [];
return [mock, FileInfo.joinPaths(mock, "include")];
}

View File

@@ -0,0 +1,27 @@
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

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

View File

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

View File

@@ -0,0 +1,35 @@
import qbs
@if "%{TestFrameWork}" == "GTest"
import "../googlecommon.js" as googleCommon
@endif
CppApplication {
@if "%{TestFrameWork}" == "QtTest"
Depends { name: "Qt.testlib" }
@if "%{RequireGUI}" == "false"
consoleApplication: true
@else
Depends { name: "Qt.gui" }
@endif
files: [
"%{TestCaseFileWithCppSuffix}"
]
@else
consoleApplication: true
@if "%{GTestCXX11}" == "true"
cpp.cxxLanguageVersion: "c++11"
cpp.defines: [ "GTEST_LANG_CXX11" ]
@endif
cpp.dynamicLibraries: [ "pthread" ]
cpp.includePaths: [].concat(googleCommon.getGTestIncludes(project.googletestDir))
.concat(googleCommon.getGMockIncludes(project.googletestDir))
files: [
"%{MainCppName}",
"%{TestCaseFileWithHeaderSuffix}",
].concat(googleCommon.getGTestAll(project.googletestDir))
.concat(googleCommon.getGMockAll(project.googletestDir))
@endif
}

View File

@@ -12,9 +12,16 @@
"options": "options":
[ [
{ "key": "ProjectFilePath",
"value": "%{JS: '%{BuildSystem}' == 'qmake' ? '%{ProFileName}' : '%{QbsFileName}' }"
},
{ "key": "ProFileName", { "key": "ProFileName",
"value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'pro')}" "value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'pro')}"
}, },
{
"key": "QbsFileName",
"value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'qbs')}"
},
{ "key": "IsTopLevelProject", { "key": "IsTopLevelProject",
"value": "%{JS: !'%{Exists:ProjectExplorer.Profile.Ids}' }" "value": "%{JS: !'%{Exists:ProjectExplorer.Profile.Ids}' }"
}, },
@@ -154,6 +161,27 @@
"data": { "data": {
"kind": "existingDirectory" "kind": "existingDirectory"
} }
},
{
"name": "BuildSystem",
"trDisplayName": "Build system:",
"type": "ComboBox",
"data":
{
"index": 0,
"items":
[
{
"trKey": "Qmake",
"value": "qmake"
},
{
"trKey": "Qbs",
"value": "qbs",
"condition": "%{JS: [ %{Plugins} ].indexOf('QbsProjectManager') >= 0}"
}
]
}
} }
] ]
}, },
@@ -162,7 +190,9 @@
"trShortTitle": "Kits", "trShortTitle": "Kits",
"typeId": "Kits", "typeId": "Kits",
"enabled": "%{IsTopLevelProject}", "enabled": "%{IsTopLevelProject}",
"data": { "projectFilePath": "%{ProFileName}" } "data": {
"projectFilePath": "%{ProjectFilePath}"
}
}, },
{ {
"trDisplayName": "Project Management", "trDisplayName": "Project Management",
@@ -179,11 +209,25 @@
{ {
"source": "files/tmp.pro", "source": "files/tmp.pro",
"target": "%{ProFileName}", "target": "%{ProFileName}",
"condition": "%{JS: '%{BuildSystem}' == 'qmake'}",
"openAsProject": true
},
{
"source": "files/tmp.qbs",
"target": "%{QbsFileName}",
"condition": "%{JS: '%{BuildSystem}' == 'qbs'}",
"openAsProject": true "openAsProject": true
}, },
{ {
"source": "files/src.pro", "source": "files/src.pro",
"target": "src/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 "openInEditor": false
}, },
{ {
@@ -194,22 +238,49 @@
{ {
"source": "files/tests.pro", "source": "files/tests.pro",
"target": "tests/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 "openInEditor": false
}, },
{ {
"source": "files/auto.pro", "source": "files/auto.pro",
"target": "tests/auto/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 "openInEditor": false
}, },
{ {
"source": "files/gtest_dependency.pri", "source": "files/gtest_dependency.pri",
"target": "tests/auto/gtest_dependency.pri", "target": "tests/auto/gtest_dependency.pri",
"condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", "condition": "%{JS: '%{TestFrameWork}' == 'GTest' && '%{BuildSystem}' == 'qmake'}",
"openInEditor": false
},
{
"source": "files/googlecommon.js",
"target": "tests/auto/googlecommon.js",
"condition": "%{JS: '%{TestFrameWork}' == 'GTest' && '%{BuildSystem}' == 'qbs'}",
"openInEditor": false "openInEditor": false
}, },
{ {
"source": "files/tst.pro", "source": "files/tst.pro",
"target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.pro' }", "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.pro' }",
"condition": "%{JS: '%{BuildSystem}' == 'qmake'}",
"openInEditor": false
},
{
"source": "files/tst.qbs",
"target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.qbs' }",
"condition": "%{JS: '%{BuildSystem}' == 'qbs'}",
"openInEditor": false "openInEditor": false
}, },
{ {