forked from qt-creator/qt-creator
FilePathify some testing code
Change-Id: I3739a6eb3c2172078e9519e8186daf94ec74d99a Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -64,9 +64,9 @@ namespace Tests {
|
||||
|
||||
const Usage::Tags Initialization{Usage::Tag::Declaration, Usage::Tag::Write};
|
||||
|
||||
static QString qrcPath(const QByteArray &relativeFilePath)
|
||||
static QString qrcPath(const QString &relativeFilePath)
|
||||
{
|
||||
return QLatin1String(":/unittests/ClangCodeModel/") + QString::fromUtf8(relativeFilePath);
|
||||
return ":/unittests/ClangCodeModel/" + relativeFilePath;
|
||||
}
|
||||
|
||||
ClangdTest::~ClangdTest()
|
||||
@@ -79,7 +79,7 @@ ClangdTest::~ClangdTest()
|
||||
|
||||
Utils::FilePath ClangdTest::filePath(const QString &fileName) const
|
||||
{
|
||||
return Utils::FilePath::fromString(m_projectDir->absolutePath(fileName.toLocal8Bit()));
|
||||
return m_projectDir->absolutePath(fileName);
|
||||
}
|
||||
|
||||
void ClangdTest::waitForNewClient(bool withIndex)
|
||||
@@ -133,11 +133,10 @@ void ClangdTest::initTestCase()
|
||||
QSKIP("The test requires at least one valid kit with a valid Qt");
|
||||
|
||||
// Copy project out of qrc file, open it, and set up target.
|
||||
m_projectDir = new TemporaryCopiedDir(qrcPath(QFileInfo(m_projectFileName)
|
||||
.baseName().toLocal8Bit()));
|
||||
m_projectDir = new TemporaryCopiedDir(qrcPath(QFileInfo(m_projectFileName).baseName()));
|
||||
QVERIFY(m_projectDir->isValid());
|
||||
const auto openProjectResult = ProjectExplorerPlugin::openProject(
|
||||
Utils::FilePath::fromString(m_projectDir->absolutePath(m_projectFileName.toUtf8())));
|
||||
m_projectDir->absolutePath(m_projectFileName));
|
||||
QVERIFY2(openProjectResult, qPrintable(openProjectResult.errorMessage()));
|
||||
m_project = openProjectResult.project();
|
||||
m_project->configureAsExampleProject(m_kit);
|
||||
@@ -147,8 +146,7 @@ void ClangdTest::initTestCase()
|
||||
|
||||
// Open cpp documents.
|
||||
for (const QString &sourceFileName : std::as_const(m_sourceFileNames)) {
|
||||
const auto sourceFilePath = Utils::FilePath::fromString(
|
||||
m_projectDir->absolutePath(sourceFileName.toLocal8Bit()));
|
||||
const auto sourceFilePath = m_projectDir->absolutePath(sourceFileName);
|
||||
QVERIFY2(sourceFilePath.exists(), qPrintable(sourceFilePath.toUserOutput()));
|
||||
IEditor * const editor = EditorManager::openEditor(sourceFilePath);
|
||||
QVERIFY(editor);
|
||||
|
||||
@@ -29,21 +29,20 @@ void ClangFixItTest::testDescription()
|
||||
|
||||
Utils::FilePath ClangFixItTest::semicolonFilePath() const
|
||||
{
|
||||
return Utils::FilePath::fromString(m_dataDir->absolutePath("diagnostic_semicolon_fixit.cpp"));
|
||||
return m_dataDir->absolutePath("diagnostic_semicolon_fixit.cpp");
|
||||
}
|
||||
|
||||
Utils::FilePath ClangFixItTest::compareFilePath() const
|
||||
{
|
||||
return Utils::FilePath::fromString(m_dataDir->absolutePath("diagnostic_comparison_fixit.cpp"));
|
||||
return m_dataDir->absolutePath("diagnostic_comparison_fixit.cpp");
|
||||
}
|
||||
|
||||
QString ClangFixItTest::fileContent(const QByteArray &relFilePath) const
|
||||
QString ClangFixItTest::fileContent(const QString &relFilePath) const
|
||||
{
|
||||
QFile file(m_dataDir->absolutePath(relFilePath));
|
||||
const bool isOpen = file.open(QFile::ReadOnly | QFile::Text);
|
||||
if (!isOpen)
|
||||
qDebug() << "File with the unsaved content cannot be opened!";
|
||||
return QString::fromUtf8(file.readAll());
|
||||
Utils::expected_str<QByteArray> data = m_dataDir->absolutePath(relFilePath).fileContents();
|
||||
if (!data)
|
||||
qDebug() << "File with the unsaved content cannot be opened!" << data.error();
|
||||
return QString::fromUtf8(*data);
|
||||
}
|
||||
|
||||
ClangFixIt ClangFixItTest::semicolonFixIt() const
|
||||
|
||||
@@ -30,7 +30,7 @@ private slots:
|
||||
private:
|
||||
Utils::FilePath semicolonFilePath() const;
|
||||
Utils::FilePath compareFilePath() const;
|
||||
QString fileContent(const QByteArray &relFilePath) const;
|
||||
QString fileContent(const QString &relFilePath) const;
|
||||
|
||||
ClangFixIt semicolonFixIt() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user