Skip to content

Commit 9f4f012

Browse files
committed
[libcxx][test] Attempt to make debug mode tests more bulletproof
The problem with debug mode tests is that it isn't known which particular _LIBCPP_ASSERT causes the test to exit, and as shown by https://reviews.llvm.org/D100029 and 2908eb2 it might be not the expected one. The patch adds TEST_LIBCPP_ASSERT_FAILURE macro that allows checking _LIBCPP_ASSERT message to ensure we caught an expected failure. Reviewed By: Quuxplusone, ldionne Differential Revision: https://reviews.llvm.org/D100595
1 parent 38e2359 commit 9f4f012

File tree

177 files changed

+516
-962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+516
-962
lines changed

libcxx/test/libcxx/containers/sequences/deque/pop_back_empty.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010

1111
// pop_back() more than the number of elements in a deque
1212

13-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
13+
// UNSUPPORTED: libcxx-no-debug-mode
14+
15+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
1416

15-
#include <cstdlib>
1617
#include <deque>
1718

1819
#include "test_macros.h"
19-
20+
#include "debug_macros.h"
2021

2122
int main(int, char**) {
2223
std::deque<int> q;
2324
q.push_back(0);
2425
q.pop_back();
25-
q.pop_back();
26-
std::exit(1);
26+
TEST_LIBCPP_ASSERT_FAILURE(q.pop_back(), "deque::pop_back called on an empty deque");
2727

28-
return 0;
28+
return 0;
2929
}

libcxx/test/libcxx/containers/sequences/list/list.cons/db_copy.pass.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cstdlib>
20-
#include <cassert>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
std::list<int> l1;
2725
l1.push_back(1); l1.push_back(2); l1.push_back(3);
2826
std::list<int>::iterator i = l1.begin();
2927
std::list<int> l2 = l1;
30-
l2.erase(i);
31-
assert(false);
28+
TEST_LIBCPP_ASSERT_FAILURE(l2.erase(i), "list::erase(iterator) called with an iterator not referring to this list");
3229

33-
return 0;
30+
return 0;
3431
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/emplace_db1.pass.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,25 @@
1414
// UNSUPPORTED: libcxx-no-debug-mode
1515

1616
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
17-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1817

1918
#include <list>
20-
#include <cstdlib>
21-
#include <cassert>
2219

2320
#include "test_macros.h"
21+
#include "debug_macros.h"
2422

25-
class A
26-
{
27-
int i_;
28-
double d_;
29-
30-
A(const A&);
31-
A& operator=(const A&);
32-
public:
33-
A(int i, double d)
34-
: i_(i), d_(d) {}
35-
36-
int geti() const {return i_;}
37-
double getd() const {return d_;}
23+
struct A {
24+
explicit A(int i, double d) {
25+
(void)i;
26+
(void)d;
27+
}
3828
};
3929

4030
int main(int, char**)
4131
{
4232
std::list<A> c1;
4333
std::list<A> c2;
44-
std::list<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
45-
assert(false);
34+
TEST_LIBCPP_ASSERT_FAILURE(c1.emplace(c2.cbegin(), 2, 3.5),
35+
"list::emplace(iterator, args...) called with an iterator not referring to this list");
4636

47-
return 0;
37+
return 0;
4838
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cassert>
20-
#include <cstdlib>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
int a1[] = {1, 2, 3};
2725
std::list<int> l1(a1, a1+3);
2826
std::list<int>::const_iterator i = l1.end();
29-
l1.erase(i);
30-
assert(false);
27+
TEST_LIBCPP_ASSERT_FAILURE(l1.erase(i), "list::erase(iterator) called with a non-dereferenceable iterator");
3128

32-
return 0;
29+
return 0;
3330
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cassert>
20-
#include <cstdlib>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
int a1[] = {1, 2, 3};
2725
std::list<int> l1(a1, a1+3);
2826
std::list<int> l2(a1, a1+3);
2927
std::list<int>::const_iterator i = l2.begin();
30-
l1.erase(i);
31-
assert(false);
28+
TEST_LIBCPP_ASSERT_FAILURE(l1.erase(i), "list::erase(iterator) called with an iterator not referring to this list");
3229

33-
return 0;
30+
return 0;
3431
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cassert>
20-
#include <cstdlib>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
int a1[] = {1, 2, 3};
2725
std::list<int> l1(a1, a1+3);
2826
std::list<int> l2(a1, a1+3);
29-
std::list<int>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin()));
30-
assert(false);
27+
TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l2.cbegin(), std::next(l1.cbegin())),
28+
"list::erase(iterator, iterator) called with an iterator not referring to this list");
3129

32-
return 0;
30+
return 0;
3331
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cassert>
20-
#include <cstdlib>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
int a1[] = {1, 2, 3};
2725
std::list<int> l1(a1, a1+3);
2826
std::list<int> l2(a1, a1+3);
29-
std::list<int>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin()));
30-
assert(false);
27+
TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l1.cbegin(), std::next(l2.cbegin())),
28+
"list::erase(iterator, iterator) called with an iterator not referring to this list");
3129

32-
return 0;
30+
return 0;
3331
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cassert>
20-
#include <cstdlib>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
int a1[] = {1, 2, 3};
2725
std::list<int> l1(a1, a1+3);
2826
std::list<int> l2(a1, a1+3);
29-
std::list<int>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin()));
30-
assert(false);
27+
TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l2.cbegin(), std::next(l2.cbegin())),
28+
"list::erase(iterator, iterator) called with an iterator not referring to this list");
3129

32-
return 0;
30+
return 0;
3331
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@
1313
// UNSUPPORTED: libcxx-no-debug-mode
1414

1515
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
16-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1716

1817
#include <list>
19-
#include <cassert>
20-
#include <cstdlib>
2118

2219
#include "test_macros.h"
20+
#include "debug_macros.h"
2321

2422
int main(int, char**)
2523
{
2624
int a1[] = {1, 2, 3};
2725
std::list<int> l1(a1, a1+3);
28-
std::list<int>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin());
29-
assert(false);
26+
TEST_LIBCPP_ASSERT_FAILURE(l1.erase(std::next(l1.cbegin()), l1.cbegin()),
27+
"Attempted to increment a non-incrementable list::const_iterator");
3028

31-
return 0;
29+
return 0;
3230
}

libcxx/test/libcxx/containers/sequences/list/list.modifiers/insert_iter_iter_iter_db1.pass.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,20 @@
1414
// UNSUPPORTED: libcxx-no-debug-mode
1515

1616
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
17-
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
1817

1918
#include <list>
20-
#include <cstdlib>
21-
#include <cassert>
19+
2220
#include "test_macros.h"
23-
#include "test_iterators.h"
21+
#include "debug_macros.h"
2422

2523
int main(int, char**)
2624
{
2725
{
2826
std::list<int> v(100);
2927
std::list<int> v2(100);
3028
int a[] = {1, 2, 3, 4, 5};
31-
const int N = sizeof(a)/sizeof(a[0]);
32-
std::list<int>::iterator i = v.insert(next(v2.cbegin(), 10),
33-
cpp17_input_iterator<const int*>(a),
34-
cpp17_input_iterator<const int*>(a+N));
35-
assert(false);
29+
TEST_LIBCPP_ASSERT_FAILURE(v.insert(v2.cbegin(), a, a + 5),
30+
"list::insert(iterator, range) called with an iterator not referring to this list");
3631
}
3732

3833
return 0;

0 commit comments

Comments
 (0)