Skip to content

Commit 5a0a0af

Browse files
committed
TemporaryDirectory: Use soltestAssert() instead of assert() and remove filesystem namespace alias
1 parent fb6a257 commit 5a0a0af

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

test/TemporaryDirectory.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
#include <test/TemporaryDirectory.h>
2020

21+
#include <test/libsolidity/util/SoltestErrors.h>
22+
2123
#include <boost/filesystem.hpp>
2224

23-
#include <cassert>
2425
#include <regex>
2526
#include <iostream>
2627

@@ -34,18 +35,18 @@ TemporaryDirectory::TemporaryDirectory(std::string const& _prefix):
3435
m_path(fs::temp_directory_path() / fs::unique_path(_prefix + "-%%%%-%%%%-%%%%-%%%%"))
3536
{
3637
// Prefix should just be a file name and not contain anything that would make us step out of /tmp.
37-
assert(fs::path(_prefix) == fs::path(_prefix).stem());
38+
soltestAssert(fs::path(_prefix) == fs::path(_prefix).stem(), "");
3839

3940
fs::create_directory(m_path);
4041
}
4142

4243
TemporaryDirectory::~TemporaryDirectory()
4344
{
4445
// A few paranoid sanity checks just to be extra sure we're not deleting someone's homework.
45-
assert(m_path.string().find(fs::temp_directory_path().string()) == 0);
46-
assert(!fs::equivalent(m_path, fs::temp_directory_path()));
47-
assert(!fs::equivalent(m_path, m_path.root_path()));
48-
assert(!m_path.empty());
46+
soltestAssert(m_path.string().find(fs::temp_directory_path().string()) == 0, "");
47+
soltestAssert(!fs::equivalent(m_path, fs::temp_directory_path()), "");
48+
soltestAssert(!fs::equivalent(m_path, m_path.root_path()), "");
49+
soltestAssert(!m_path.empty(), "");
4950

5051
boost::system::error_code errorCode;
5152
uintmax_t numRemoved = fs::remove_all(m_path, errorCode);

test/TemporaryDirectoryTest.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <test/TemporaryDirectory.h>
2020

21+
#include <test/libsolidity/util/SoltestErrors.h>
22+
2123
#include <boost/filesystem.hpp>
2224
#include <boost/test/unit_test.hpp>
2325

@@ -26,68 +28,66 @@
2628
using namespace std;
2729
using namespace boost::test_tools;
2830

29-
namespace fs = boost::filesystem;
30-
3131
namespace solidity::test
3232
{
3333

3434
BOOST_AUTO_TEST_SUITE(TemporaryDirectoryTest)
3535

3636
BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_create_and_delete_a_unique_and_empty_directory)
3737
{
38-
fs::path dirPath;
38+
boost::filesystem::path dirPath;
3939
{
4040
TemporaryDirectory tempDir("temporary-directory-test");
4141
dirPath = tempDir.path();
4242

4343
BOOST_TEST(dirPath.stem().string().find("temporary-directory-test") == 0);
44-
BOOST_TEST(fs::equivalent(dirPath.parent_path(), fs::temp_directory_path()));
45-
BOOST_TEST(fs::is_directory(dirPath));
46-
BOOST_TEST(fs::is_empty(dirPath));
44+
BOOST_TEST(boost::filesystem::equivalent(dirPath.parent_path(), boost::filesystem::temp_directory_path()));
45+
BOOST_TEST(boost::filesystem::is_directory(dirPath));
46+
BOOST_TEST(boost::filesystem::is_empty(dirPath));
4747
}
48-
BOOST_TEST(!fs::exists(dirPath));
48+
BOOST_TEST(!boost::filesystem::exists(dirPath));
4949
}
5050

5151
BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_delete_its_directory_even_if_not_empty)
5252
{
53-
fs::path dirPath;
53+
boost::filesystem::path dirPath;
5454
{
5555
TemporaryDirectory tempDir("temporary-directory-test");
5656
dirPath = tempDir.path();
5757

58-
BOOST_TEST(fs::is_directory(dirPath));
58+
BOOST_TEST(boost::filesystem::is_directory(dirPath));
5959

6060
{
6161
ofstream tmpFile((dirPath / "test-file.txt").string());
6262
tmpFile << "Delete me!" << endl;
6363
}
64-
assert(fs::is_regular_file(dirPath / "test-file.txt"));
64+
soltestAssert(boost::filesystem::is_regular_file(dirPath / "test-file.txt"), "");
6565
}
66-
BOOST_TEST(!fs::exists(dirPath / "test-file.txt"));
66+
BOOST_TEST(!boost::filesystem::exists(dirPath / "test-file.txt"));
6767
}
6868

6969
BOOST_AUTO_TEST_CASE(TemporaryWorkingDirectory_should_change_and_restore_working_directory)
7070
{
71-
fs::path originalWorkingDirectory = fs::current_path();
71+
boost::filesystem::path originalWorkingDirectory = boost::filesystem::current_path();
7272

7373
try
7474
{
7575
{
7676
TemporaryDirectory tempDir("temporary-directory-test");
77-
assert(fs::equivalent(fs::current_path(), originalWorkingDirectory));
78-
assert(!fs::equivalent(tempDir.path(), originalWorkingDirectory));
77+
soltestAssert(boost::filesystem::equivalent(boost::filesystem::current_path(), originalWorkingDirectory), "");
78+
soltestAssert(!boost::filesystem::equivalent(tempDir.path(), originalWorkingDirectory), "");
7979

8080
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
8181

82-
BOOST_TEST(fs::equivalent(fs::current_path(), tempDir.path()));
82+
BOOST_TEST(boost::filesystem::equivalent(boost::filesystem::current_path(), tempDir.path()));
8383
}
84-
BOOST_TEST(fs::equivalent(fs::current_path(), originalWorkingDirectory));
84+
BOOST_TEST(boost::filesystem::equivalent(boost::filesystem::current_path(), originalWorkingDirectory));
8585

86-
fs::current_path(originalWorkingDirectory);
86+
boost::filesystem::current_path(originalWorkingDirectory);
8787
}
8888
catch (...)
8989
{
90-
fs::current_path(originalWorkingDirectory);
90+
boost::filesystem::current_path(originalWorkingDirectory);
9191
}
9292
}
9393

0 commit comments

Comments
 (0)