@@ -214,28 +214,44 @@ void TestProjectFile::emptyUserInclude() const
214214 QCOMPARE (settings.userIncludes .size (), 0 );
215215}
216216
217- // Absolute path is made relative when it does not require walking up more than 2 parent folders
217+ // Absolute path is made relative when it does not require walking up more than 3 parent folders
218218void TestProjectFile::getRelativePathRelative () const
219219{
220220 ProjectFile projectFile;
221- projectFile.setFilename (" /some/path/123.cppcheck" );
222- QCOMPARE (projectFile.getRelativePath (" /some/externals/foo.cpp" ), QString (" ../externals/foo.cpp" ));
221+ projectFile.setFilename (" /some/path/sub/123.cppcheck" );
222+ QCOMPARE (projectFile.getRelativePath (" /some/path/externals/foo.cpp" ), QString (" ../externals/foo.cpp" ));
223+ }
224+
225+ // Absolute path is made relative even when it requires walking up 2 parent folders
226+ void TestProjectFile::getRelativePathTwoUp () const
227+ {
228+ ProjectFile projectFile;
229+ projectFile.setFilename (" /some/path/sub/123.cppcheck" );
230+ QCOMPARE (projectFile.getRelativePath (" /some/externals/foo.cpp" ), QString (" ../../externals/foo.cpp" ));
223231}
224232
225- // Absolute path is kept as-is when making it relative would require walking up more than 2 parent folders
233+ // Absolute path is kept as-is when making it relative would require walking up more than 3 parent folders
226234void TestProjectFile::getRelativePathTooFarUp () const
227235{
228236 ProjectFile projectFile;
229- projectFile.setFilename (" /some/path/123.cppcheck" );
237+ projectFile.setFilename (" /some/path/sub/ 123.cppcheck" );
230238 QCOMPARE (projectFile.getRelativePath (" /other/deep/foo.cpp" ), QString (" /other/deep/foo.cpp" ));
231239}
232240
233241// Absolute path in a subfolder of the project path is made relative without walking up at all
234242void TestProjectFile::getRelativePathSubfolder () const
235243{
236244 ProjectFile projectFile;
237- projectFile.setFilename (" /some/path/123.cppcheck" );
238- QCOMPARE (projectFile.getRelativePath (" /some/path/src/file1.c" ), QString (" src/file1.c" ));
245+ projectFile.setFilename (" /some/path/sub/123.cppcheck" );
246+ QCOMPARE (projectFile.getRelativePath (" /some/path/sub/src/file1.c" ), QString (" src/file1.c" ));
247+ }
248+
249+ // Absolute path is kept as-is when it is shorter than the relative path, even if it does not require walking up 3 or more parent folders
250+ void TestProjectFile::getRelativePathAbsoluteShorter () const
251+ {
252+ ProjectFile projectFile;
253+ projectFile.setFilename (" /ab/path/sub/123.cppcheck" );
254+ QCOMPARE (projectFile.getRelativePath (" /ab/foo.cpp" ), QString (" /ab/foo.cpp" ));
239255}
240256
241257QTEST_MAIN (TestProjectFile)
0 commit comments