TextStubV3Tests.cpp 20 KB

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