[libcxx] r286474 - Protect bitset tests under libcpp-no-exceptions

Roger Ferrer Ibanez via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 10 08:54:55 PST 2016


Author: rogfer01
Date: Thu Nov 10 10:54:55 2016
New Revision: 286474

URL: http://llvm.org/viewvc/llvm-project?rev=286474&view=rev
Log:
Protect bitset tests under libcpp-no-exceptions

Bitset tests feature a sequence of tests of increasing bitset sizes,
but these tests rely on exceptions when the bitset size is less than
50 elements.

This change adds a flag to tell whether a test should throw. If it must
throw it will be skipped under no-exceptions.

Differential Revision: https://reviews.llvm.org/D26140


Modified:
    libcxx/trunk/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp
    libcxx/trunk/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
    libcxx/trunk/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp
    libcxx/trunk/test/std/utilities/template.bitset/bitset.members/test.pass.cpp

Modified: libcxx/trunk/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp?rev=286474&r1=286473&r2=286474&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp Thu Nov 10 10:54:55 2016
@@ -7,13 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // test bitset<N>& flip(size_t pos);
 
 #include <bitset>
 #include <cstdlib>
 #include <cassert>
 
+#include "test_macros.h"
+
 template <std::size_t N>
 std::bitset<N>
 make_bitset()
@@ -25,11 +26,15 @@ make_bitset()
 }
 
 template <std::size_t N>
-void test_flip_one()
+void test_flip_one(bool test_throws)
 {
     std::bitset<N> v = make_bitset<N>();
+#ifdef TEST_HAS_NO_EXCEPTIONS
+    if (test_throws) return;
+#else
     try
     {
+#endif
         v.flip(50);
         bool b = v[50];
         if (50 >= v.size())
@@ -39,21 +44,25 @@ void test_flip_one()
         assert(v[50] != b);
         v.flip(50);
         assert(v[50] == b);
+        assert(!test_throws);
+#ifndef TEST_HAS_NO_EXCEPTIONS
     }
     catch (std::out_of_range&)
     {
+        assert(test_throws);
     }
+#endif
 }
 
 int main()
 {
-    test_flip_one<0>();
-    test_flip_one<1>();
-    test_flip_one<31>();
-    test_flip_one<32>();
-    test_flip_one<33>();
-    test_flip_one<63>();
-    test_flip_one<64>();
-    test_flip_one<65>();
-    test_flip_one<1000>();
+    test_flip_one<0>(true);
+    test_flip_one<1>(true);
+    test_flip_one<31>(true);
+    test_flip_one<32>(true);
+    test_flip_one<33>(true);
+    test_flip_one<63>(false);
+    test_flip_one<64>(false);
+    test_flip_one<65>(false);
+    test_flip_one<1000>(false);
 }

Modified: libcxx/trunk/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp?rev=286474&r1=286473&r2=286474&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp Thu Nov 10 10:54:55 2016
@@ -7,18 +7,23 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // test bitset<N>& reset(size_t pos);
 
 #include <bitset>
 #include <cassert>
 
+#include "test_macros.h"
+
 template <std::size_t N>
-void test_reset_one()
+void test_reset_one(bool test_throws)
 {
     std::bitset<N> v;
+#ifdef TEST_HAS_NO_EXCEPTIONS
+    if (test_throws) return;
+#else
     try
     {
+#endif
         v.set();
         v.reset(50);
         if (50 >= v.size())
@@ -28,21 +33,25 @@ void test_reset_one()
                 assert(!v[i]);
             else
                 assert(v[i]);
+        assert(!test_throws);
+#ifndef TEST_HAS_NO_EXCEPTIONS
     }
     catch (std::out_of_range&)
     {
+        assert(test_throws);
     }
+#endif
 }
 
 int main()
 {
-    test_reset_one<0>();
-    test_reset_one<1>();
-    test_reset_one<31>();
-    test_reset_one<32>();
-    test_reset_one<33>();
-    test_reset_one<63>();
-    test_reset_one<64>();
-    test_reset_one<65>();
-    test_reset_one<1000>();
+    test_reset_one<0>(true);
+    test_reset_one<1>(true);
+    test_reset_one<31>(true);
+    test_reset_one<32>(true);
+    test_reset_one<33>(true);
+    test_reset_one<63>(false);
+    test_reset_one<64>(false);
+    test_reset_one<65>(false);
+    test_reset_one<1000>(false);
 }

