DEF_WRAP_1_R(create_directory, bool, const path&, p)
DEF_WRAP_2_V(create_hard_link, void, const path&, target, const path&, link)
DEF_WRAP_0_R(current_path, path)
+DEF_WRAP_1_V(current_path, void, const path&, p)
DEF_WRAP_1_P(exists, bool, const path&, p)
DEF_WRAP_1_P(is_directory, bool, const path&, p)
DEF_WRAP_1_R(read_symlink, path, const path&, p)
++m_subdir_counter;
std::string subtest_dir = FMT("{}/test_{}", m_test_dir, m_subdir_counter);
fs::create_directories(subtest_dir);
- if (chdir(subtest_dir.c_str()) != 0) {
+ if (!fs::current_path(subtest_dir)) {
abort();
}
}
TestContext::~TestContext()
{
- if (chdir(m_test_dir.c_str()) != 0) {
+ if (!fs::current_path(m_test_dir)) {
abort();
}
}
-void
-check_chdir(const std::string& dir)
-{
- if (chdir(dir.c_str()) != 0) {
- throw core::Error(
- FMT("failed to change directory to {}: {}", dir, strerror(errno)));
- }
-}
-
} // namespace TestUtil
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
static size_t m_subdir_counter;
};
-// Change directory to `dir`, throwing Error on failure.
-void check_chdir(const std::string& dir);
-
} // namespace TestUtil
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../src/fmtmacros.hpp"
-#include "TestUtil.hpp"
#include <util/environment.hpp>
#include <util/filesystem.hpp>
std::string testdir = FMT("testdir/{}", getpid());
fs::remove_all(testdir);
fs::create_directories(testdir);
- TestUtil::check_chdir(testdir);
+ fs::current_path(testdir);
doctest::Context context;
context.applyCommandLine(argc, argv);
int result = context.run();
if (result == 0) {
- TestUtil::check_chdir(dir_before);
+ fs::current_path(dir_before);
fs::remove_all(testdir);
} else {
PRINT(stderr, "Note: Test data has been left in {}\n", testdir);
#ifndef _WIN32
REQUIRE(symlink("d", "s") == 0);
#endif
- REQUIRE(chdir("d") == 0);
+ REQUIRE(fs::current_path("d"));
util::setenv("PWD", apparent_cwd);
SUBCASE("No base directory")