| 20 | |
| 21 | namespace { |
| 22 | ReplacementsParserTester::TestFilePaths prepareTestFiles(const char* relativeSourceFilePath, |
| 23 | QObject* temporaryFileParent) |
| 24 | { |
| 25 | QFile sourceYamlFile(QFINDTESTDATA(QString::fromUtf8(relativeSourceFilePath) + ".yaml")); |
| 26 | QVERIFY_RETURN(sourceYamlFile.open(QIODevice::ReadOnly), {}); |
| 27 | auto fileContents = sourceYamlFile.readAll(); |
| 28 | sourceYamlFile.close(); |
| 29 | |
| 30 | auto* const yamlFile = |
| 31 | new QTemporaryFile(QDir::tempPath() + "/kdevclangtidy_test_XXXXXX.yaml", temporaryFileParent); |
| 32 | QVERIFY_RETURN(yamlFile->open(), {}); |
| 33 | |
| 34 | ReplacementsParserTester::TestFilePaths filePaths{yamlFile->fileName(), QFINDTESTDATA(relativeSourceFilePath)}; |
| 35 | |
| 36 | // Make the file path in the yaml file match the source file path in order to prevent |
| 37 | // ReplacementParser::nextNode() from detecting file path mismatch and early-returning. |
| 38 | // The file path check in ReplacementParser::nextNode() is the only reason for this helper function's existence. |
| 39 | fileContents.replace(relativeSourceFilePath, filePaths.source.toUtf8()); |
| 40 | |
| 41 | QCOMPARE_RETURN(yamlFile->write(fileContents), fileContents.size(), {}); |
| 42 | QVERIFY_RETURN(yamlFile->flush(), {}); |
| 43 | yamlFile->close(); |
| 44 | |
| 45 | return filePaths; |
| 46 | } |
| 47 | } // namespace |
| 48 | |
| 49 | using namespace KDevelop; |