Modified: libcxx/trunk/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp?rev=286474&r1=286473&r2=286474&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp Thu Nov 10 10:54:55 2016
@@ -7,47 +7,60 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // test bitset<N>& set(size_t pos, bool val = true);
 
 #include <bitset>
 #include <cassert>
 
+#include "test_macros.h"
+
 template <std::size_t N>
-void test_set_one()
+void test_set_one(bool test_throws)
 {
     std::bitset<N> v;
+#ifdef TEST_HAS_NO_EXCEPTIONS
+    if (test_throws) return;
+#else
     try
+#endif
     {
         v.set(50);
         if (50 >= v.size())
             assert(false);
         assert(v[50]);
+        assert(!test_throws);
     }
+#ifndef TEST_HAS_NO_EXCEPTIONS
     catch (std::out_of_range&)
     {
+        assert(test_throws);
     }
     try
+#endif
     {
         v.set(50, false);
         if (50 >= v.size())
             assert(false);
         assert(!v[50]);
+        assert(!test_throws);
     }
+#ifndef TEST_HAS_NO_EXCEPTIONS
     catch (std::out_of_range&)
     {
+        assert(test_throws);
     }
+#endif
 }
 
 int main()
 {
-    test_set_one<0>();
-    test_set_one<1>();
-    test_set_one<31>();
-    test_set_one<32>();
-    test_set_one<33>();
-    test_set_one<63>();
-    test_set_one<64>();
-    test_set_one<65>();
-    test_set_one<1000>();
+    test_set_one<0>(true);
+    test_set_one<1>(true);
+    test_set_one<31>(true);
+    test_set_one<32>(true);
+    test_set_one<33>(true);
+    test_set_one<63>(false);
+    test_set_one<64>(false);
+    test_set_one<65>(false);
+    test_set_one<1000>(false);
 }

Modified: libcxx/trunk/test/std/utilities/template.bitset/bitset.members/test.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/template.bitset/bitset.members/test.pass.cpp?rev=286474&r1=286473&r2=286474&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/template.bitset/bitset.members/test.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/template.bitset/bitset.members/test.pass.cpp Thu Nov 10 10:54:55 2016
@@ -7,13 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // test constexpr bool test(size_t pos) const;
 
 #include <bitset>
 #include <cstdlib>
 #include <cassert>
 
+#include "test_macros.h"
+
 template <std::size_t N>
 std::bitset<N>
 make_bitset()
@@ -25,30 +26,38 @@ make_bitset()
 }
 
 template <std::size_t N>
-void test_test()
+void test_test(bool test_throws)
 {
     const std::bitset<N> v1 = make_bitset<N>();
+#ifdef TEST_HAS_NO_EXCEPTIONS
+    if (test_throws) return;
+#else
     try
     {
+#endif
         bool b = v1.test(50);
         if (50 >= v1.size())
             assert(false);
         assert(b == v1[50]);
+        assert(!test_throws);
+#ifndef TEST_HAS_NO_EXCEPTIONS
     }
     catch (std::out_of_range&)
     {
+        assert(test_throws);
     }
+#endif
 }
 
 int main()
 {
-    test_test<0>();
-    test_test<1>();
-    test_test<31>();
-    test_test<32>();
-    test_test<33>();
-    test_test<63>();
-    test_test<64>();
-    test_test<65>();
-    test_test<1000>();
+    test_test<0>(true);
+    test_test<1>(true);
+    test_test<31>(true);
+    test_test<32>(true);
+    test_test<33>(true);
+    test_test<63>(false);
+    test_test<64>(false);
+    test_test<65>(false);
+    test_test<1000>(false);
 }




More information about the cfe-commits mailing list