瀏覽代碼

Test updated to use ctor directly.

main
offa 7 年之前
父節點
當前提交
47f5e75fd8
共有 1 個文件被更改,包括 10 次插入10 次删除
  1. +10
    -10
      test/ScopeSuccessTest.cpp

+ 10
- 10
test/ScopeSuccessTest.cpp 查看文件

@@ -39,7 +39,7 @@ namespace
TEST_CASE("exit function called on destruction", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter());
auto guard = sr::make_scope_success(deleter);
auto guard = sr::scope_success{deleter};
static_cast<void>(guard);
}

@@ -47,7 +47,7 @@ TEST_CASE("exit function lambda called on destruction", "[ScopeSuccess]")
{
CallMock cm;
REQUIRE_CALL(cm, deleter());
auto guard = sr::make_scope_success([&cm] { cm.deleter(); });
auto guard = sr::scope_success{[&cm] { cm.deleter(); }};
static_cast<void>(guard);
}

@@ -56,21 +56,21 @@ TEST_CASE("exit function not called and rethrow on copy exception", "[ScopeSucce
REQUIRE_THROWS([] {
const ThrowOnCopyMock noMove;
REQUIRE_CALL(noMove, deleter());
sr::scope_success<decltype(noMove)> guard{noMove};
sr::scope_success guard{noMove};
}());
}

TEST_CASE("exit function is not called if released", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter()).TIMES(0);
auto guard = sr::make_scope_success(deleter);
auto guard = sr::scope_success{deleter};
guard.release();
}

TEST_CASE("move releases moved-from object", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter());
auto movedFrom = sr::make_scope_success(deleter);
auto movedFrom = sr::scope_success{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
}
@@ -80,14 +80,14 @@ TEST_CASE("move with copy init releases moved-from object", "[ScopeSuccess]")
CallMock mock;
const NotNothrowMoveMock notNothrow{&mock};
REQUIRE_CALL(mock, deleter());
sr::scope_success<decltype(notNothrow)> movedFrom{notNothrow};
sr::scope_success movedFrom{notNothrow};
auto guard = std::move(movedFrom);
}

TEST_CASE("move transfers state", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter());
auto movedFrom = sr::make_scope_success(deleter);
auto movedFrom = sr::scope_success{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
}
@@ -95,7 +95,7 @@ TEST_CASE("move transfers state", "[ScopeSuccess]")
TEST_CASE("move transfers state if released", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::make_scope_success(deleter);
auto movedFrom = sr::scope_success{deleter};
movedFrom.release();
auto guard = std::move(movedFrom);
static_cast<void>(guard);
@@ -105,7 +105,7 @@ TEST_CASE("exit function not called on exception", "[ScopeFail]")
{
try
{
auto guard = sr::make_scope_success(deleter);
auto guard = sr::scope_success{deleter};
static_cast<void>(guard);
throw 3;
}
@@ -123,7 +123,7 @@ TEST_CASE("exit function called on pending exception", "[ScopeFail]")
catch( ... )
{
REQUIRE_CALL(m, deleter());
auto guard = sr::make_scope_success(deleter);
auto guard = sr::scope_success{deleter};
static_cast<void>(guard);
}
}

Loading…
取消
儲存