Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented Aug 29, 2024

  • Add validation subtest that tests assert failures in assert enabled
    builds, and that validation is disabled in assert disabled builds.

- Add validation subtest that tests assert failures in assert enabled
  builds, and that validation is disabled in assert disabled builds.
@jurahul jurahul marked this pull request as ready for review August 29, 2024 19:13
@jurahul jurahul requested review from joker-eph and jpienaar August 29, 2024 19:13
@llvmbot
Copy link
Member

llvmbot commented Aug 29, 2024

@llvm/pr-subscribers-llvm-support

Author: Rahul Joshi (jurahul)

Changes
  • Add validation subtest that tests assert failures in assert enabled builds,
    and that validation is disabled in assert disabled builds.

Full diff: https://github.com/llvm/llvm-project/pull/106578.diff

1 Files Affected:

  • (modified) llvm/unittests/Support/FormatVariadicTest.cpp (+17)
diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp
index 6ee0d924867419..7f1e09b1857dde 100644
--- a/llvm/unittests/Support/FormatVariadicTest.cpp
+++ b/llvm/unittests/Support/FormatVariadicTest.cpp
@@ -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 };

@jurahul jurahul merged commit ad30a05 into llvm:main Sep 2, 2024
@jurahul jurahul deleted the add_formatvariadic_validate_test branch September 2, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants