forked from qt-creator/qt-creator
UnitTests: Setup an environment for every test run
So there are no old file an temporary file. Change-Id: Ida22703b5842b094f9a0f26562cd0908542e044f Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -36,13 +36,23 @@
|
|||||||
#include <benchmark/benchmark.h>
|
#include <benchmark/benchmark.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class Environment : public testing::Environment
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void SetUp() override
|
||||||
|
{
|
||||||
|
const QString temporayDirectoryPath = QDir::tempPath() + "/QtCreator-UnitTests-XXXXXX";
|
||||||
|
Utils::TemporaryDirectory::setMasterTemporaryDirectory(temporayDirectoryPath);
|
||||||
|
qputenv("TMPDIR", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
||||||
|
qputenv("TEMP", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override {}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Sqlite::Database::activateLogging();
|
Sqlite::Database::activateLogging();
|
||||||
const QString temporayDirectoryPath = QDir::tempPath() +"/QtCreator-UnitTests-XXXXXX";
|
|
||||||
Utils::TemporaryDirectory::setMasterTemporaryDirectory(temporayDirectoryPath);
|
|
||||||
qputenv("TMPDIR", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
|
||||||
qputenv("TEMP", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
|
||||||
|
|
||||||
QCoreApplication application(argc, argv);
|
QCoreApplication application(argc, argv);
|
||||||
|
|
||||||
@@ -51,6 +61,9 @@ int main(int argc, char *argv[])
|
|||||||
benchmark::Initialize(&argc, argv);
|
benchmark::Initialize(&argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Environment environment;
|
||||||
|
testing::AddGlobalTestEnvironment(&environment);
|
||||||
|
|
||||||
int testsHaveErrors = RUN_ALL_TESTS();
|
int testsHaveErrors = RUN_ALL_TESTS();
|
||||||
|
|
||||||
#ifdef WITH_BENCHMARKS
|
#ifdef WITH_BENCHMARKS
|
||||||
|
|||||||
Reference in New Issue
Block a user