diff options
Diffstat (limited to 'unittests/Support')
-rw-r--r-- | unittests/Support/CachePruningTest.cpp | 34 | ||||
-rw-r--r-- | unittests/Support/CommandLineTest.cpp | 6 | ||||
-rw-r--r-- | unittests/Support/ErrorTest.cpp | 4 |
3 files changed, 40 insertions, 4 deletions
diff --git a/unittests/Support/CachePruningTest.cpp b/unittests/Support/CachePruningTest.cpp index 04ac0d09b4935..1bb57871925c2 100644 --- a/unittests/Support/CachePruningTest.cpp +++ b/unittests/Support/CachePruningTest.cpp @@ -18,7 +18,7 @@ TEST(CachePruningPolicyParser, Empty) { ASSERT_TRUE(bool(P)); EXPECT_EQ(std::chrono::seconds(1200), P->Interval); EXPECT_EQ(std::chrono::hours(7 * 24), P->Expiration); - EXPECT_EQ(75u, P->PercentageOfAvailableSpace); + EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace); } TEST(CachePruningPolicyParser, Interval) { @@ -39,10 +39,30 @@ TEST(CachePruningPolicyParser, Expiration) { EXPECT_EQ(std::chrono::seconds(1), P->Expiration); } -TEST(CachePruningPolicyParser, PercentageOfAvailableSpace) { +TEST(CachePruningPolicyParser, MaxSizePercentageOfAvailableSpace) { auto P = parseCachePruningPolicy("cache_size=100%"); ASSERT_TRUE(bool(P)); - EXPECT_EQ(100u, P->PercentageOfAvailableSpace); + EXPECT_EQ(100u, P->MaxSizePercentageOfAvailableSpace); + EXPECT_EQ(0u, P->MaxSizeBytes); +} + +TEST(CachePruningPolicyParser, MaxSizeBytes) { + auto P = parseCachePruningPolicy("cache_size_bytes=1"); + ASSERT_TRUE(bool(P)); + EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace); + EXPECT_EQ(1u, P->MaxSizeBytes); + P = parseCachePruningPolicy("cache_size_bytes=2k"); + ASSERT_TRUE(bool(P)); + EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace); + EXPECT_EQ(2u * 1024u, P->MaxSizeBytes); + P = parseCachePruningPolicy("cache_size_bytes=3m"); + ASSERT_TRUE(bool(P)); + EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace); + EXPECT_EQ(3u * 1024u * 1024u, P->MaxSizeBytes); + P = parseCachePruningPolicy("cache_size_bytes=4G"); + ASSERT_TRUE(bool(P)); + EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace); + EXPECT_EQ(4ull * 1024ull * 1024ull * 1024ull, P->MaxSizeBytes); } TEST(CachePruningPolicyParser, Multiple) { @@ -50,7 +70,7 @@ TEST(CachePruningPolicyParser, Multiple) { ASSERT_TRUE(bool(P)); EXPECT_EQ(std::chrono::seconds(1200), P->Interval); EXPECT_EQ(std::chrono::seconds(1), P->Expiration); - EXPECT_EQ(50u, P->PercentageOfAvailableSpace); + EXPECT_EQ(50u, P->MaxSizePercentageOfAvailableSpace); } TEST(CachePruningPolicyParser, Errors) { @@ -66,6 +86,12 @@ TEST(CachePruningPolicyParser, Errors) { toString(parseCachePruningPolicy("cache_size=foo%").takeError())); EXPECT_EQ("'101' must be between 0 and 100", toString(parseCachePruningPolicy("cache_size=101%").takeError())); + EXPECT_EQ( + "'foo' not an integer", + toString(parseCachePruningPolicy("cache_size_bytes=foo").takeError())); + EXPECT_EQ( + "'foo' not an integer", + toString(parseCachePruningPolicy("cache_size_bytes=foom").takeError())); EXPECT_EQ("Unknown key: 'foo'", toString(parseCachePruningPolicy("foo=bar").takeError())); } diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index f9dc3930df8c6..660df11446acb 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -13,6 +13,7 @@ #include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Program.h" #include "llvm/Support/StringSaver.h" #include "gtest/gtest.h" #include <fstream> @@ -546,6 +547,11 @@ TEST(CommandLineTest, GetRegisteredSubcommands) { } } +TEST(CommandLineTest, ArgumentLimit) { + std::string args(32 * 4096, 'a'); + EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data())); +} + TEST(CommandLineTest, ResponseFiles) { llvm::SmallString<128> TestDir; std::error_code EC = diff --git a/unittests/Support/ErrorTest.cpp b/unittests/Support/ErrorTest.cpp index 382346cd231ac..299fc50b46979 100644 --- a/unittests/Support/ErrorTest.cpp +++ b/unittests/Support/ErrorTest.cpp @@ -475,6 +475,10 @@ TEST(Error, CantFailSuccess) { int X = cantFail(Expected<int>(42)); EXPECT_EQ(X, 42) << "Expected value modified by cantFail"; + + int Dummy = 42; + int &Y = cantFail(Expected<int&>(Dummy)); + EXPECT_EQ(&Dummy, &Y) << "Reference mangled by cantFail"; } // Test that cantFail results in a crash if you pass it a failure value. |