MCPcopy Create free account
hub / github.com/KDE/kdevelop / prepareTestFiles

Function prepareTestFiles

plugins/clangtidy/tests/test_replacementparser.cpp:22–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21namespace {
22ReplacementsParserTester::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
49using namespace KDevelop;

Callers 1

initTestCaseMethod · 0.85

Calls 6

openMethod · 0.45
closeMethod · 0.45
fileNameMethod · 0.45
replaceMethod · 0.45
writeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected