Skip to content

Commit 9dc7360

Browse files
committed
TemporaryDirectory: Add automatic conversions to boost::filesystem::path
1 parent 5a0a0af commit 9dc7360

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

test/TemporaryDirectory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TemporaryDirectory
4444
~TemporaryDirectory();
4545

4646
boost::filesystem::path const& path() const { return m_path; }
47+
operator boost::filesystem::path() const { return m_path; }
4748

4849
private:
4950
boost::filesystem::path m_path;
@@ -59,6 +60,7 @@ class TemporaryWorkingDirectory
5960
~TemporaryWorkingDirectory();
6061

6162
boost::filesystem::path const& originalWorkingDirectory() const { return m_originalWorkingDirectory; }
63+
operator boost::filesystem::path() const { return boost::filesystem::current_path(); }
6264

6365
private:
6466
boost::filesystem::path m_originalWorkingDirectory;

test/libsolidity/interface/FileReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_redundant_slashes)
129129
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path)
130130
{
131131
TemporaryDirectory tempDir(TEST_CASE_NAME);
132-
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
132+
TemporaryWorkingDirectory tempWorkDir(tempDir);
133133

134134
// On Windows tempDir.path() normally contains the drive letter while the normalized path should not.
135135
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_unc_path)
157157
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
158158
{
159159
TemporaryDirectory tempDir(TEST_CASE_NAME);
160-
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
160+
TemporaryWorkingDirectory tempWorkDir(tempDir);
161161

162162
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
163163
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
@@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
187187
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_stripping_root_name)
188188
{
189189
TemporaryDirectory tempDir(TEST_CASE_NAME);
190-
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
190+
TemporaryWorkingDirectory tempWorkDir(tempDir);
191191

192192
soltestAssert(boost::filesystem::current_path().is_absolute(), "");
193193
#if defined(_WIN32)
@@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_path_beyond_root)
234234
BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_case_sensitivity)
235235
{
236236
TemporaryDirectory tempDir(TEST_CASE_NAME);
237-
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
237+
TemporaryWorkingDirectory tempWorkDir(tempDir);
238238

239239
boost::filesystem::path expectedPrefix = "/" / tempDir.path().relative_path();
240240
soltestAssert(expectedPrefix.is_absolute() || expectedPrefix.root_path() == "/", "");

test/libsolutil/CommonIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(readFileAsString_regular_file)
5252
BOOST_AUTO_TEST_CASE(readFileAsString_directory)
5353
{
5454
TemporaryDirectory tempDir(TEST_CASE_NAME);
55-
BOOST_CHECK_THROW(readFileAsString(tempDir.path()), NotAFile);
55+
BOOST_CHECK_THROW(readFileAsString(tempDir), NotAFile);
5656
}
5757

5858
BOOST_AUTO_TEST_CASE(readFileAsString_symlink)

test/solc/CommandLineInterface.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ BOOST_AUTO_TEST_CASE(cli_input)
156156
{(expectedDir2 / "input2.sol").generic_string(), ""},
157157
};
158158
PathSet expectedAllowedPaths = {
159-
boost::filesystem::canonical(tempDir1.path()),
160-
boost::filesystem::canonical(tempDir2.path()),
159+
boost::filesystem::canonical(tempDir1),
160+
boost::filesystem::canonical(tempDir2),
161161
"b/c",
162162
"c/d/e",
163163
};
@@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(cli_ignore_missing_some_files_exist)
191191

192192
// NOTE: Allowed paths should not be added for skipped files.
193193
map<string, string> expectedSources = {{(expectedDir1 / "input1.sol").generic_string(), ""}};
194-
PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1.path())};
194+
PathSet expectedAllowedPaths = {boost::filesystem::canonical(tempDir1)};
195195

