2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2016-06-06 12:17:19 +02:00
|
|
|
#include "gtestconfiguration.h"
|
2022-07-13 18:31:56 +02:00
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
#include "gtestoutputreader.h"
|
2016-10-05 12:39:23 +02:00
|
|
|
#include "gtestsettings.h"
|
2017-09-01 14:59:39 +02:00
|
|
|
#include "../autotestplugin.h"
|
2020-03-26 10:11:39 +01:00
|
|
|
#include "../itestframework.h"
|
2017-09-01 14:59:39 +02:00
|
|
|
#include "../testsettings.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2020-06-17 06:35:31 +02:00
|
|
|
#include <utils/stringutils.h>
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2023-01-14 16:25:51 +01:00
|
|
|
TestOutputReader *GTestConfiguration::createOutputReader(const QFutureInterface<TestResult> &fi,
|
2023-01-13 12:13:45 +01:00
|
|
|
Utils::QtcProcess *app) const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2017-08-04 18:33:50 +02:00
|
|
|
return new GTestOutputReader(fi, app, buildDirectory(), projectFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-01 14:59:39 +02:00
|
|
|
QStringList filterInterfering(const QStringList &provided, QStringList *omitted)
|
|
|
|
|
{
|
|
|
|
|
static const QSet<QString> knownInterferingOptions { "--gtest_list_tests",
|
|
|
|
|
"--gtest_filter=",
|
|
|
|
|
"--gtest_also_run_disabled_tests",
|
|
|
|
|
"--gtest_repeat=",
|
|
|
|
|
"--gtest_shuffle",
|
|
|
|
|
"--gtest_random_seed=",
|
|
|
|
|
"--gtest_output=",
|
|
|
|
|
"--gtest_stream_result_to=",
|
|
|
|
|
"--gtest_break_on_failure",
|
|
|
|
|
"--gtest_throw_on_failure",
|
2021-11-04 22:33:48 +01:00
|
|
|
"--gtest_catch_exceptions=",
|
2018-09-28 08:32:04 +02:00
|
|
|
"--gtest_print_time="
|
2017-09-01 14:59:39 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-07 14:45:43 +01:00
|
|
|
QStringList allowed = Utils::filtered(provided, [](const QString &arg) {
|
|
|
|
|
return Utils::allOf(knownInterferingOptions, [&arg](const QString &interfering) {
|
2017-09-01 14:59:39 +02:00
|
|
|
return !arg.startsWith(interfering);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-07 22:50:51 +01:00
|
|
|
if (omitted && allowed.size() < provided.size()) {
|
2019-06-21 08:40:47 +02:00
|
|
|
QSet<QString> providedSet = Utils::toSet(provided);
|
2021-12-07 22:50:51 +01:00
|
|
|
providedSet.subtract(Utils::toSet(allowed));
|
2019-06-21 08:40:47 +02:00
|
|
|
omitted->append(Utils::toList(providedSet));
|
2017-09-01 14:59:39 +02:00
|
|
|
}
|
2021-12-07 22:50:51 +01:00
|
|
|
return allowed;
|
2017-09-01 14:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList GTestConfiguration::argumentsForTestRunner(QStringList *omitted) const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
2018-02-01 09:17:56 +01:00
|
|
|
if (AutotestPlugin::settings()->processArgs) {
|
2021-08-10 09:19:30 +02:00
|
|
|
arguments << filterInterfering(runnable().command.arguments().split(
|
2020-07-21 10:19:36 +02:00
|
|
|
' ', Qt::SkipEmptyParts), omitted);
|
2017-09-01 14:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
const QStringList &testSets = testCases();
|
2022-11-25 13:45:28 +01:00
|
|
|
if (!testSets.isEmpty()) {
|
|
|
|
|
if (isDebugRunMode()) // debugger does its own special quoting
|
|
|
|
|
arguments << "--gtest_filter=" + testSets.join(':');
|
|
|
|
|
else
|
|
|
|
|
arguments << "--gtest_filter=\"" + testSets.join(':') + '"';
|
|
|
|
|
}
|
2016-10-05 12:39:23 +02:00
|
|
|
|
2021-03-24 12:40:03 +01:00
|
|
|
auto gSettings = static_cast<GTestSettings *>(framework()->testSettings());
|
2020-03-12 13:58:09 +01:00
|
|
|
if (!gSettings)
|
2016-10-05 12:39:23 +02:00
|
|
|
return arguments;
|
|
|
|
|
|
2021-03-24 12:40:03 +01:00
|
|
|
if (gSettings->runDisabled.value())
|
2016-09-29 12:15:43 +02:00
|
|
|
arguments << "--gtest_also_run_disabled_tests";
|
2021-03-24 12:40:03 +01:00
|
|
|
if (gSettings->repeat.value())
|
|
|
|
|
arguments << QString("--gtest_repeat=%1").arg(gSettings->iterations.value());
|
|
|
|
|
if (gSettings->shuffle.value())
|
|
|
|
|
arguments << "--gtest_shuffle" << QString("--gtest_random_seed=%1").arg(gSettings->seed.value());
|
|
|
|
|
if (gSettings->throwOnFailure.value())
|
2016-08-12 09:06:52 +02:00
|
|
|
arguments << "--gtest_throw_on_failure";
|
|
|
|
|
|
2017-09-05 13:57:22 +02:00
|
|
|
if (isDebugRunMode()) {
|
2021-03-24 12:40:03 +01:00
|
|
|
if (gSettings->breakOnFailure.value())
|
2016-08-12 09:06:52 +02:00
|
|
|
arguments << "--gtest_break_on_failure";
|
2021-11-04 22:33:48 +01:00
|
|
|
arguments << "--gtest_catch_exceptions=0";
|
2016-08-12 09:06:52 +02:00
|
|
|
}
|
2016-05-11 13:02:42 +02:00
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 12:33:15 +02:00
|
|
|
Utils::Environment GTestConfiguration::filteredEnvironment(const Utils::Environment &original) const
|
|
|
|
|
{
|
2019-11-06 14:26:40 +01:00
|
|
|
const QStringList interfering{"GTEST_FILTER", "GTEST_ALSO_RUN_DISABLED_TESTS",
|
2018-08-29 12:33:15 +02:00
|
|
|
"GTEST_REPEAT", "GTEST_SHUFFLE", "GTEST_RANDOM_SEED",
|
|
|
|
|
"GTEST_OUTPUT", "GTEST_BREAK_ON_FAILURE", "GTEST_PRINT_TIME",
|
|
|
|
|
"GTEST_CATCH_EXCEPTIONS"};
|
|
|
|
|
Utils::Environment result = original;
|
2019-11-06 14:26:40 +01:00
|
|
|
if (!result.hasKey("GTEST_COLOR"))
|
|
|
|
|
result.set("GTEST_COLOR", "1"); // use colored output by default
|
2018-08-29 12:33:15 +02:00
|
|
|
for (const QString &key : interfering)
|
|
|
|
|
result.unset(key);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|