Skip to content

[NFC][Support] Add FormatVariadic sub-test for validation #106578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions llvm/unittests/Support/FormatVariadicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,23 @@ TEST(FormatVariadicTest, FormatFilterRange) {
EXPECT_EQ("1, 2, 3", formatv("{0}", Range).str());
}

TEST(FormatVariadicTest, Validate) {
#ifndef NDEBUG
#if GTEST_HAS_DEATH_TEST
// If asserts are enabled, verify that invalid formatv calls cause assertions.
EXPECT_DEATH(formatv("{0}", 1, 2).str(), "Expected 1 Args, but got 2");
EXPECT_DEATH(formatv("{0} {2}", 1, 2, 3).str(),
"Replacement field indices cannot have holes");
#else // GTEST_HAS_DEATH_TEST
GTEST_SKIP() << "No support for EXPECT_DEATH";
#endif // GTEST_HAS_DEATH_TEST
#else // NDEBUG
// If asserts are disabled, verify that validation is disabled.
EXPECT_EQ(formatv("{0}", 1, 2).str(), "1");
EXPECT_EQ(formatv("{0} {2}", 1, 2, 3).str(), "1 3");
#endif // NDEBUG
}

namespace {

enum class Base { First };
Expand Down
Loading