mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-11 07:09:29 +02:00
refactor: replace boost::filesystem with std::filesystem
Warning: Replacing fs::system_complete calls with fs::absolute calls in this commit may cause minor changes in behaviour because fs::absolute no longer strips trailing slashes; however these changes are believed to be safe. Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fsbridge_pathtostring)
|
||||
@@ -45,37 +49,37 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
|
||||
fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃";
|
||||
fs::path tmpfile2 = tmpfolder / "fs_tests_₿_🏃";
|
||||
{
|
||||
fsbridge::ofstream file(tmpfile1);
|
||||
std::ofstream file{tmpfile1};
|
||||
file << "bitcoin";
|
||||
}
|
||||
{
|
||||
fsbridge::ifstream file(tmpfile2);
|
||||
std::ifstream file{tmpfile2};
|
||||
std::string input_buffer;
|
||||
file >> input_buffer;
|
||||
BOOST_CHECK_EQUAL(input_buffer, "bitcoin");
|
||||
}
|
||||
{
|
||||
fsbridge::ifstream file(tmpfile1, std::ios_base::in | std::ios_base::ate);
|
||||
std::ifstream file{tmpfile1, std::ios_base::in | std::ios_base::ate};
|
||||
std::string input_buffer;
|
||||
file >> input_buffer;
|
||||
BOOST_CHECK_EQUAL(input_buffer, "");
|
||||
}
|
||||
{
|
||||
fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::app);
|
||||
std::ofstream file{tmpfile2, std::ios_base::out | std::ios_base::app};
|
||||
file << "tests";
|
||||
}
|
||||
{
|
||||
fsbridge::ifstream file(tmpfile1);
|
||||
std::ifstream file{tmpfile1};
|
||||
std::string input_buffer;
|
||||
file >> input_buffer;
|
||||
BOOST_CHECK_EQUAL(input_buffer, "bitcointests");
|
||||
}
|
||||
{
|
||||
fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::trunc);
|
||||
std::ofstream file{tmpfile2, std::ios_base::out | std::ios_base::trunc};
|
||||
file << "bitcoin";
|
||||
}
|
||||
{
|
||||
fsbridge::ifstream file(tmpfile1);
|
||||
std::ifstream file{tmpfile1};
|
||||
std::string input_buffer;
|
||||
file >> input_buffer;
|
||||
BOOST_CHECK_EQUAL(input_buffer, "bitcoin");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <test/fuzz/fuzz.h>
|
||||
|
||||
#include <fs.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <test/util/setup_common.h>
|
||||
@@ -12,9 +13,12 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -80,7 +84,7 @@ void initialize()
|
||||
}
|
||||
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
||||
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
|
||||
fsbridge::ofstream out_stream{out_path, std::ios::binary};
|
||||
std::ofstream out_stream{out_path, std::ios::binary};
|
||||
for (const auto& t : FuzzTargets()) {
|
||||
if (std::get<2>(t.second)) continue;
|
||||
out_stream << t.first << std::endl;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <fs.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
#include <script/bitcoinconsensus.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -1727,7 +1728,7 @@ BOOST_AUTO_TEST_CASE(script_assets_test)
|
||||
bool exists = fs::exists(path);
|
||||
BOOST_WARN_MESSAGE(exists, "File $DIR_UNIT_TEST_DATA/script_assets_test.json not found, skipping script_assets_test");
|
||||
if (!exists) return;
|
||||
fs::ifstream file(path);
|
||||
std::ifstream file{path};
|
||||
BOOST_CHECK(file.is_open());
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t length = file.tellg();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <util/settings.h>
|
||||
|
||||
#include <fs.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/str.h>
|
||||
|
||||
@@ -13,6 +14,11 @@
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
inline bool operator==(const util::SettingsValue& a, const util::SettingsValue& b)
|
||||
@@ -36,7 +42,7 @@ inline std::ostream& operator<<(std::ostream& os, const std::pair<std::string, u
|
||||
|
||||
inline void WriteText(const fs::path& path, const std::string& text)
|
||||
{
|
||||
fsbridge::ofstream file;
|
||||
std::ofstream file;
|
||||
file.open(path);
|
||||
file << text;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <fs.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <util/system.h>
|
||||
|
||||
#include <clientversion.h>
|
||||
#include <fs.h>
|
||||
#include <hash.h> // For Hash()
|
||||
#include <key.h> // For CKey
|
||||
#include <sync.h>
|
||||
@@ -70,9 +71,12 @@ BOOST_AUTO_TEST_CASE(util_datadir)
|
||||
args.ClearPathCache();
|
||||
BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase());
|
||||
|
||||
#ifndef WIN32
|
||||
// Windows does not consider "datadir/.//" to be a valid directory path.
|
||||
args.ForceSetArg("-datadir", fs::PathToString(dd_norm) + "/.//");
|
||||
args.ClearPathCache();
|
||||
BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase());
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_check)
|
||||
|
||||
Reference in New Issue
Block a user