File: raii_test.cpp

package info (click to toggle)
libfplus 0.2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,904 kB
  • sloc: cpp: 27,543; javascript: 634; sh: 105; python: 103; makefile: 6
file content (24 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright 2015, Tobias Hermann and the FunctionalPlus contributors.
// https://github.com/Dobiasd/FunctionalPlus
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
#include <fplus/fplus.hpp>

TEST_CASE("raii_test, make_raii")
{
    std::string log = "nothing";
    const auto init = [&log]() { log = "init"; };
    const auto quit = [&log]() { log = "quit"; };

    REQUIRE_EQ(log, "nothing");
    {
        REQUIRE_EQ(log, "nothing");
        const auto ressource = fplus::make_raii(init, quit);
        REQUIRE_EQ(log, "init");
    }
    REQUIRE_EQ(log, "quit");
}