diff --git a/llvm/unittests/TextAPI/TextStubV3Tests.cpp b/llvm/unittests/TextAPI/TextStubV3Tests.cpp --- a/llvm/unittests/TextAPI/TextStubV3Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV3Tests.cpp @@ -34,6 +34,11 @@ std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue); } +inline std::string stripWhitespace(std::string s) { + s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end()); + return s; +} + static ExportedSymbol TBDv3Symbols[] = { {SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false}, {SymbolKind::GlobalSymbol, "_sym1", false, false}, @@ -204,6 +209,12 @@ EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(File->getPlatforms().size(), 1U); EXPECT_EQ(Platform, *File->getPlatforms().begin()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_macos), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Platform_iOS) { @@ -221,6 +232,12 @@ EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(File->getPlatforms().size(), 1U); EXPECT_EQ(Platform, *File->getPlatforms().begin()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_ios), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Platform_watchOS) { @@ -238,6 +255,12 @@ EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(File->getPlatforms().size(), 1U); EXPECT_EQ(Platform, *File->getPlatforms().begin()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_watchos), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Platform_tvOS) { @@ -255,6 +278,12 @@ EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(File->getPlatforms().size(), 1U); EXPECT_EQ(Platform, *File->getPlatforms().begin()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_tvos), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Platform_bridgeOS) { @@ -272,6 +301,12 @@ EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(File->getPlatforms().size(), 1U); EXPECT_EQ(Platform, *File->getPlatforms().begin()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_bridgeos), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Platform_macCatalyst) { @@ -288,6 +323,14 @@ auto File = std::move(Result.get()); EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(Platform, *File->getPlatforms().begin()); + +#if 0 + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_iosmac), stripWhitespace(Buffer.c_str())); +#endif } TEST(TBDv3, Platform_zippered) { @@ -309,6 +352,12 @@ EXPECT_EQ(Platforms.size(), File->getPlatforms().size()); for (auto Platform : File->getPlatforms()) EXPECT_EQ(Platforms.count(Platform), 1U); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_platform_zip), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Swift_1_0) { @@ -325,6 +374,12 @@ auto File = std::move(Result.get()); EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(1U, File->getSwiftABIVersion()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_swift_1_0), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Swift_1_1) { @@ -341,6 +396,12 @@ auto File = std::move(Result.get()); EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(2U, File->getSwiftABIVersion()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_swift_1_1), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Swift_2_0) { @@ -357,6 +418,12 @@ auto File = std::move(Result.get()); EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(3U, File->getSwiftABIVersion()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_swift_2_0), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Swift_3_0) { @@ -373,6 +440,12 @@ auto File = std::move(Result.get()); EXPECT_EQ(FileType::TBD_V3, File->getFileType()); EXPECT_EQ(4U, File->getSwiftABIVersion()); + + SmallString<4096> Buffer; + raw_svector_ostream OS(Buffer); + auto WriteResult = TextAPIWriter::writeToStream(OS, *File); + EXPECT_TRUE(!WriteResult); + EXPECT_EQ(stripWhitespace(tbd_v3_swift_3_0), stripWhitespace(Buffer.c_str())); } TEST(TBDv3, Swift_4_0) {