Changeset View
Changeset View
Standalone View
Standalone View
projectmanagers/cmake/tests/test_cmakemanager.cpp
Show All 14 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "test_cmakemanager.h" | 20 | #include "test_cmakemanager.h" | ||
21 | #include "testhelpers.h" | 21 | #include "testhelpers.h" | ||
22 | #include "cmakemodelitems.h" | 22 | #include "cmakemodelitems.h" | ||
23 | #include "cmakeutils.h" | ||||
23 | #include <icmakemanager.h> | 24 | #include <icmakemanager.h> | ||
24 | 25 | | |||
25 | #include <qtest.h> | 26 | #include <qtest.h> | ||
26 | 27 | | |||
27 | #include <interfaces/iplugincontroller.h> | 28 | #include <interfaces/iplugincontroller.h> | ||
28 | #include <interfaces/icore.h> | 29 | #include <interfaces/icore.h> | ||
29 | #include <project/interfaces/iprojectfilemanager.h> | 30 | #include <project/interfaces/iprojectfilemanager.h> | ||
30 | #include <project/interfaces/ibuildsystemmanager.h> | 31 | #include <project/interfaces/ibuildsystemmanager.h> | ||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Line(s) | 287 | { | |||
295 | Path subdirectoryFooCpp(project->path(), "subdirectory/foo.cpp"); | 296 | Path subdirectoryFooCpp(project->path(), "subdirectory/foo.cpp"); | ||
296 | QVERIFY(QFile::exists(subdirectoryFooCpp.toLocalFile())); | 297 | QVERIFY(QFile::exists(subdirectoryFooCpp.toLocalFile())); | ||
297 | QList< ProjectBaseItem* > subdirectoryFooItems = project->itemsForPath(IndexedString(subdirectoryFooCpp.pathOrUrl())); | 298 | QList< ProjectBaseItem* > subdirectoryFooItems = project->itemsForPath(IndexedString(subdirectoryFooCpp.pathOrUrl())); | ||
298 | 299 | | |||
299 | QEXPECT_FAIL("", "files aren't being added to the target", Continue); | 300 | QEXPECT_FAIL("", "files aren't being added to the target", Continue); | ||
300 | QCOMPARE(subdirectoryFooItems.size(), 4); // three items for the targets, one item for the plain file | 301 | QCOMPARE(subdirectoryFooItems.size(), 4); // three items for the targets, one item for the plain file | ||
301 | } | 302 | } | ||
302 | 303 | | |||
304 | void TestCMakeManager::testEnumerateTargets() | ||||
kfunk: Be explicit: Call it `testEnumerateTargets()` | |||||
305 | { | ||||
306 | QString currentDir = QDir::currentPath(); | ||||
307 | | ||||
308 | QTemporaryFile targetDirectoriesFile("./TargetDirectories.txt"); | ||||
kfunk: `QTemporaryFile`? | |||||
Cleaner to use absolute file paths here: QDir::tempPath() + "/TargetDirectories.txt" -> Doesn't pollute your CWD kfunk: Cleaner to use absolute file paths here: `QDir::tempPath() + "/TargetDirectories.txt"`
->… | |||||
309 | QTemporaryDir subdir("."); | ||||
kfunk: Dito, using the default ctor of `QTemporaryDir` is fine already. | |||||
310 | | ||||
311 | auto opened = targetDirectoriesFile.open(); | ||||
312 | QVERIFY(opened); | ||||
313 | QVERIFY(subdir.isValid()); | ||||
314 | | ||||
315 | const QString targetDirectoriesContent = currentDir + "/CMakeFiles/first_target.dir\n" + | ||||
316 | currentDir + "/CMakeFiles/second_target.dir\r\n" + | ||||
317 | currentDir + "/" + subdir.path() + "/CMakeFiles/third_target.dir"; | ||||
318 | | ||||
319 | targetDirectoriesFile.write(targetDirectoriesContent.toLatin1()); | ||||
320 | targetDirectoriesFile.close(); | ||||
Better use QTemporaryDir("/path/to/subdir") on the stack => takes care of construction & deletion of this dir kfunk: Better use `QTemporaryDir("/path/to/subdir")` on the stack => takes care of construction &… | |||||
321 | | ||||
322 | QHash<KDevelop::Path, QStringList> targets = | ||||
323 | CMake::enumerateTargets(Path(targetDirectoriesFile.fileName()), | ||||
324 | currentDir, Path(currentDir)); | ||||
325 | | ||||
326 | QCOMPARE(targets.value(Path(currentDir)).value(0), QStringLiteral("first_target")); | ||||
327 | QCOMPARE(targets.value(Path(currentDir)).value(1), QStringLiteral("second_target")); | ||||
328 | QCOMPARE(targets.value(Path(currentDir + subdir.path())).value(0), QStringLiteral("third_target")); | ||||
329 | } | ||||
330 | | ||||
303 | void TestCMakeManager::testFaultyTarget() | 331 | void TestCMakeManager::testFaultyTarget() | ||
304 | { | 332 | { | ||
305 | loadProject("faulty_target"); | 333 | loadProject("faulty_target"); | ||
306 | } | 334 | } |
Be explicit: Call it testEnumerateTargets()