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:
@@ -81,7 +81,7 @@ void AutoTestUnitTests::cleanupTestCase()
|
||||
|
||||
void AutoTestUnitTests::testCodeParser()
|
||||
{
|
||||
QFETCH(QString, projectFilePath);
|
||||
QFETCH(FilePath, projectFilePath);
|
||||
QFETCH(int, expectedAutoTestsCount);
|
||||
QFETCH(int, expectedNamedQuickTestsCount);
|
||||
QFETCH(int, expectedUnnamedQuickTestsCount);
|
||||
@@ -106,30 +106,30 @@ void AutoTestUnitTests::testCodeParser()
|
||||
|
||||
void AutoTestUnitTests::testCodeParser_data()
|
||||
{
|
||||
QTest::addColumn<QString>("projectFilePath");
|
||||
QTest::addColumn<FilePath>("projectFilePath");
|
||||
QTest::addColumn<int>("expectedAutoTestsCount");
|
||||
QTest::addColumn<int>("expectedNamedQuickTestsCount");
|
||||
QTest::addColumn<int>("expectedUnnamedQuickTestsCount");
|
||||
QTest::addColumn<int>("expectedDataTagsCount");
|
||||
|
||||
|
||||
const FilePath base = m_tmpDir->filePath();
|
||||
QTest::newRow("plainAutoTest")
|
||||
<< QString(m_tmpDir->path() + "/plain/plain.pro")
|
||||
<< base / "plain/plain.pro"
|
||||
<< 1 << 0 << 0 << 0;
|
||||
QTest::newRow("mixedAutoTestAndQuickTests")
|
||||
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.pro")
|
||||
<< base / "mixed_atp/mixed_atp.pro"
|
||||
<< 4 << 10 << 5 << 10;
|
||||
QTest::newRow("plainAutoTestQbs")
|
||||
<< QString(m_tmpDir->path() + "/plain/plain.qbs")
|
||||
<< base / "plain/plain.qbs"
|
||||
<< 1 << 0 << 0 << 0;
|
||||
QTest::newRow("mixedAutoTestAndQuickTestsQbs")
|
||||
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.qbs")
|
||||
<< base / "mixed_atp/mixed_atp.qbs"
|
||||
<< 4 << 10 << 5 << 10;
|
||||
}
|
||||
|
||||
void AutoTestUnitTests::testCodeParserSwitchStartup()
|
||||
{
|
||||
QFETCH(QStringList, projectFilePaths);
|
||||
QFETCH(FilePaths, projectFilePaths);
|
||||
QFETCH(QList<int>, expectedAutoTestsCount);
|
||||
QFETCH(QList<int>, expectedNamedQuickTestsCount);
|
||||
QFETCH(QList<int>, expectedUnnamedQuickTestsCount);
|
||||
@@ -157,16 +157,19 @@ void AutoTestUnitTests::testCodeParserSwitchStartup()
|
||||
|
||||
void AutoTestUnitTests::testCodeParserSwitchStartup_data()
|
||||
{
|
||||
QTest::addColumn<QStringList>("projectFilePaths");
|
||||
QTest::addColumn<FilePaths>("projectFilePaths");
|
||||
QTest::addColumn<QList<int> >("expectedAutoTestsCount");
|
||||
QTest::addColumn<QList<int> >("expectedNamedQuickTestsCount");
|
||||
QTest::addColumn<QList<int> >("expectedUnnamedQuickTestsCount");
|
||||
QTest::addColumn<QList<int> >("expectedDataTagsCount");
|
||||
|
||||
QStringList projects = QStringList({m_tmpDir->path() + "/plain/plain.pro",
|
||||
m_tmpDir->path() + "/mixed_atp/mixed_atp.pro",
|
||||
m_tmpDir->path() + "/plain/plain.qbs",
|
||||
m_tmpDir->path() + "/mixed_atp/mixed_atp.qbs"});
|
||||
const FilePath base = m_tmpDir->filePath();
|
||||
FilePaths projects {
|
||||
base / "plain/plain.pro",
|
||||
base / "mixed_atp/mixed_atp.pro",
|
||||
base / "plain/plain.qbs",
|
||||
base / "mixed_atp/mixed_atp.qbs"
|
||||
};
|
||||
|
||||
QList<int> expectedAutoTests = QList<int>() << 1 << 4 << 1 << 4;
|
||||
QList<int> expectedNamedQuickTests = QList<int>() << 0 << 10 << 0 << 10;
|
||||
@@ -183,7 +186,7 @@ void AutoTestUnitTests::testCodeParserGTest()
|
||||
if (qtcEnvironmentVariableIsEmpty("GOOGLETEST_DIR"))
|
||||
QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)");
|
||||
|
||||
QFETCH(QString, projectFilePath);
|
||||
QFETCH(FilePath, projectFilePath);
|
||||
CppEditor::Tests::ProjectOpenerAndCloser projectManager;
|
||||
QVERIFY(projectManager.open(projectFilePath, true, m_kit));
|
||||
|
||||
@@ -219,11 +222,11 @@ void AutoTestUnitTests::testCodeParserGTest()
|
||||
|
||||
void AutoTestUnitTests::testCodeParserGTest_data()
|
||||
{
|
||||
QTest::addColumn<QString>("projectFilePath");
|
||||
QTest::addColumn<FilePath>("projectFilePath");
|
||||
QTest::newRow("simpleGoogletest")
|
||||
<< QString(m_tmpDir->path() + "/simple_gt/simple_gt.pro");
|
||||
<< m_tmpDir->filePath() / "simple_gt/simple_gt.pro";
|
||||
QTest::newRow("simpleGoogletestQbs")
|
||||
<< QString(m_tmpDir->path() + "/simple_gt/simple_gt.qbs");
|
||||
<< m_tmpDir->filePath() / "simple_gt/simple_gt.qbs";
|
||||
}
|
||||
|
||||
void AutoTestUnitTests::testCodeParserBoostTest()
|
||||
@@ -231,7 +234,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
|
||||
if (!m_checkBoost)
|
||||
QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)");
|
||||
|
||||
QFETCH(QString, projectFilePath);
|
||||
QFETCH(FilePath, projectFilePath);
|
||||
QFETCH(QString, extension);
|
||||
CppEditor::Tests::ProjectOpenerAndCloser projectManager;
|
||||
const CppEditor::ProjectInfo::ConstPtr projectInfo
|
||||
|
@@ -68,7 +68,7 @@ bool LoadProjectScenario::init()
|
||||
|
||||
bool LoadProjectScenario::loadProject()
|
||||
{
|
||||
const QString projectFilePath = m_tmpDir->path() + "/plain/plain.pro";
|
||||
const FilePath projectFilePath = m_tmpDir->filePath() / "/plain/plain.pro";
|
||||
|
||||
CppEditor::Tests::ProjectOpenerAndCloser projectManager;
|
||||
// This code must trigger a call to PluginManager::finishScenario() at some later point.
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static ClangDiagnosticConfig configFor(const QString &tidyChecks, const QString
|
||||
|
||||
void ClangToolsUnitTests::testProject()
|
||||
{
|
||||
QFETCH(QString, projectFilePath);
|
||||
QFETCH(FilePath, projectFilePath);
|
||||
QFETCH(int, expectedDiagCountClangTidy);
|
||||
QFETCH(int, expectedDiagCountClazy);
|
||||
QFETCH(ClangDiagnosticConfig, diagnosticConfig);
|
||||
@@ -119,7 +119,7 @@ void ClangToolsUnitTests::testProject()
|
||||
|
||||
void ClangToolsUnitTests::testProject_data()
|
||||
{
|
||||
QTest::addColumn<QString>("projectFilePath");
|
||||
QTest::addColumn<FilePath>("projectFilePath");
|
||||
QTest::addColumn<int>("expectedDiagCountClangTidy");
|
||||
QTest::addColumn<int>("expectedDiagCountClazy");
|
||||
QTest::addColumn<ClangDiagnosticConfig>("diagnosticConfig");
|
||||
@@ -161,8 +161,8 @@ void ClangToolsUnitTests::addTestRow(const QByteArray &relativeFilePath,
|
||||
int expectedDiagCountClazy,
|
||||
const ClangDiagnosticConfig &diagnosticConfig)
|
||||
{
|
||||
const QString absoluteFilePath = m_tmpDir->absolutePath(relativeFilePath);
|
||||
const QString fileName = QFileInfo(absoluteFilePath).fileName();
|
||||
const FilePath absoluteFilePath = m_tmpDir->absolutePath(QString::fromUtf8(relativeFilePath));
|
||||
const QString fileName = absoluteFilePath.fileName();
|
||||
|
||||
QTest::newRow(fileName.toUtf8().constData())
|
||||
<< absoluteFilePath << expectedDiagCountClangTidy << expectedDiagCountClazy
|
||||
|
@@ -267,8 +267,8 @@ QString ReadExportedDiagnosticsTest::createFile(const QString &yamlFilePath,
|
||||
const QString &filePathToInject) const
|
||||
{
|
||||
QTC_ASSERT(QDir::isAbsolutePath(filePathToInject), return QString());
|
||||
const Utils::FilePath newFileName = FilePath::fromString(m_baseDir->absolutePath(
|
||||
QFileInfo(yamlFilePath).fileName().toLocal8Bit()));
|
||||
const Utils::FilePath newFileName = m_baseDir->absolutePath(
|
||||
QFileInfo(yamlFilePath).fileName());
|
||||
|
||||
Utils::FileReader reader;
|
||||
if (QTC_GUARD(reader.fetch(Utils::FilePath::fromString(yamlFilePath),
|
||||
@@ -286,7 +286,7 @@ QString ReadExportedDiagnosticsTest::createFile(const QString &yamlFilePath,
|
||||
|
||||
FilePath ReadExportedDiagnosticsTest::filePath(const QString &fileName) const
|
||||
{
|
||||
return FilePath::fromString(m_baseDir->absolutePath(fileName.toUtf8()));
|
||||
return m_baseDir->absolutePath(fileName);
|
||||
}
|
||||
|
||||
} // namespace ClangTools::Internal
|
||||
|
@@ -25,8 +25,7 @@ using namespace CppEditor;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace CompilationDatabaseProjectManager {
|
||||
namespace Internal {
|
||||
namespace CompilationDatabaseProjectManager::Internal {
|
||||
|
||||
CompilationDatabaseTests::CompilationDatabaseTests(QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -57,7 +56,7 @@ void CompilationDatabaseTests::cleanupTestCase()
|
||||
|
||||
void CompilationDatabaseTests::testProject()
|
||||
{
|
||||
QFETCH(QString, projectFilePath);
|
||||
QFETCH(FilePath, projectFilePath);
|
||||
|
||||
CppEditor::Tests::ProjectOpenerAndCloser projectManager;
|
||||
const CppEditor::ProjectInfo::ConstPtr projectInfo = projectManager.open(projectFilePath, true);
|
||||
@@ -263,12 +262,11 @@ void CompilationDatabaseTests::testSkipOutputFiles()
|
||||
QVERIFY(testData.getFilteredFlags().isEmpty());
|
||||
}
|
||||
|
||||
void CompilationDatabaseTests::addTestRow(const QByteArray &relativeFilePath)
|
||||
void CompilationDatabaseTests::addTestRow(const QString &relativeFilePath)
|
||||
{
|
||||
const QString absoluteFilePath = m_tmpDir->absolutePath(relativeFilePath);
|
||||
const FilePath absoluteFilePath = m_tmpDir->absolutePath(relativeFilePath);
|
||||
|
||||
QTest::newRow(relativeFilePath.constData()) << absoluteFilePath;
|
||||
QTest::newRow(qPrintable(relativeFilePath)) << absoluteFilePath;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CompilationDatabaseProjectManager
|
||||
} // CompilationDatabaseProjectManager::Internal
|
||||
|
@@ -8,8 +8,7 @@
|
||||
|
||||
namespace CppEditor { namespace Tests { class TemporaryCopiedDir; } }
|
||||
|
||||
namespace CompilationDatabaseProjectManager {
|
||||
namespace Internal {
|
||||
namespace CompilationDatabaseProjectManager::Internal {
|
||||
|
||||
class CompilationDatabaseTests : public QObject
|
||||
{
|
||||
@@ -34,10 +33,9 @@ private slots:
|
||||
void testSkipOutputFiles();
|
||||
|
||||
private:
|
||||
void addTestRow(const QByteArray &relativeFilePath);
|
||||
void addTestRow(const QString &relativeFilePath);
|
||||
|
||||
std::unique_ptr<CppEditor::Tests::TemporaryCopiedDir> m_tmpDir;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CompilationDatabaseProjectManager
|
||||
} // CompilationDatabaseProjectManager::Internal
|
||||
|
@@ -80,7 +80,7 @@ FilePaths toAbsolutePaths(const QStringList &relativePathList,
|
||||
{
|
||||
FilePaths result;
|
||||
for (const QString &file : relativePathList)
|
||||
result << FilePath::fromString(temporaryDir.absolutePath(file.toUtf8()));
|
||||
result << temporaryDir.absolutePath(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
|
||||
QFETCH(QStringList, finalProjectFiles);
|
||||
|
||||
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path());
|
||||
const FilePath filePath = FilePath::fromString(temporaryDir.absolutePath(fileToChange.toUtf8()));
|
||||
const FilePath filePath = temporaryDir.absolutePath(fileToChange);
|
||||
const FilePaths initialProjectFilePaths = toAbsolutePaths(initialProjectFiles, temporaryDir);
|
||||
const FilePaths finalProjectFilePaths = toAbsolutePaths(finalProjectFiles, temporaryDir);
|
||||
|
||||
@@ -594,7 +594,7 @@ void ModelManagerTest::testExtraeditorsupportUiFiles()
|
||||
|
||||
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_guiproject1")).path());
|
||||
QVERIFY(temporaryDir.isValid());
|
||||
const QString projectFile = temporaryDir.absolutePath("testdata_guiproject1.pro");
|
||||
const FilePath projectFile = temporaryDir.absolutePath("testdata_guiproject1.pro");
|
||||
|
||||
ProjectOpenerAndCloser projects;
|
||||
QVERIFY(projects.open(projectFile, /*configureAsExampleProject=*/ true));
|
||||
@@ -618,8 +618,7 @@ void ModelManagerTest::testExtraeditorsupportUiFiles()
|
||||
|
||||
// Check CppSourceProcessor / includes.
|
||||
// The CppSourceProcessor is expected to find the ui_* file in the working copy.
|
||||
const FilePath fileIncludingTheUiFile =
|
||||
FilePath::fromString(temporaryDir.absolutePath("mainwindow.cpp"));
|
||||
const FilePath fileIncludingTheUiFile = temporaryDir.absolutePath("mainwindow.cpp");
|
||||
while (!mm->snapshot().document(fileIncludingTheUiFile))
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
|
@@ -391,11 +391,11 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const QString &projectFile,
|
||||
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
|
||||
bool configureAsExampleProject, Kit *kit)
|
||||
{
|
||||
ProjectExplorerPlugin::OpenProjectResult result =
|
||||
ProjectExplorerPlugin::openProject(FilePath::fromString(projectFile));
|
||||
ProjectExplorerPlugin::openProject(projectFile);
|
||||
if (!result) {
|
||||
qWarning() << result.errorMessage() << result.alreadyOpen();
|
||||
return {};
|
||||
@@ -476,9 +476,9 @@ TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
|
||||
}
|
||||
}
|
||||
|
||||
QString TemporaryCopiedDir::absolutePath(const QByteArray &relativePath) const
|
||||
FilePath TemporaryCopiedDir::absolutePath(const QString &relativePath) const
|
||||
{
|
||||
return m_temporaryDir.filePath(QString::fromUtf8(relativePath)).path();
|
||||
return m_temporaryDir.filePath(relativePath);
|
||||
}
|
||||
|
||||
int clangdIndexingTimeout()
|
||||
|
@@ -167,7 +167,7 @@ public:
|
||||
~ProjectOpenerAndCloser(); // Closes opened projects
|
||||
|
||||
ProjectInfo::ConstPtr open(
|
||||
const QString &projectFile,
|
||||
const Utils::FilePath &projectFile,
|
||||
bool configureAsExampleProject = false,
|
||||
ProjectExplorer::Kit *kit = nullptr);
|
||||
|
||||
@@ -197,7 +197,7 @@ class CPPEDITOR_EXPORT TemporaryCopiedDir : public TemporaryDir
|
||||
{
|
||||
public:
|
||||
explicit TemporaryCopiedDir(const QString &sourceDirPath);
|
||||
QString absolutePath(const QByteArray &relativePath) const;
|
||||
Utils::FilePath absolutePath(const QString &relativePath) const;
|
||||
|
||||
private:
|
||||
TemporaryCopiedDir();
|
||||
|
@@ -2351,7 +2351,7 @@ void DebuggerUnitTests::cleanupTestCase()
|
||||
|
||||
void DebuggerUnitTests::testStateMachine()
|
||||
{
|
||||
QString proFile = m_tmpDir->absolutePath("simple/simple.pro");
|
||||
FilePath proFile = m_tmpDir->absolutePath("simple/simple.pro");
|
||||
|
||||
CppEditor::Tests::ProjectOpenerAndCloser projectManager;
|
||||
QVERIFY(projectManager.open(proFile, true));
|
||||
|
Reference in New Issue
Block a user