TextStubV2Tests.cpp 19 KB

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