summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/TarWriterTest.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2017-12-05 10:09:59 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2017-12-05 10:09:59 +0000
commitf91f0b0af790043956e9224564844f7545579cb7 (patch)
tree7131bc994fc78157b208cae8296481b08fff7c10 /llvm/unittests/Support/TarWriterTest.cpp
parentfe52e0064bcc288a52b952302e147fe7a66d82f7 (diff)
downloadbcm5719-llvm-f91f0b0af790043956e9224564844f7545579cb7.tar.gz
bcm5719-llvm-f91f0b0af790043956e9224564844f7545579cb7.zip
[Support/TarWriter] - Don't allow TarWriter to add the same file more than once.
This is for PR35460. Currently when LLD adds files to TarWriter it may pass the same file multiple times. For example it happens for clang reproduce file which specifies archive (.a) files more than once in command line. Patch makes TarWriter to ignore files with the same path, so it will add only the first one to archive. Differential revision: https://reviews.llvm.org/D40606 llvm-svn: 319750
Diffstat (limited to 'llvm/unittests/Support/TarWriterTest.cpp')
-rw-r--r--llvm/unittests/Support/TarWriterTest.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/llvm/unittests/Support/TarWriterTest.cpp b/llvm/unittests/Support/TarWriterTest.cpp
index 6007e73ffaf..548efcade93 100644
--- a/llvm/unittests/Support/TarWriterTest.cpp
+++ b/llvm/unittests/Support/TarWriterTest.cpp
@@ -120,4 +120,60 @@ TEST_F(TarWriterTest, Pax) {
StringRef Pax = StringRef((char *)(Buf.data() + 512), 512);
EXPECT_TRUE(Pax.startswith("211 path=/" + std::string(200, 'x')));
}
+
+TEST_F(TarWriterTest, SingleFile) {
+ SmallString<128> Path;
+ std::error_code EC =
+ sys::fs::createTemporaryFile("TarWriterTest", "tar", Path);
+ EXPECT_FALSE((bool)EC);
+
+ Expected<std::unique_ptr<TarWriter>> TarOrErr = TarWriter::create(Path, "");
+ EXPECT_TRUE((bool)TarOrErr);
+ std::unique_ptr<TarWriter> Tar = std::move(*TarOrErr);
+ Tar->append("FooPath", "foo");
+ Tar.reset();
+
+ uint64_t TarSize;
+ EC = sys::fs::file_size(Path, TarSize);
+ EXPECT_FALSE((bool)EC);
+ EXPECT_EQ(TarSize, 2048);
+}
+
+TEST_F(TarWriterTest, NoDuplicate) {
+ SmallString<128> Path;
+ std::error_code EC =
+ sys::fs::createTemporaryFile("TarWriterTest", "tar", Path);
+ EXPECT_FALSE((bool)EC);
+
+ Expected<std::unique_ptr<TarWriter>> TarOrErr = TarWriter::create(Path, "");
+ EXPECT_TRUE((bool)TarOrErr);
+ std::unique_ptr<TarWriter> Tar = std::move(*TarOrErr);
+ Tar->append("FooPath", "foo");
+ Tar->append("BarPath", "bar");
+ Tar.reset();
+
+ uint64_t TarSize;
+ EC = sys::fs::file_size(Path, TarSize);
+ EXPECT_FALSE((bool)EC);
+ EXPECT_EQ(TarSize, 3072);
+}
+
+TEST_F(TarWriterTest, Duplicate) {
+ SmallString<128> Path;
+ std::error_code EC =
+ sys::fs::createTemporaryFile("TarWriterTest", "tar", Path);
+ EXPECT_FALSE((bool)EC);
+
+ Expected<std::unique_ptr<TarWriter>> TarOrErr = TarWriter::create(Path, "");
+ EXPECT_TRUE((bool)TarOrErr);
+ std::unique_ptr<TarWriter> Tar = std::move(*TarOrErr);
+ Tar->append("FooPath", "foo");
+ Tar->append("FooPath", "bar");
+ Tar.reset();
+
+ uint64_t TarSize;
+ EC = sys::fs::file_size(Path, TarSize);
+ EXPECT_FALSE((bool)EC);
+ EXPECT_EQ(TarSize, 2048);
}
+} // namespace
OpenPOWER on IntegriCloud