diff options
author | Kiminuo <kiminuo@protonmail.com> | 2020-06-11 08:58:46 +0200 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-02-03 18:35:52 +0800 |
commit | 41d7166c8a598b604aad6c6b1d88ad46e23be247 (patch) | |
tree | 883af805ab387dc7db01602a19ccd70d89b78cb1 /src/test | |
parent | ffc89d1f21258553c0087b774a9ea1ce84139d4f (diff) |
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>
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fs_tests.cpp | 18 | ||||
-rw-r--r-- | src/test/fuzz/fuzz.cpp | 6 | ||||
-rw-r--r-- | src/test/fuzz/utxo_snapshot.cpp | 1 | ||||
-rw-r--r-- | src/test/script_tests.cpp | 5 | ||||
-rw-r--r-- | src/test/settings_tests.cpp | 8 | ||||
-rw-r--r-- | src/test/streams_tests.cpp | 1 | ||||
-rw-r--r-- | src/test/util_tests.cpp | 4 |
7 files changed, 32 insertions, 11 deletions
diff --git a/src/test/fs_tests.cpp b/src/test/fs_tests.cpp index d3389c30eb..1256395849 100644 --- a/src/test/fs_tests.cpp +++ b/src/test/fs_tests.cpp @@ -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"); diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index 60c48e7c22..a490bbfa1d 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -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; diff --git a/src/test/fuzz/utxo_snapshot.cpp b/src/test/fuzz/utxo_snapshot.cpp index 19ca1f0c99..e513f1883c 100644 --- a/src/test/fuzz/utxo_snapshot.cpp +++ b/src/test/fuzz/utxo_snapshot.cpp @@ -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> diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 4906bd2386..c453f22594 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -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(); diff --git a/src/test/settings_tests.cpp b/src/test/settings_tests.cpp index 3c6e31d311..15ffd068c7 100644 --- a/src/test/settings_tests.cpp +++ b/src/test/settings_tests.cpp @@ -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; } diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index af0f86274e..6a69fe9840 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -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> diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 20d27a237d..b6479efe7d 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -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) |