196196
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
197197
"solc",
@@ -354,14 +354,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_no_base_path)
354354
{
355355
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
356356
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
357-
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
357+
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
358358
soltestAssert(tempDirCurrent.path().is_absolute(), "");
359359
soltestAssert(tempDirOther.path().is_absolute(), "");
360360

361361
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
362362
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
363-
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
364-
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
363+
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
364+
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
365365

366366
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
367367
soltestAssert(expectedOtherDir.is_absolute() || expectedOtherDir.root_path() == "/", "");
@@ -412,14 +412,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_same_as_work_dir)
412412
{
413413
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
414414
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
415-
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
415+
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
416416
soltestAssert(tempDirCurrent.path().is_absolute(), "");
417417
soltestAssert(tempDirOther.path().is_absolute(), "");
418418

419419
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
420420
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
421-
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
422-
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
421+
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
422+
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
423423

424424
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
425425
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
@@ -475,16 +475,16 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_different_from_wor
475475
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
476476
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
477477
TemporaryDirectory tempDirBase(TEST_CASE_NAME);
478-
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
478+
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
479479
soltestAssert(tempDirCurrent.path().is_absolute(), "");
480480
soltestAssert(tempDirOther.path().is_absolute(), "");
481481
soltestAssert(tempDirBase.path().is_absolute(), "");
482482

483483
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
484484
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
485-
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
486-
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
487-
boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase.path());
485+
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
486+
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
487+
boost::filesystem::path baseDirNoSymlinks = boost::filesystem::canonical(tempDirBase);
488488

489489
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
490490
boost::filesystem::path expectedCurrentDir = "/" / currentDirNoSymlinks.relative_path();
@@ -547,14 +547,14 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_relative_base_path)
547547
{
548548
TemporaryDirectory tempDirCurrent(TEST_CASE_NAME);
549549
TemporaryDirectory tempDirOther(TEST_CASE_NAME);
550-
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent.path());
550+
TemporaryWorkingDirectory tempWorkDir(tempDirCurrent);
551551
soltestAssert(tempDirCurrent.path().is_absolute(), "");
552552
soltestAssert(tempDirOther.path().is_absolute(), "");
553553

554554
// NOTE: On macOS the path usually contains symlinks which prevents base path from being stripped.
555555
// Use canonical() to resolve symnlinks and get consistent results on all platforms.
556-
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent.path());
557-
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther.path());
556+
boost::filesystem::path currentDirNoSymlinks = boost::filesystem::canonical(tempDirCurrent);
557+
boost::filesystem::path otherDirNoSymlinks = boost::filesystem::canonical(tempDirOther);
558558

559559
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
560560
boost::filesystem::path expectedOtherDir = "/" / otherDirNoSymlinks.relative_path();
@@ -622,7 +622,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_normalization_and_weird_name
622622
string uncPath = "//" + tempDir.path().relative_path().generic_string();
623623
soltestAssert(FileReader::isUNCPath(uncPath), "");
624624

625-
boost::filesystem::path tempDirNoSymlinks = boost::filesystem::canonical(tempDir.path());
625+
boost::filesystem::path tempDirNoSymlinks = boost::filesystem::canonical(tempDir);
626626

627627
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();
628628
soltestAssert(expectedWorkDir.is_absolute() || expectedWorkDir.root_path() == "/", "");
@@ -829,7 +829,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
829829
};
830830

831831
FileReader::FileSystemPathSet expectedAllowedDirectories = {
832-
boost::filesystem::canonical(tempDir.path()) / "x/y/z",
832+
boost::filesystem::canonical(tempDir) / "x/y/z",
833833
};
834834

835835
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
@@ -846,7 +846,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
846846
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_base_path_and_stdin)
847847
{
848848
TemporaryDirectory tempDir(TEST_CASE_NAME);
849-
TemporaryWorkingDirectory tempWorkDir(tempDir.path());
849+
TemporaryWorkingDirectory tempWorkDir(tempDir);
850850
boost::filesystem::create_directories(tempDir.path() / "base");
851851

852852
boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::current_path().relative_path();

0 commit comments

Comments
 (0)