Skip to content

Commit

Permalink
test: shared recycled_ptrs
Browse files Browse the repository at this point in the history
This commit includes tests for shared `recycled_ptr`s. Unreachable paths are also marked.

This is the last in a series of commits that intend to fix #828, where `recycled_ptr` had low coverage.

fix #828
  • Loading branch information
alandefreitas committed Mar 15, 2024
1 parent 5b86565 commit f7bd5a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/grammar/detail/recycled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ recycled_add_impl(
{
auto& a = all_reports_;

// LCOV_EXCL_START
/*
* We can't guarantee coverage
* exercise of this path.
*/
std::size_t new_count = ++a.count;
std::size_t old_count_max = a.count_max;
while (
Expand All @@ -83,6 +88,7 @@ recycled_add_impl(
!a.alloc_max.compare_exchange_weak(
old_alloc_max, n))
{}
// LCOV_EXCL_STOP
}

void
Expand Down
21 changes: 16 additions & 5 deletions test/unit/grammar/recycled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,33 @@ namespace grammar {

struct recycled_test
{
void
testPtr()
{
}

void
run()
{
// basic
{
recycled_ptr<std::string> sp;
sp->reserve(1000);
BOOST_TEST(sp->capacity() >= 1000);
}
{
recycled_ptr<std::string> sp;
BOOST_TEST(sp->capacity() >= 1000);
}

// shared
{
recycled_ptr<std::string> sp;
auto sp2 = sp;
sp->reserve(1000);
BOOST_TEST(sp->capacity() >= 1000);
BOOST_TEST(sp2->capacity() >= 1000);
}
{
recycled_ptr<std::string> sp;
recycled_ptr<std::string> sp2(sp);
BOOST_TEST(sp->capacity() >= 1000);
BOOST_TEST(sp2->capacity() >= 1000);
}

// coverage
Expand Down

0 comments on commit f7bd5a6

Please sign in to comment.