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