Skip to content

Commit e85d33f

Browse files
committed
Generalize test directory fixture setup.
1 parent 551a5f9 commit e85d33f

3 files changed

Lines changed: 20 additions & 32 deletions

File tree

test/test.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ bool create(const std::filesystem::path& file_path) NOEXCEPT;
105105
bool exists(const std::filesystem::path& file_path) NOEXCEPT;
106106
bool remove(const std::filesystem::path& file_path) NOEXCEPT;
107107

108+
struct directory_setup_fixture
109+
{
110+
DELETE_COPY_MOVE(directory_setup_fixture);
111+
112+
directory_setup_fixture() NOEXCEPT
113+
{
114+
BOOST_REQUIRE(clear(directory));
115+
}
116+
~directory_setup_fixture() NOEXCEPT
117+
{
118+
BOOST_REQUIRE(clear(directory));
119+
}
120+
};
121+
108122
// Utility to convert a const reference instance to moveable.
109123
template <typename Type>
110124
Type move_copy(const Type& instance) NOEXCEPT

test/unicode/utf8_everywhere/ifstream.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,11 @@
1818
*/
1919
#include "../../test.hpp"
2020

21-
struct ifstream_tests_setup_fixture
22-
{
23-
ifstream_tests_setup_fixture()
24-
{
25-
test::remove(TEST_NAME);
26-
}
27-
28-
~ifstream_tests_setup_fixture()
29-
{
30-
test::remove(TEST_NAME);
31-
}
32-
};
33-
34-
BOOST_FIXTURE_TEST_SUITE(ifstream_tests, ifstream_tests_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(ifstream_tests, test::directory_setup_fixture)
3522

3623
BOOST_AUTO_TEST_CASE(ifstream__construct__valid_path__round_trip)
3724
{
38-
ofstream out(TEST_NAME, std::ofstream::out);
25+
ofstream out(TEST_PATH, std::ofstream::out);
3926
BOOST_REQUIRE(out.good());
4027
BOOST_REQUIRE(!out.bad());
4128

@@ -46,7 +33,7 @@ BOOST_AUTO_TEST_CASE(ifstream__construct__valid_path__round_trip)
4633
out.close();
4734
BOOST_REQUIRE(out.good());
4835

49-
ifstream in(TEST_NAME);
36+
ifstream in(TEST_PATH);
5037
BOOST_REQUIRE(in.good());
5138

5239
std::string line;

test/unicode/utf8_everywhere/ofstream.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,11 @@
1818
*/
1919
#include "../../test.hpp"
2020

21-
struct ofstream_tests_setup_fixture
22-
{
23-
ofstream_tests_setup_fixture()
24-
{
25-
test::remove(TEST_NAME);
26-
}
27-
28-
~ofstream_tests_setup_fixture()
29-
{
30-
test::remove(TEST_NAME);
31-
}
32-
};
33-
34-
BOOST_FIXTURE_TEST_SUITE(ofstream_tests, ofstream_tests_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(ofstream_tests, test::directory_setup_fixture)
3522

3623
BOOST_AUTO_TEST_CASE(ofstream__construct__valid_path__round_trip)
3724
{
38-
ofstream out(TEST_NAME, std::ofstream::out);
25+
ofstream out(TEST_PATH, std::ofstream::out);
3926
BOOST_REQUIRE(out.good());
4027
BOOST_REQUIRE(!out.bad());
4128

@@ -46,7 +33,7 @@ BOOST_AUTO_TEST_CASE(ofstream__construct__valid_path__round_trip)
4633
out.close();
4734
BOOST_REQUIRE(out.good());
4835

49-
ifstream in(TEST_NAME);
36+
ifstream in(TEST_PATH);
5037
BOOST_REQUIRE(in.good());
5138

5239
std::string line;

0 commit comments

Comments
 (0)