Avoid polluting the source directory if qtprotobufgen test failed

Use a directory where the test binary is located to generate
the protobuf source files. This avoids polluting the source
directory if test exits with the critical error.

Change-Id: I288b5b3b84b243c28e9dd967e4411a7d4805d1bf
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Alexey Edelev 2022-12-06 15:59:51 +01:00 committed by Tatiana Borisova
parent 81d3e8eb8c
commit e040265d42
1 changed files with 5 additions and 7 deletions

View File

@ -172,17 +172,15 @@ void tst_qtprotobufgen::initTestCase()
m_protoFiles = QFINDTESTDATA("../shared/data/proto/"); m_protoFiles = QFINDTESTDATA("../shared/data/proto/");
QVERIFY(!m_protoFiles.isEmpty()); QVERIFY(!m_protoFiles.isEmpty());
QString dataPath = QFINDTESTDATA("data"); QDir testOutputBaseDir(QCoreApplication::applicationDirPath());
QVERIFY(!dataPath.isEmpty()); testOutputBaseDir.mkdir(QLatin1StringView("cmd_line_generation"));
QDir dataDir(dataPath);
dataDir.mkdir(QLatin1StringView("cmd_line_generation"));
QLatin1StringView folders[] = {"comments"_L1, "extra-namespace"_L1, QLatin1StringView folders[] = {"comments"_L1, "extra-namespace"_L1,
"fieldenum"_L1, "folder"_L1, "no-options"_L1}; "fieldenum"_L1, "folder"_L1, "no-options"_L1};
for (QLatin1StringView folder : folders) for (QLatin1StringView folder : folders)
dataDir.mkdir("cmd_line_generation/"_L1 + folder); testOutputBaseDir.mkdir("cmd_line_generation/"_L1 + folder);
m_commandLineGenerated = dataDir.absolutePath() + QLatin1StringView("/cmd_line_generation"); m_commandLineGenerated = testOutputBaseDir.absolutePath() +
QLatin1StringView("/cmd_line_generation");
QVERIFY(!m_commandLineGenerated.isEmpty()); QVERIFY(!m_commandLineGenerated.isEmpty());
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
if (!protocolCompilerAvailableToRun()) if (!protocolCompilerAvailableToRun())