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 // Disable test for windows.
175 #ifndef _WIN32
176 TEST(TBDv2, WriteFile) {
177   static const char tbd_v2_file3[] =
178       "--- !tapi-tbd-v2\n"
179       "archs:           [ i386, x86_64 ]\n"
180       "platform:        macosx\n"
181       "install-name:    '/usr/lib/libfoo.dylib'\n"
182       "current-version: 1.2.3\n"
183       "compatibility-version: 0\n"
184       "swift-version:   5\n"
185       "exports:         \n"
186       "  - archs:           [ i386 ]\n"
187       "    symbols:         [ _sym1 ]\n"
188       "    weak-def-symbols: [ _sym2 ]\n"
189       "    thread-local-symbols: [ _sym3 ]\n"
190       "  - archs:           [ x86_64 ]\n"
191       "    allowable-clients: [ clientA ]\n"
192       "    re-exports:      [ '/usr/lib/libfoo.dylib' ]\n"
193       "    symbols:         [ '_OBJC_EHTYPE_$_Class1' ]\n"
194       "    objc-classes:    [ _Class1 ]\n"
195       "    objc-ivars:      [ _Class1._ivar1 ]\n"
196       "...\n";
197 
198   InterfaceFile File;
199   File.setPath("libfoo.dylib");
200   File.setInstallName("/usr/lib/libfoo.dylib");
201   File.setFileType(FileType::TBD_V2);
202   File.setArchitectures(AK_i386 | AK_x86_64);
203   File.setPlatform(PlatformKind::macOS);
204   File.setCurrentVersion(PackedVersion(1, 2, 3));
205   File.setTwoLevelNamespace();
206   File.setApplicationExtensionSafe();
207   File.setSwiftABIVersion(5);
208   File.setObjCConstraint(ObjCConstraintType::Retain_Release);
209   File.addAllowableClient("clientA", AK_x86_64);
210   File.addReexportedLibrary("/usr/lib/libfoo.dylib", AK_x86_64);
211   File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", AK_i386);
212   File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", AK_i386,
213                  SymbolFlags::WeakDefined);
214   File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", AK_i386,
215                  SymbolFlags::ThreadLocalValue);
216   File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", AK_x86_64);
217   File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", AK_x86_64);
218   File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1",
219                  AK_x86_64);
220 
221   SmallString<4096> Buffer;
222   raw_svector_ostream OS(Buffer);
223   auto Result = TextAPIWriter::writeToStream(OS, File);
224   EXPECT_FALSE(Result);
225   EXPECT_STREQ(tbd_v2_file3, Buffer.c_str());
226 }
227 #endif // _WIN32
228 
229 TEST(TBDv2, Platform_macOS) {
230   static const char tbd_v1_platform_macos[] = "--- !tapi-tbd-v2\n"
231                                               "archs: [ x86_64 ]\n"
232                                               "platform: macosx\n"
233                                               "install-name: Test.dylib\n"
234                                               "...\n";
235 
236   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_macos, "Test.tbd");
237   auto Result = TextAPIReader::get(std::move(Buffer));
238   EXPECT_TRUE(!!Result);
239   auto File = std::move(Result.get());
240   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
241   EXPECT_EQ(PlatformKind::macOS, File->getPlatform());
242 }
243 
244 TEST(TBDv2, Platform_iOS) {
245   static const char tbd_v1_platform_ios[] = "--- !tapi-tbd-v2\n"
246                                             "archs: [ arm64 ]\n"
247                                             "platform: ios\n"
248                                             "install-name: Test.dylib\n"
249                                             "...\n";
250 
251   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_ios, "Test.tbd");
252   auto Result = TextAPIReader::get(std::move(Buffer));
253   EXPECT_TRUE(!!Result);
254   auto File = std::move(Result.get());
255   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
256   EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
257 }
258 
259 TEST(TBDv2, Platform_watchOS) {
260   static const char tbd_v1_platform_watchos[] = "--- !tapi-tbd-v2\n"
261                                                 "archs: [ armv7k ]\n"
262                                                 "platform: watchos\n"
263                                                 "install-name: Test.dylib\n"
264                                                 "...\n";
265 
266   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_watchos, "Test.tbd");
267   auto Result = TextAPIReader::get(std::move(Buffer));
268   EXPECT_TRUE(!!Result);
269   auto File = std::move(Result.get());
270   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
271   EXPECT_EQ(PlatformKind::watchOS, File->getPlatform());
272 }
273 
274 TEST(TBDv2, Platform_tvOS) {
275   static const char tbd_v1_platform_tvos[] = "--- !tapi-tbd-v2\n"
276                                              "archs: [ arm64 ]\n"
277                                              "platform: tvos\n"
278                                              "install-name: Test.dylib\n"
279                                              "...\n";
280 
281   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_platform_tvos, "Test.tbd");
282   auto Result = TextAPIReader::get(std::move(Buffer));
283   EXPECT_TRUE(!!Result);
284   auto File = std::move(Result.get());
285   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
286   EXPECT_EQ(PlatformKind::tvOS, File->getPlatform());
287 }
288 
289 TEST(TBDv2, Platform_bridgeOS) {
290   static const char tbd_v1_platform_bridgeos[] = "--- !tapi-tbd-v2\n"
291                                                  "archs: [ armv7k ]\n"
292                                                  "platform: bridgeos\n"
293                                                  "install-name: Test.dylib\n"
294                                                  "...\n";
295 
296   auto Buffer =
297       MemoryBuffer::getMemBuffer(tbd_v1_platform_bridgeos, "Test.tbd");
298   auto Result = TextAPIReader::get(std::move(Buffer));
299   EXPECT_TRUE(!!Result);
300   auto File = std::move(Result.get());
301   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
302   EXPECT_EQ(PlatformKind::bridgeOS, File->getPlatform());
303 }
304 
305 TEST(TBDv2, Swift_1_0) {
306   static const char tbd_v1_swift_1_0[] = "--- !tapi-tbd-v2\n"
307                                          "archs: [ arm64 ]\n"
308                                          "platform: ios\n"
309                                          "install-name: Test.dylib\n"
310                                          "swift-version: 1.0\n"
311                                          "...\n";
312 
313   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_1_0, "Test.tbd");
314   auto Result = TextAPIReader::get(std::move(Buffer));
315   EXPECT_TRUE(!!Result);
316   auto File = std::move(Result.get());
317   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
318   EXPECT_EQ(1U, File->getSwiftABIVersion());
319 }
320 
321 TEST(TBDv2, Swift_1_1) {
322   static const char tbd_v1_swift_1_1[] = "--- !tapi-tbd-v2\n"
323                                          "archs: [ arm64 ]\n"
324                                          "platform: ios\n"
325                                          "install-name: Test.dylib\n"
326                                          "swift-version: 1.1\n"
327                                          "...\n";
328 
329   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_1_1, "Test.tbd");
330   auto Result = TextAPIReader::get(std::move(Buffer));
331   EXPECT_TRUE(!!Result);
332   auto File = std::move(Result.get());
333   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
334   EXPECT_EQ(2U, File->getSwiftABIVersion());
335 }
336 
337 TEST(TBDv2, Swift_2_0) {
338   static const char tbd_v1_swift_2_0[] = "--- !tapi-tbd-v2\n"
339                                          "archs: [ arm64 ]\n"
340                                          "platform: ios\n"
341                                          "install-name: Test.dylib\n"
342                                          "swift-version: 2.0\n"
343                                          "...\n";
344 
345   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_2_0, "Test.tbd");
346   auto Result = TextAPIReader::get(std::move(Buffer));
347   EXPECT_TRUE(!!Result);
348   auto File = std::move(Result.get());
349   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
350   EXPECT_EQ(3U, File->getSwiftABIVersion());
351 }
352 
353 TEST(TBDv2, Swift_3_0) {
354   static const char tbd_v1_swift_3_0[] = "--- !tapi-tbd-v2\n"
355                                          "archs: [ arm64 ]\n"
356                                          "platform: ios\n"
357                                          "install-name: Test.dylib\n"
358                                          "swift-version: 3.0\n"
359                                          "...\n";
360 
361   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_3_0, "Test.tbd");
362   auto Result = TextAPIReader::get(std::move(Buffer));
363   EXPECT_TRUE(!!Result);
364   auto File = std::move(Result.get());
365   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
366   EXPECT_EQ(4U, File->getSwiftABIVersion());
367 }
368 
369 TEST(TBDv2, Swift_4_0) {
370   static const char tbd_v1_swift_4_0[] = "--- !tapi-tbd-v2\n"
371                                          "archs: [ arm64 ]\n"
372                                          "platform: ios\n"
373                                          "install-name: Test.dylib\n"
374                                          "swift-version: 4.0\n"
375                                          "...\n";
376 
377   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_4_0, "Test.tbd");
378   auto Result = TextAPIReader::get(std::move(Buffer));
379   EXPECT_FALSE(!!Result);
380   auto errorMessage = toString(Result.takeError());
381   EXPECT_EQ("malformed file\nTest.tbd:5:16: error: invalid Swift ABI "
382             "version.\nswift-version: 4.0\n               ^~~\n",
383             errorMessage);
384 }
385 
386 TEST(TBDv2, Swift_5) {
387   static const char tbd_v1_swift_5[] = "--- !tapi-tbd-v2\n"
388                                        "archs: [ arm64 ]\n"
389                                        "platform: ios\n"
390                                        "install-name: Test.dylib\n"
391                                        "swift-version: 5\n"
392                                        "...\n";
393 
394   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_5, "Test.tbd");
395   auto Result = TextAPIReader::get(std::move(Buffer));
396   EXPECT_TRUE(!!Result);
397   auto File = std::move(Result.get());
398   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
399   EXPECT_EQ(5U, File->getSwiftABIVersion());
400 }
401 
402 TEST(TBDv2, Swift_99) {
403   static const char tbd_v1_swift_99[] = "--- !tapi-tbd-v2\n"
404                                         "archs: [ arm64 ]\n"
405                                         "platform: ios\n"
406                                         "install-name: Test.dylib\n"
407                                         "swift-version: 99\n"
408                                         "...\n";
409 
410   auto Buffer = MemoryBuffer::getMemBuffer(tbd_v1_swift_99, "Test.tbd");
411   auto Result = TextAPIReader::get(std::move(Buffer));
412   EXPECT_TRUE(!!Result);
413   auto File = std::move(Result.get());
414   EXPECT_EQ(FileType::TBD_V2, File->getFileType());
415   EXPECT_EQ(99U, File->getSwiftABIVersion());
416 }
417 
418 TEST(TBDv2, UnknownArchitecture) {
419   static const char tbd_v2_file_unknown_architecture[] =
420       "--- !tapi-tbd-v2\n"
421       "archs: [ foo ]\n"
422       "platform: macosx\n"
423       "install-name: Test.dylib\n"
424       "...\n";
425 
426   auto Buffer =
427       MemoryBuffer::getMemBuffer(tbd_v2_file_unknown_architecture, "Test.tbd");
428   auto Result = TextAPIReader::get(std::move(Buffer));
429   EXPECT_TRUE(!!Result);
430 }
431 
432 TEST(TBDv2, UnknownPlatform) {
433   static const char tbd_v2_file_unknown_platform[] = "--- !tapi-tbd-v2\n"
434                                                      "archs: [ i386 ]\n"
435                                                      "platform: newOS\n"
436                                                      "...\n";
437 
438   auto Buffer =
439       MemoryBuffer::getMemBuffer(tbd_v2_file_unknown_platform, "Test.tbd");
440   auto Result = TextAPIReader::get(std::move(Buffer));
441   EXPECT_FALSE(!!Result);
442   auto errorMessage = toString(Result.takeError());
443   EXPECT_EQ("malformed file\nTest.tbd:3:11: error: unknown platform\nplatform: "
444             "newOS\n          ^~~~~\n",
445             errorMessage);
446 }
447 
448 TEST(TBDv2, MalformedFile1) {
449   static const char malformed_file1[] = "--- !tapi-tbd-v2\n"
450                                         "archs: [ arm64 ]\n"
451                                         "foobar: \"Unsupported key\"\n"
452                                         "...\n";
453 
454   auto Buffer = MemoryBuffer::getMemBuffer(malformed_file1, "Test.tbd");
455   auto Result = TextAPIReader::get(std::move(Buffer));
456   EXPECT_FALSE(!!Result);
457   auto errorMessage = toString(Result.takeError());
458   ASSERT_EQ("malformed file\nTest.tbd:2:1: error: missing required key "
459             "'platform'\narchs: [ arm64 ]\n^\n",
460             errorMessage);
461 }
462 
463 TEST(TBDv2, MalformedFile2) {
464   static const char malformed_file2[] = "--- !tapi-tbd-v2\n"
465                                         "archs: [ arm64 ]\n"
466                                         "platform: ios\n"
467                                         "install-name: Test.dylib\n"
468                                         "foobar: \"Unsupported key\"\n"
469                                         "...\n";
470 
471   auto Buffer = MemoryBuffer::getMemBuffer(malformed_file2, "Test.tbd");
472   auto Result = TextAPIReader::get(std::move(Buffer));
473   EXPECT_FALSE(!!Result);
474   auto errorMessage = toString(Result.takeError());
475   ASSERT_EQ(
476       "malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
477       "\"Unsupported key\"\n        ^~~~~~~~~~~~~~~~~\n",
478       errorMessage);
479 }
480 
481 } // namespace TBDv2
482