1 //===-- TextStubV2Tests.cpp - TBD V2 File Test ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===-----------------------------------------------------------------------===/
8 
9 #include "llvm/TextAPI/MachO/InterfaceFile.h"
10 #include "llvm/TextAPI/MachO/TextAPIReader.h"
11 #include "llvm/TextAPI/MachO/TextAPIWriter.h"
12 #include "gtest/gtest.h"
13 #include <string>
14 #include <vector>
15 
16 using namespace llvm;
17 using namespace llvm::MachO;
18 
19 struct ExportedSymbol {
20   SymbolKind Kind;
21   std::string Name;
22   bool WeakDefined;
23   bool ThreadLocalValue;
24 };
25 using ExportedSymbolSeq = std::vector<ExportedSymbol>;
26 
27 inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
28   return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
29 }
30 
31 inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
32   return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
33          std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
34 }
35 
36 static ExportedSymbol TBDv2Symbols[] = {
37     {SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
38     {SymbolKind::GlobalSymbol, "_sym1", false, false},
39     {SymbolKind::GlobalSymbol, "_sym2", false, false},
40     {SymbolKind::GlobalSymbol, "_sym3", false, false},
41     {SymbolKind::GlobalSymbol, "_sym4", false, false},
42     {SymbolKind::GlobalSymbol, "_sym5", false, false},
43     {SymbolKind::GlobalSymbol, "_tlv1", false, true},
44     {SymbolKind::GlobalSymbol, "_tlv2", false, true},
45     {SymbolKind::GlobalSymbol, "_tlv3", false, true},
46     {SymbolKind::GlobalSymbol, "_weak1", true, false},
47     {SymbolKind::GlobalSymbol, "_weak2", true, false},
48     {SymbolKind::GlobalSymbol, "_weak3", true, false},
49     {SymbolKind::ObjectiveCClass, "class1", false, false},
50     {SymbolKind::ObjectiveCClass, "class2", false, false},
51     {SymbolKind::ObjectiveCClass, "class3", false, false},
52     {SymbolKind::ObjectiveCInstanceVariable, "class1._ivar1", false, false},
53     {SymbolKind::ObjectiveCInstanceVariable, "class1._ivar2", false, false},
54     {SymbolKind::ObjectiveCInstanceVariable, "class1._ivar3", false, false},
55 };
56 
57 namespace TBDv2 {
58 
59 TEST(TBDv2, ReadFile) {
60   static const char tbd_v2_file1[] =
61       "--- !tapi-tbd-v2\n"
62       "archs: [ armv7, armv7s, armv7k, arm64 ]\n"
63       "platform: ios\n"
64       "flags: [ installapi ]\n"
65       "install-name: Test.dylib\n"
66       "current-version: 2.3.4\n"
67       "compatibility-version: 1.0\n"
68       "swift-version: 1.1\n"
69       "parent-umbrella: Umbrella.dylib\n"
70       "exports:\n"
71       "  - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
72       "    allowable-clients: [ clientA ]\n"
73       "    re-exports: [ /usr/lib/libfoo.dylib ]\n"
74       "    symbols: [ _sym1, _sym2, _sym3, _sym4, $ld$hide$os9.0$_sym1 ]\n"
75       "    objc-classes: [ _class1, _class2 ]\n"
76       "    objc-ivars: [ _class1._ivar1, _class1._ivar2 ]\n"
77       "    weak-def-symbols: [ _weak1, _weak2 ]\n"
78       "    thread-local-symbols: [ _tlv1, _tlv2 ]\n"
79       "  - archs: [ armv7, armv7s, armv7k ]\n"
80       "    symbols: [ _sym5 ]\n"
81       "    objc-classes: [ _class3 ]\n"
82       "    objc-ivars: [ _class1._ivar3 ]\n"
83       "    weak-def-symbols: [ _weak3 ]\n"
84       "    thread-local-symbols: [ _tlv3 ]\n"
85       "...\n";
86 
87   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v2_file1, "Test.tbd");
88   auto Result = TextAPIReader::get(std::move(Buffer));
89   EXPECT_TRUE(!!Result);
90   auto File = std::move(Result.get());
91   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
92   auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
93   EXPECT_EQ(Archs, File->getArchitectures());
94   EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
95   EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
96   EXPECT_EQ(PackedVersion(2, 3, 4), File->getCurrentVersion());
97   EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
98   EXPECT_EQ(2U, File->getSwiftABIVersion());
99   EXPECT_EQ(ObjCConstraintType::Retain_Release, File->getObjCConstraint());
100   EXPECT_TRUE(File->isTwoLevelNamespace());
101   EXPECT_TRUE(File->isApplicationExtensionSafe());
102   EXPECT_TRUE(File->isInstallAPI());
103   InterfaceFileRef client("clientA", Archs);
104   InterfaceFileRef reexport("/usr/lib/libfoo.dylib", Archs);
105   EXPECT_EQ(1U, File->allowableClients().size());
106   EXPECT_EQ(client, File->allowableClients().front());
107   EXPECT_EQ(1U, File->reexportedLibraries().size());
108   EXPECT_EQ(reexport, File->reexportedLibraries().front());
109 
110   ExportedSymbolSeq Exports;
111   for (const auto *Sym : File->symbols()) {
112     EXPECT_FALSE(Sym->isWeakReferenced());
113     EXPECT_FALSE(Sym->isUndefined());
114     Exports.emplace_back(ExportedSymbol{Sym->getKind(), Sym->getName(),
115                                         Sym->isWeakDefined(),
116                                         Sym->isThreadLocalValue()});
117   }
118   llvm::sort(Exports.begin(), Exports.end());
119 
120   EXPECT_EQ(sizeof(TBDv2Symbols) / sizeof(ExportedSymbol), Exports.size());
121   EXPECT_TRUE(
122       std::equal(Exports.begin(), Exports.end(), std::begin(TBDv2Symbols)));
123 }
124 
125 TEST(TBDv2, ReadFile2) {
126   static const char tbd_v2_file2[] =
127       "--- !tapi-tbd-v2\n"
128       "archs: [ armv7, armv7s, armv7k, arm64 ]\n"
129       "platform: ios\n"
130       "flags: [ flat_namespace, not_app_extension_safe ]\n"
131       "install-name: Test.dylib\n"
132       "swift-version: 1.1\n"
133       "exports:\n"
134       "  - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
135       "    symbols: [ _sym1, _sym2, _sym3, _sym4, $ld$hide$os9.0$_sym1 ]\n"
136       "    objc-classes: [ _class1, _class2 ]\n"
137       "    objc-ivars: [ _class1._ivar1, _class1._ivar2 ]\n"
138       "    weak-def-symbols: [ _weak1, _weak2 ]\n"
139       "    thread-local-symbols: [ _tlv1, _tlv2 ]\n"
140       "  - archs: [ armv7, armv7s, armv7k ]\n"
141       "    symbols: [ _sym5 ]\n"
142       "    objc-classes: [ _class3 ]\n"
143       "    objc-ivars: [ _class1._ivar3 ]\n"
144       "    weak-def-symbols: [ _weak3 ]\n"
145       "    thread-local-symbols: [ _tlv3 ]\n"
146       "undefineds:\n"
147       "  - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
148       "    symbols: [ _undefSym1, _undefSym2, _undefSym3 ]\n"
149       "    objc-classes: [ _undefClass1, _undefClass2 ]\n"
150       "    objc-ivars: [ _undefClass1._ivar1, _undefClass1._ivar2 ]\n"
151       "    weak-ref-symbols: [ _undefWeak1, _undefWeak2 ]\n"
152       "...\n";
153 
154   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v2_file2, "Test.tbd");
155   auto Result = TextAPIReader::get(std::move(Buffer));
156   EXPECT_TRUE(!!Result);
157   auto File = std::move(Result.get());
158   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
159   auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
160   EXPECT_EQ(Archs, File->getArchitectures());
161   EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
162   EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
163   EXPECT_EQ(PackedVersion(1, 0, 0), File->getCurrentVersion());
164   EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
165   EXPECT_EQ(2U, File->getSwiftABIVersion());
166   EXPECT_EQ(ObjCConstraintType::Retain_Release, File->getObjCConstraint());
167   EXPECT_FALSE(File->isTwoLevelNamespace());
168   EXPECT_FALSE(File->isApplicationExtensionSafe());
169   EXPECT_FALSE(File->isInstallAPI());
170   EXPECT_EQ(0U, File->allowableClients().size());
171   EXPECT_EQ(0U, File->reexportedLibraries().size());
172 }
173 
174 TEST(TBDv2, WriteFile) {
175   static const char tbd_v2_file3[] =
176       "--- !tapi-tbd-v2\n"
177       "archs:           [ i386, x86_64 ]\n"
178       "platform:        macosx\n"
179       "install-name:    '/usr/lib/libfoo.dylib'\n"
180       "current-version: 1.2.3\n"
181       "compatibility-version: 0\n"
182       "swift-version:   5\n"
183       "exports:\n"
184       "  - archs:           [ i386 ]\n"
185       "    symbols:         [ _sym1 ]\n"
186       "    weak-def-symbols: [ _sym2 ]\n"
187       "    thread-local-symbols: [ _sym3 ]\n"
188       "  - archs:           [ x86_64 ]\n"
189       "    allowable-clients: [ clientA ]\n"
190       "    re-exports:      [ '/usr/lib/libfoo.dylib' ]\n"
191       "    symbols:         [ '_OBJC_EHTYPE_$_Class1' ]\n"
192       "    objc-classes:    [ _Class1 ]\n"
193       "    objc-ivars:      [ _Class1._ivar1 ]\n"
194       "...\n";
195 
196   InterfaceFile File;
197   File.setPath("libfoo.dylib");
198   File.setInstallName("/usr/lib/libfoo.dylib");
199   File.setFileType(FileType::TBD_V2);
200   File.setArchitectures(AK_i386 | AK_x86_64);
201   File.setPlatform(PlatformKind::macOS);
202   File.setCurrentVersion(PackedVersion(1, 2, 3));
203   File.setTwoLevelNamespace();
204   File.setApplicationExtensionSafe();
205   File.setSwiftABIVersion(5);
206   File.setObjCConstraint(ObjCConstraintType::Retain_Release);
207   File.addAllowableClient("clientA", AK_x86_64);
208   File.addReexportedLibrary("/usr/lib/libfoo.dylib", AK_x86_64);
209   File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", AK_i386);
210   File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", AK_i386,
211                  SymbolFlags::WeakDefined);
212   File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", AK_i386,
213                  SymbolFlags::ThreadLocalValue);
214   File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", AK_x86_64);
215   File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", AK_x86_64);
216   File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1",
217                  AK_x86_64);
218 
219   SmallString<4096> Buffer;
220   raw_svector_ostream OS(Buffer);
221   auto Result = TextAPIWriter::writeToStream(OS, File);
222   EXPECT_FALSE(Result);
223   EXPECT_STREQ(tbd_v2_file3, Buffer.c_str());
224 }
225 
226 TEST(TBDv2, Platform_macOS) {
227   static const char tbd_v1_platform_macos[] = "--- !tapi-tbd-v2\n"
228                                               "archs: [ x86_64 ]\n"
229                                               "platform: macosx\n"
230                                               "install-name: Test.dylib\n"
231                                               "...\n";
232 
233   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_macos, "Test.tbd");
234   auto Result = TextAPIReader::get(std::move(Buffer));
235   EXPECT_TRUE(!!Result);
236   auto File = std::move(Result.get());
237   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
238   EXPECT_EQ(PlatformKind::macOS, File->getPlatform());
239 }
240 
241 TEST(TBDv2, Platform_iOS) {
242   static const char tbd_v1_platform_ios[] = "--- !tapi-tbd-v2\n"
243                                             "archs: [ arm64 ]\n"
244                                             "platform: ios\n"
245                                             "install-name: Test.dylib\n"
246                                             "...\n";
247 
248   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_ios, "Test.tbd");
249   auto Result = TextAPIReader::get(std::move(Buffer));
250   EXPECT_TRUE(!!Result);
251   auto File = std::move(Result.get());
252   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
253   EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
254 }
255 
256 TEST(TBDv2, Platform_watchOS) {
257   static const char tbd_v1_platform_watchos[] = "--- !tapi-tbd-v2\n"
258                                                 "archs: [ armv7k ]\n"
259                                                 "platform: watchos\n"
260                                                 "install-name: Test.dylib\n"
261                                                 "...\n";
262 
263   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_watchos, "Test.tbd");
264   auto Result = TextAPIReader::get(std::move(Buffer));
265   EXPECT_TRUE(!!Result);
266   auto File = std::move(Result.get());
267   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
268   EXPECT_EQ(PlatformKind::watchOS, File->getPlatform());
269 }
270 
271 TEST(TBDv2, Platform_tvOS) {
272   static const char tbd_v1_platform_tvos[] = "--- !tapi-tbd-v2\n"
273                                              "archs: [ arm64 ]\n"
274                                              "platform: tvos\n"
275                                              "install-name: Test.dylib\n"
276                                              "...\n";
277 
278   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_tvos, "Test.tbd");
279   auto Result = TextAPIReader::get(std::move(Buffer));
280   EXPECT_TRUE(!!Result);
281   auto File = std::move(Result.get());
282   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
283   EXPECT_EQ(PlatformKind::tvOS, File->getPlatform());
284 }
285 
286 TEST(TBDv2, Platform_bridgeOS) {
287   static const char tbd_v1_platform_bridgeos[] = "--- !tapi-tbd-v2\n"
288                                                  "archs: [ armv7k ]\n"
289                                                  "platform: bridgeos\n"
290                                                  "install-name: Test.dylib\n"
291                                                  "...\n";
292 
293   auto Buffer =
294       MemoryBuffer::getMemBuffer(tbd_v1_platform_bridgeos, "Test.tbd");
295   auto Result = TextAPIReader::get(std::move(Buffer));
296   EXPECT_TRUE(!!Result);
297   auto File = std::move(Result.get());
298   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
299   EXPECT_EQ(PlatformKind::bridgeOS, File->getPlatform());
300 }
301 
302 TEST(TBDv2, Swift_1_0) {
303   static const char tbd_v1_swift_1_0[] = "--- !tapi-tbd-v2\n"
304                                          "archs: [ arm64 ]\n"
305                                          "platform: ios\n"
306                                          "install-name: Test.dylib\n"
307                                          "swift-version: 1.0\n"
308                                          "...\n";
309 
310   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_1_0, "Test.tbd");
311   auto Result = TextAPIReader::get(std::move(Buffer));
312   EXPECT_TRUE(!!Result);
313   auto File = std::move(Result.get());
314   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
315   EXPECT_EQ(1U, File->getSwiftABIVersion());
316 }
317 
318 TEST(TBDv2, Swift_1_1) {
319   static const char tbd_v1_swift_1_1[] = "--- !tapi-tbd-v2\n"
320                                          "archs: [ arm64 ]\n"
321                                          "platform: ios\n"
322                                          "install-name: Test.dylib\n"
323                                          "swift-version: 1.1\n"
324                                          "...\n";
325 
326   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_1_1, "Test.tbd");
327   auto Result = TextAPIReader::get(std::move(Buffer));
328   EXPECT_TRUE(!!Result);
329   auto File = std::move(Result.get());
330   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
331   EXPECT_EQ(2U, File->getSwiftABIVersion());
332 }
333 
334 TEST(TBDv2, Swift_2_0) {
335   static const char tbd_v1_swift_2_0[] = "--- !tapi-tbd-v2\n"
336                                          "archs: [ arm64 ]\n"
337                                          "platform: ios\n"
338                                          "install-name: Test.dylib\n"
339                                          "swift-version: 2.0\n"
340                                          "...\n";
341 
342   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_2_0, "Test.tbd");
343   auto Result = TextAPIReader::get(std::move(Buffer));
344   EXPECT_TRUE(!!Result);
345   auto File = std::move(Result.get());
346   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
347   EXPECT_EQ(3U, File->getSwiftABIVersion());
348 }
349 
350 TEST(TBDv2, Swift_3_0) {
351   static const char tbd_v1_swift_3_0[] = "--- !tapi-tbd-v2\n"
352                                          "archs: [ arm64 ]\n"
353                                          "platform: ios\n"
354                                          "install-name: Test.dylib\n"
355                                          "swift-version: 3.0\n"
356                                          "...\n";
357 
358   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_3_0, "Test.tbd");
359   auto Result = TextAPIReader::get(std::move(Buffer));
360   EXPECT_TRUE(!!Result);
361   auto File = std::move(Result.get());
362   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
363   EXPECT_EQ(4U, File->getSwiftABIVersion());
364 }
365 
366 TEST(TBDv2, Swift_4_0) {
367   static const char tbd_v1_swift_4_0[] = "--- !tapi-tbd-v2\n"
368                                          "archs: [ arm64 ]\n"
369                                          "platform: ios\n"
370                                          "install-name: Test.dylib\n"
371                                          "swift-version: 4.0\n"
372                                          "...\n";
373 
374   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_4_0, "Test.tbd");
375   auto Result = TextAPIReader::get(std::move(Buffer));
376   EXPECT_FALSE(!!Result);
377   auto errorMessage = toString(Result.takeError());
378   EXPECT_EQ("malformed file\nTest.tbd:5:16: error: invalid Swift ABI "
379             "version.\nswift-version: 4.0\n               ^~~\n",
380             errorMessage);
381 }
382 
383 TEST(TBDv2, Swift_5) {
384   static const char tbd_v1_swift_5[] = "--- !tapi-tbd-v2\n"
385                                        "archs: [ arm64 ]\n"
386                                        "platform: ios\n"
387                                        "install-name: Test.dylib\n"
388                                        "swift-version: 5\n"
389                                        "...\n";
390 
391   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_5, "Test.tbd");
392   auto Result = TextAPIReader::get(std::move(Buffer));
393   EXPECT_TRUE(!!Result);
394   auto File = std::move(Result.get());
395   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
396   EXPECT_EQ(5U, File->getSwiftABIVersion());
397 }
398 
399 TEST(TBDv2, Swift_99) {
400   static const char tbd_v1_swift_99[] = "--- !tapi-tbd-v2\n"
401                                         "archs: [ arm64 ]\n"
402                                         "platform: ios\n"
403                                         "install-name: Test.dylib\n"
404                                         "swift-version: 99\n"
405                                         "...\n";
406 
407   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_99, "Test.tbd");
408   auto Result = TextAPIReader::get(std::move(Buffer));
409   EXPECT_TRUE(!!Result);
410   auto File = std::move(Result.get());
411   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
412   EXPECT_EQ(99U, File->getSwiftABIVersion());
413 }
414 
415 TEST(TBDv2, UnknownArchitecture) {
416   static const char tbd_v2_file_unknown_architecture[] =
417       "--- !tapi-tbd-v2\n"
418       "archs: [ foo ]\n"
419       "platform: macosx\n"
420       "install-name: Test.dylib\n"
421       "...\n";
422 
423   auto Buffer =
424       MemoryBuffer::getMemBuffer(tbd_v2_file_unknown_architecture, "Test.tbd");
425   auto Result = TextAPIReader::get(std::move(Buffer));
426   EXPECT_TRUE(!!Result);
427 }
428 
429 TEST(TBDv2, UnknownPlatform) {
430   static const char tbd_v2_file_unknown_platform[] = "--- !tapi-tbd-v2\n"
431                                                      "archs: [ i386 ]\n"
432                                                      "platform: newOS\n"
433                                                      "...\n";
434 
435   auto Buffer =
436       MemoryBuffer::getMemBuffer(tbd_v2_file_unknown_platform, "Test.tbd");
437   auto Result = TextAPIReader::get(std::move(Buffer));
438   EXPECT_FALSE(!!Result);
439   auto errorMessage = toString(Result.takeError());
440   EXPECT_EQ("malformed file\nTest.tbd:3:11: error: unknown platform\nplatform: "
441             "newOS\n          ^~~~~\n",
442             errorMessage);
443 }
444 
445 TEST(TBDv2, MalformedFile1) {
446   static const char malformed_file1[] = "--- !tapi-tbd-v2\n"
447                                         "archs: [ arm64 ]\n"
448                                         "foobar: \"Unsupported key\"\n"
449                                         "...\n";
450 
451   auto Buffer = MemoryBuffer::getMemBuffer(malformed_file1, "Test.tbd");
452   auto Result = TextAPIReader::get(std::move(Buffer));
453   EXPECT_FALSE(!!Result);
454   auto errorMessage = toString(Result.takeError());
455   ASSERT_EQ("malformed file\nTest.tbd:2:1: error: missing required key "
456             "'platform'\narchs: [ arm64 ]\n^\n",
457             errorMessage);
458 }
459 
460 TEST(TBDv2, MalformedFile2) {
461   static const char malformed_file2[] = "--- !tapi-tbd-v2\n"
462                                         "archs: [ arm64 ]\n"
463                                         "platform: ios\n"
464                                         "install-name: Test.dylib\n"
465                                         "foobar: \"Unsupported key\"\n"
466                                         "...\n";
467 
468   auto Buffer = MemoryBuffer::getMemBuffer(malformed_file2, "Test.tbd");
469   auto Result = TextAPIReader::get(std::move(Buffer));
470   EXPECT_FALSE(!!Result);
471   auto errorMessage = toString(Result.takeError());
472   ASSERT_EQ(
473       "malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
474       "\"Unsupported key\"\n        ^~~~~~~~~~~~~~~~~\n",
475       errorMessage);
476 }
477 
478 } // namespace TBDv2
479