@@ -197,6 +197,8 @@ TEST(IncludeTree, IncludeTreeFileList) {
197
197
size_t I = 0 ;
198
198
ASSERT_THAT_ERROR (
199
199
L->forEachFile ([&](IncludeTree::File F, auto Size) -> llvm::Error {
200
+ if (I >= Files.size ())
201
+ return llvm::Error::success (); // diagnosed later.
200
202
EXPECT_EQ (F.getFilenameRef (), Files[I].getFilenameRef ())
201
203
<< " filename mismatch at " << I;
202
204
EXPECT_EQ (F.getContentsRef (), Files[I].getContentsRef ())
@@ -206,4 +208,55 @@ TEST(IncludeTree, IncludeTreeFileList) {
206
208
return llvm::Error::success ();
207
209
}),
208
210
llvm::Succeeded ());
211
+ EXPECT_EQ (I, Files.size ());
212
+ }
213
+
214
+ TEST (IncludeTree, IncludeTreeFileListDuplicates) {
215
+ std::shared_ptr<ObjectStore> DB = llvm::cas::createInMemoryCAS ();
216
+ SmallVector<IncludeTree::File> Files;
217
+ for (unsigned I = 0 ; I < 10 ; ++I) {
218
+ std::optional<IncludeTree::File> File;
219
+ std::string Path = " /file" + std::to_string (I);
220
+ static constexpr StringRef Bytes = " 123456789" ;
221
+ std::optional<ObjectRef> Content;
222
+ ASSERT_THAT_ERROR (
223
+ DB->storeFromString ({}, Bytes.substr (0 , I)).moveInto (Content),
224
+ llvm::Succeeded ());
225
+ ASSERT_THAT_ERROR (
226
+ IncludeTree::File::create (*DB, Path, *Content).moveInto (File),
227
+ llvm::Succeeded ());
228
+ Files.push_back (std::move (*File));
229
+ }
230
+
231
+ auto MakeFileList = [&](unsigned Begin, unsigned End,
232
+ ArrayRef<ObjectRef> Lists) {
233
+ SmallVector<IncludeTree::FileList::FileEntry> Entries;
234
+ for (; Begin != End; ++Begin)
235
+ Entries.push_back ({Files[Begin].getRef (), Begin});
236
+ return IncludeTree::FileList::create (*DB, Entries, Lists);
237
+ };
238
+
239
+ std::optional<IncludeTree::FileList> L89, L;
240
+ ASSERT_THAT_ERROR (MakeFileList (8 , 10 , {}).moveInto (L89), llvm::Succeeded ());
241
+ EXPECT_EQ (L89->getNumReferences (), 2u );
242
+ ASSERT_THAT_ERROR (
243
+ MakeFileList (0 , 9 , {L89->getRef (), L89->getRef ()}).moveInto (L),
244
+ llvm::Succeeded ());
245
+ EXPECT_EQ (L->getNumReferences (), 11u ); // 0, 1, ..., 8, {8, 9}, {8, 9}
246
+
247
+ size_t I = 0 ;
248
+ ASSERT_THAT_ERROR (
249
+ L->forEachFile ([&](IncludeTree::File F, auto Size) -> llvm::Error {
250
+ if (I >= Files.size ())
251
+ return llvm::Error::success (); // diagnosed later.
252
+ EXPECT_EQ (F.getFilenameRef (), Files[I].getFilenameRef ())
253
+ << " filename mismatch at " << I;
254
+ EXPECT_EQ (F.getContentsRef (), Files[I].getContentsRef ())
255
+ << " contents mismatch at " << I;
256
+ EXPECT_EQ (Size, I) << " size mismatch at " << I;
257
+ I += 1 ;
258
+ return llvm::Error::success ();
259
+ }),
260
+ llvm::Succeeded ());
261
+ EXPECT_EQ (I, Files.size ());
209
262
}
0 commit comments