Protect bitset tests under libcpp-no-exceptions
authorRoger Ferrer Ibanez <roger.ferreribanez@arm.com>
Thu, 10 Nov 2016 16:54:55 +0000 (16:54 +0000)
committerRoger Ferrer Ibanez <roger.ferreribanez@arm.com>
Thu, 10 Nov 2016 16:54:55 +0000 (16:54 +0000)
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

llvm-svn: 286474

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

index 88ce8e943caf1c317c215def98d3ec4dbd45de1d..18a64a214a45953fd4551aa4487ed8ae4ea678f5 100644 (file)
@@ -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);
 }
index f01d35b9a33c386668f81bf9ac489a23f361a7aa..6847694e4b73d5ca4abf1b61d5b9b41da15c3bcf 100644 (file)
@@ -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);
 }
index debe5431d8d047bb453792e63c526f3475aa8d77..1c8d6a1c32a4e221b9dff1f254ed2915a5831426 100644 (file)
@@ -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);
 }
index 161afd11c291d413fd2334dfaeaa79b16b128053..1a2d70613e1f55bedd60e640989066973c1aab1f 100644 (file)
@@ -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);
 }