Skip to content

Commit ad30a05

Browse files
authored
[NFC][Support] Add FormatVariadic sub-test for validation (llvm#106578)
- Add validation subtest that tests assert failures in assert enabled builds, and that validation is disabled in assert disabled builds.
1 parent b47d7ce commit ad30a05

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

llvm/unittests/Support/FormatVariadicTest.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,23 @@ TEST(FormatVariadicTest, FormatFilterRange) {
710710
EXPECT_EQ("1, 2, 3", formatv("{0}", Range).str());
711711
}
712712

713+
TEST(FormatVariadicTest, Validate) {
714+
#ifndef NDEBUG
715+
#if GTEST_HAS_DEATH_TEST
716+
// If asserts are enabled, verify that invalid formatv calls cause assertions.
717+
EXPECT_DEATH(formatv("{0}", 1, 2).str(), "Expected 1 Args, but got 2");
718+
EXPECT_DEATH(formatv("{0} {2}", 1, 2, 3).str(),
719+
"Replacement field indices cannot have holes");
720+
#else // GTEST_HAS_DEATH_TEST
721+
GTEST_SKIP() << "No support for EXPECT_DEATH";
722+
#endif // GTEST_HAS_DEATH_TEST
723+
#else // NDEBUG
724+
// If asserts are disabled, verify that validation is disabled.
725+
EXPECT_EQ(formatv("{0}", 1, 2).str(), "1");
726+
EXPECT_EQ(formatv("{0} {2}", 1, 2, 3).str(), "1 3");
727+
#endif // NDEBUG
728+
}
729+
713730
namespace {
714731

715732
enum class Base { First };

0 commit comments

Comments
 (0)