Skip to content

Commit 5941222

Browse files
committed
Add test case for whole directory name matching and root directory as a special case
1 parent 03c73f4 commit 5941222

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

lldb/unittests/Utility/FileSpecListTest.cpp

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ TEST(SupportFileListTest, RelativePathMatchesWindows) {
127127
}
128128

129129
// Support file is a symlink to the breakpoint file.
130-
// A matching prefix is set.
131-
// Should find the two compatible.
132130
// Absolute paths are used.
131+
// A matching prefix is set.
132+
// Should find it compatible.
133133
TEST(SupportFileListTest, SymlinkedAbsolutePaths) {
134134
// Prepare FS
135135
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
@@ -151,9 +151,33 @@ TEST(SupportFileListTest, SymlinkedAbsolutePaths) {
151151
}
152152

153153
// Support file is a symlink to the breakpoint file.
154-
// A matching prefix is set.
155-
// Should find the two compatible.
154+
// Absolute paths are used.
155+
// A matching prefix is set, which is the root directory.
156+
// Should find it compatible.
157+
TEST(SupportFileListTest, RootDirectory) {
158+
// Prepare FS
159+
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
160+
FileSpec("/symlink_dir/foo.h"), FileSpec("/real_dir/foo.h")));
161+
162+
// Prepare RealpathPrefixes
163+
FileSpecList file_spec_list;
164+
file_spec_list.EmplaceBack("/");
165+
RealpathPrefixes prefixes(file_spec_list, fs);
166+
167+
// Prepare support file list
168+
SupportFileList support_file_list;
169+
support_file_list.EmplaceBack(FileSpec("/symlink_dir/foo.h"));
170+
171+
// Test
172+
size_t ret = support_file_list.FindCompatibleIndex(
173+
0, FileSpec("/real_dir/foo.h"), &prefixes);
174+
EXPECT_EQ(ret, (size_t)0);
175+
}
176+
177+
// Support file is a symlink to the breakpoint file.
156178
// Relative paths are used.
179+
// A matching prefix is set.
180+
// Should find it compatible.
157181
TEST(SupportFileListTest, SymlinkedRelativePaths) {
158182
// Prepare FS
159183
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
@@ -177,7 +201,7 @@ TEST(SupportFileListTest, SymlinkedRelativePaths) {
177201
// Support file is a symlink to the breakpoint file.
178202
// A matching prefix is set.
179203
// Input file only match basename and not directory.
180-
// Should find the two incompatible.
204+
// Should find it incompatible.
181205
TEST(SupportFileListTest, RealpathOnlyMatchFileName) {
182206
// Prepare FS
183207
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
@@ -198,10 +222,34 @@ TEST(SupportFileListTest, RealpathOnlyMatchFileName) {
198222
EXPECT_EQ(ret, UINT32_MAX);
199223
}
200224

225+
// Support file is a symlink to the breakpoint file.
226+
// A prefix is set, which is a matching string prefix, but not a path prefix.
227+
// Should find it incompatible.
228+
TEST(SupportFileListTest, DirectoryMatchStringPrefixButNotWholeDirectoryName) {
229+
// Prepare FS
230+
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
231+
FileSpec("symlink_dir/foo.h"), FileSpec("real_dir/foo.h")));
232+
233+
// Prepare RealpathPrefixes
234+
FileSpecList file_spec_list;
235+
file_spec_list.EmplaceBack("symlink"); // This is a string prefix of the
236+
// symlink but not a path prefix.
237+
RealpathPrefixes prefixes(file_spec_list, fs);
238+
239+
// Prepare support file list
240+
SupportFileList support_file_list;
241+
support_file_list.EmplaceBack(FileSpec("symlink_dir/foo.h"));
242+
243+
// Test
244+
size_t ret = support_file_list.FindCompatibleIndex(
245+
0, FileSpec("real_dir/foo.h"), &prefixes);
246+
EXPECT_EQ(ret, UINT32_MAX);
247+
}
248+
201249
// Support file is a symlink to the breakpoint file.
202250
// A matching prefix is set.
203251
// However, the breakpoint is set with a partial path.
204-
// Should find the two compatible.
252+
// Should find it compatible.
205253
TEST(SupportFileListTest, PartialBreakpointPath) {
206254
// Prepare FS
207255
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
@@ -225,7 +273,7 @@ TEST(SupportFileListTest, PartialBreakpointPath) {
225273
// Support file is a symlink to the breakpoint file.
226274
// A matching prefix is set.
227275
// However, the basename is different between the symlink and its target.
228-
// Should find the two incompatible.
276+
// Should find it incompatible.
229277
TEST(SupportFileListTest, DifferentBasename) {
230278
// Prepare FS
231279
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
@@ -248,7 +296,7 @@ TEST(SupportFileListTest, DifferentBasename) {
248296

249297
// No prefixes are configured.
250298
// The support file and the breakpoint file are different.
251-
// Should find the two incompatible.
299+
// Should find it incompatible.
252300
TEST(SupportFileListTest, NoPrefixes) {
253301
// Prepare support file list
254302
SupportFileList support_file_list;
@@ -262,7 +310,7 @@ TEST(SupportFileListTest, NoPrefixes) {
262310

263311
// No prefixes are configured.
264312
// The support file and the breakpoint file are the same.
265-
// Should find the two compatible.
313+
// Should find it compatible.
266314
TEST(SupportFileListTest, SameFile) {
267315
// Prepare support file list
268316
SupportFileList support_file_list;

0 commit comments

Comments
 (0)