diff options
author | Christian Stenger <christian.stenger@qt.io> | 2017-01-25 09:06:46 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2017-01-26 13:51:38 +0000 |
commit | ae98cd6f2ba918368a76dfdf1724a13f8662bf1d (patch) | |
tree | 07c74970f4c37bd934dcfb20e3888b3c6b39979c | |
parent | f00e6292278098be00b17e10cff99aa56061948d (diff) |
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>
7 files changed, 241 insertions, 2 deletions
diff --git a/share/qtcreator/templates/wizards/autotest/files/auto.qbs b/share/qtcreator/templates/wizards/autotest/files/auto.qbs new file mode 100644 index 00000000000..319bfbd1d46 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/auto.qbs @@ -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" + ] +} diff --git a/share/qtcreator/templates/wizards/autotest/files/googlecommon.js b/share/qtcreator/templates/wizards/autotest/files/googlecommon.js new file mode 100644 index 00000000000..1799b1c242c --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/googlecommon.js @@ -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")]; +} diff --git a/share/qtcreator/templates/wizards/autotest/files/src.qbs b/share/qtcreator/templates/wizards/autotest/files/src.qbs new file mode 100644 index 00000000000..36e44e774b3 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/src.qbs @@ -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}" + ] +} diff --git a/share/qtcreator/templates/wizards/autotest/files/tests.qbs b/share/qtcreator/templates/wizards/autotest/files/tests.qbs new file mode 100644 index 00000000000..6a83cf65ef1 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tests.qbs @@ -0,0 +1,8 @@ +import qbs + +Project { + name: "%{ProjectName} tests" + references: [ + "auto/auto.qbs" + ] +} diff --git a/share/qtcreator/templates/wizards/autotest/files/tmp.qbs b/share/qtcreator/templates/wizards/autotest/files/tmp.qbs new file mode 100644 index 00000000000..dfc99c15df3 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tmp.qbs @@ -0,0 +1,8 @@ +import qbs + +Project { + references: [ + "src/src.qbs", + "tests/tests.qbs" + ] +} diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.qbs b/share/qtcreator/templates/wizards/autotest/files/tst.qbs new file mode 100644 index 00000000000..1000451bc63 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tst.qbs @@ -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 +} diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json index 80b97883796..83763225c07 100644 --- a/share/qtcreator/templates/wizards/autotest/wizard.json +++ b/share/qtcreator/templates/wizards/autotest/wizard.json @@ -12,9 +12,16 @@ "options": [ + { "key": "ProjectFilePath", + "value": "%{JS: '%{BuildSystem}' == 'qmake' ? '%{ProFileName}' : '%{QbsFileName}' }" + }, { "key": "ProFileName", "value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'pro')}" }, + { + "key": "QbsFileName", + "value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'qbs')}" + }, { "key": "IsTopLevelProject", "value": "%{JS: !'%{Exists:ProjectExplorer.Profile.Ids}' }" }, @@ -154,6 +161,27 @@ "data": { "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", "typeId": "Kits", "enabled": "%{IsTopLevelProject}", - "data": { "projectFilePath": "%{ProFileName}" } + "data": { + "projectFilePath": "%{ProjectFilePath}" + } }, { "trDisplayName": "Project Management", @@ -179,11 +209,25 @@ { "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 }, { @@ -194,22 +238,49 @@ { "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", - "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 }, { "source": "files/tst.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 }, { |