Protect exceptional paths under libcpp-no-exceptions
These tests are of the form
try {
action-that-may-throw
assert(!exceptional-condition)
assert(some-other-facts)
} catch (relevant-exception) {
assert(exceptional-condition)
}
Under libcpp-no-exceptions there is still value in verifying
some-other-facts while avoiding the exceptional case. So for these tests
just conditionally check some-other-facts if exceptional-condition is
false. When exception are supported make sure that a true
exceptional-condition throws an exception
Differential Revision: https://reviews.llvm.org/D26136
llvm-svn: 285697
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XFAIL: libcpp-no-exceptions
|
||||
// <string>
|
||||
|
||||
// template <typename T>
|
||||
@@ -22,6 +21,8 @@
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int sign(int x)
|
||||
{
|
||||
if (x == 0)
|
||||
@@ -37,16 +38,22 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
SV sv, typename S::size_type pos2, typename S::size_type n2, int x)
|
||||
{
|
||||
static_assert((!std::is_same<S, SV>::value), "");
|
||||
try
|
||||
{
|
||||
if (pos1 <= s.size() && pos2 <= sv.size())
|
||||
assert(sign(s.compare(pos1, n1, sv, pos2, n2)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
assert(pos2 <= sv.size());
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > sv.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos1, n1, sv, pos2, n2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > sv.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S, class SV>
|
||||
@@ -55,16 +62,22 @@ test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
SV sv, typename S::size_type pos2, int x)
|
||||
{
|
||||
static_assert((!std::is_same<S, SV>::value), "");
|
||||
try
|
||||
{
|
||||
if (pos1 <= s.size() && pos2 <= sv.size())
|
||||
assert(sign(s.compare(pos1, n1, sv, pos2)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
assert(pos2 <= sv.size());
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > sv.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos1, n1, sv, pos2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > sv.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S, class SV>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XFAIL: libcpp-no-exceptions
|
||||
// <string>
|
||||
|
||||
// int compare(size_type pos, size_type n1, const charT *s) const;
|
||||
@@ -18,6 +17,8 @@
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int sign(int x)
|
||||
{
|
||||
if (x == 0)
|
||||
@@ -32,15 +33,22 @@ void
|
||||
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
const typename S::value_type* str, int x)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pos1 <= s.size())
|
||||
assert(sign(s.compare(pos1, n1, str)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos1 > s.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos1, n1, str);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XFAIL: libcpp-no-exceptions
|
||||
// <string>
|
||||
|
||||
// int compare(size_type pos, size_type n1, const charT *s, size_type n2) const;
|
||||
@@ -18,6 +17,8 @@
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int sign(int x)
|
||||
{
|
||||
if (x == 0)
|
||||
@@ -32,15 +33,22 @@ void
|
||||
test(const S& s, typename S::size_type pos, typename S::size_type n1,
|
||||
const typename S::value_type* str, typename S::size_type n2, int x)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pos <= s.size())
|
||||
assert(sign(s.compare(pos, n1, str, n2)) == sign(x));
|
||||
assert(pos <= s.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos > s.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos, n1, str, n2);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos > s.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XFAIL: libcpp-no-exceptions
|
||||
// <string>
|
||||
|
||||
// int compare(size_type pos1, size_type n1, const basic_string& str) const;
|
||||
@@ -18,6 +17,8 @@
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int sign(int x)
|
||||
{
|
||||
if (x == 0)
|
||||
@@ -32,15 +33,22 @@ void
|
||||
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
const S& str, int x)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pos1 <= s.size())
|
||||
assert(sign(s.compare(pos1, n1, str)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos1 > s.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos1, n1, str);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XFAIL: libcpp-no-exceptions
|
||||
// <string>
|
||||
|
||||
// int compare(size_type pos1, size_type n1, const basic_string& str,
|
||||
@@ -20,6 +19,8 @@
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int sign(int x)
|
||||
{
|
||||
if (x == 0)
|
||||
@@ -34,16 +35,22 @@ void
|
||||
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
const S& str, typename S::size_type pos2, typename S::size_type n2, int x)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pos1 <= s.size() && pos2 <= str.size())
|
||||
assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
assert(pos2 <= str.size());
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > str.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos1, n1, str, pos2, n2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > str.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -51,16 +58,22 @@ void
|
||||
test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
const S& str, typename S::size_type pos2, int x)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pos1 <= s.size() && pos2 <= str.size())
|
||||
assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
assert(pos2 <= str.size());
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > str.size());
|
||||
try
|
||||
{
|
||||
s.compare(pos1, n1, str, pos2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > str.size());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class S>
|
||||
|
||||
Reference in New Issue
Block a user