[PATCH] D45807: [libclang] Fix test LibclangReparseTest.FileName when TMPDIR is set to a symbolic link
Petr Pavlu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 19 02:26:06 PDT 2018
petpav01 created this revision.
petpav01 added reviewers: MaskRay, jbcoe.
Herald added a subscriber: cfe-commits.
Commit r329515 <http://llvm.org/viewvc/llvm-project?view=revision&revision=329515> recently added new test `LibclangReparseTest.FileName`. This test fails in an environment which has `TMPDIR` set to a symbolic link that points to an actual directory.
Example:
build$ ln -s /tmp mytmp
build$ TMPDIR=$PWD/mytmp ./tools/clang/unittests/libclang/libclangTests
[...]
[----------] 5 tests from LibclangReparseTest
[ RUN ] LibclangReparseTest.FileName
.../tools/clang/unittests/libclang/LibclangTest.cpp:497: Failure
Value of: strstr(clang_getCString(cxname), CppName.c_str())
Actual: false
Expected: true
[ FAILED ] LibclangReparseTest.FileName (10 ms)
[...]
`CppName` is the original path in form `$tmpdir/libclang-test-xxxxxx/main.cpp`. Value `cxname` is obtained through `clang_File_tryGetRealPathName()` which gives the real path with the symlink resolved. The test fails because these two paths do not match.
The proposed patch addresses the problem by checking only that the value returned by `clang_File_tryGetRealPathName()` ends with "main.cpp".
Additionally, the patch makes the previous assertion in the test that checks result of `clang_getFileName()` stricter. It newly verifies that the name returned by the function is exactly same as what was given to `clang_parseTranslationUnit()`/`clang_getFile()`.
Repository:
rC Clang
https://reviews.llvm.org/D45807
Files:
unittests/libclang/LibclangTest.cpp
Index: unittests/libclang/LibclangTest.cpp
===================================================================
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "clang-c/Index.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
@@ -490,11 +491,11 @@
CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
CXString cxname = clang_getFileName(cxf);
- ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+ ASSERT_STREQ(clang_getCString(cxname), CppName.c_str());
clang_disposeString(cxname);
cxname = clang_File_tryGetRealPathName(cxf);
- ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+ ASSERT_TRUE(llvm::StringRef(clang_getCString(cxname)).endswith("main.cpp"));
clang_disposeString(cxname);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45807.143062.patch
Type: text/x-patch
Size: 974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180419/dcacc43b/attachment.bin>
More information about the cfe-commits
mailing list