updated build system

This commit is contained in:
2024-08-08 18:59:14 -05:00
parent 6e4ae2896b
commit 0b5efef569
30 changed files with 1162 additions and 474 deletions

View File

@ -24,24 +24,24 @@
namespace {
static std::recursive_mutex file_mtx{};
static std::vector<std::string> generated_files;
static std::vector<std::unique_ptr<repertory::utils::file::i_file>>
generated_files{};
static void delete_generated_files() {
repertory::recur_mutex_lock lock{file_mtx};
std::optional<std::string> parent_path;
for (auto &&path : generated_files) {
if (parent_path->empty()) {
parent_path = std::filesystem::path(path).parent_path().string();
parent_path =
repertory::utils::path::get_parent_directory(path->get_path());
}
std::error_code ec{};
std::filesystem::remove(path, ec);
[[maybe_unused]] auto removed = path->remove();
}
generated_files.clear();
if (parent_path.has_value()) {
std::error_code ec{};
std::filesystem::remove_all(*parent_path, ec);
EXPECT_TRUE(repertory::utils::file::remove_directory(*parent_path, true));
}
}
@ -54,26 +54,25 @@ static auto deleter{std::make_unique<file_deleter>()};
namespace repertory::test {
#if defined(PROJECT_ENABLE_LIBSODIUM)
auto create_random_file(std::size_t size) -> utils::file::file {
auto create_random_file(std::size_t size) -> utils::file::i_file & {
recur_mutex_lock lock{file_mtx};
auto path = generate_test_file_name("random");
auto file = utils::file::file::open_or_create_file(path);
EXPECT_TRUE(file);
if (file) {
EXPECT_TRUE(*file);
if (*file) {
data_buffer buf(size);
randombytes_buf(buf.data(), buf.size());
std::size_t bytes_written{};
EXPECT_TRUE(file.write(buf, 0U, &bytes_written));
EXPECT_TRUE(file->write(buf, 0U, &bytes_written));
EXPECT_EQ(size, bytes_written);
EXPECT_EQ(size, file.size());
generated_files.emplace_back(path);
EXPECT_EQ(size, file->size());
}
return file;
generated_files.emplace_back(std::move(file));
return *generated_files.back();
}
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
@ -86,8 +85,9 @@ auto generate_test_file_name(std::string_view file_name_no_extension)
std::string{file_name_no_extension} +
std::to_string(generated_files.size()),
});
generated_files.emplace_back(path);
return path;
generated_files.emplace_back(
std::unique_ptr<utils::file::i_file>(new utils::file::file{path}));
return generated_files.back()->get_path();
}
auto get_test_input_dir() -> std::string {
@ -111,7 +111,7 @@ auto get_test_output_dir() -> std::string {
#endif // defined(_WIN32)
if (not utils::file::is_directory(path)) {
std::filesystem::create_directories(path);
EXPECT_TRUE(utils::file::create_directories(path));
}
return path;