From: Joel Rosdahl Date: Sun, 3 Aug 2025 11:44:15 +0000 (+0200) Subject: chore: Make code buildable with tl-expected 1.2.0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=441baad3307f9be3158d182c9921f879013c27fc;p=thirdparty%2Fccache.git chore: Make code buildable with tl-expected 1.2.0 tl-expected 1.2.0 has made tl::expected objects [[nodiscard]], so make sure to handle all tl::expected return values properly. --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 64a0f48f..5573b7bc 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -221,7 +221,7 @@ prepare_debug_path(const fs::path& cwd, // Ignore any error from fs::create_directories since we can't handle an error // in another way in this context. The caller takes care of logging when // trying to open the path for writing. - fs::create_directories(prefix.parent_path()); + std::ignore = fs::create_directories(prefix.parent_path()); char timestamp[100]; const auto tm = util::localtime(time_of_invocation); @@ -1194,7 +1194,8 @@ to_cache(Context& ctx, // it's compiling an assembler file (see // ): remove any preexisting // output object file. - util::remove_nfs_safe(ctx.args_info.output_obj, util::LogFailure::no); + std::ignore = + util::remove_nfs_safe(ctx.args_info.output_obj, util::LogFailure::no); } if (ctx.args_info.generating_diagnostics) { @@ -1293,7 +1294,12 @@ to_cache(Context& ctx, } if (ctx.args_info.generating_dependencies) { - depfile::make_paths_relative_in_output_dep(ctx); + if (auto r = depfile::make_paths_relative_in_output_dep(ctx); !r) { + LOG("Failed to make paths relative in {}: {}", + ctx.args_info.output_dep, + r.error()); + return tl::unexpected(Statistic::internal_error); + } } if (!ctx.args_info.expect_output_obj) { @@ -1445,7 +1451,10 @@ get_result_key_from_cpp(Context& ctx, util::Args& args, Hash& hash) } if (is_clang_cu) { - util::write_file(preprocessed_path, cpp_stdout_data); + if (auto r = util::write_file(preprocessed_path, cpp_stdout_data); !r) { + LOG("Failed to write {}: {}", preprocessed_path, r.error()); + return tl::unexpected(Statistic::internal_error); + } auto chunks = util::split_preprocessed_file_from_clang_cuda(preprocessed_path); for (size_t i = 0; i < chunks.size(); ++i) { diff --git a/src/ccache/context.cpp b/src/ccache/context.cpp index 681eec93..33b9b577 100644 --- a/src/ccache/context.cpp +++ b/src/ccache/context.cpp @@ -104,7 +104,7 @@ Context::unlink_pending_tmp_files() for (auto it = m_pending_tmp_files.rbegin(); it != m_pending_tmp_files.rend(); ++it) { - util::remove(*it, util::LogFailure::no); + std::ignore = util::remove(*it, util::LogFailure::no); } m_pending_tmp_files.clear(); } diff --git a/src/ccache/core/atomicfile.cpp b/src/ccache/core/atomicfile.cpp index d5013280..6660987e 100644 --- a/src/ccache/core/atomicfile.cpp +++ b/src/ccache/core/atomicfile.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2024 Joel Rosdahl and other contributors +// Copyright (C) 2019-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -43,8 +43,8 @@ AtomicFile::~AtomicFile() { if (m_stream) { // commit() was not called so remove the lingering temporary file. - std::ignore = fclose(m_stream); // Not much to do if fclose fails here - util::remove(m_tmp_path); + std::ignore = fclose(m_stream); // Not much to do if this fails + std::ignore = util::remove(m_tmp_path); // Or this } } @@ -82,7 +82,7 @@ AtomicFile::commit() int retcode = fclose(m_stream); m_stream = nullptr; if (retcode == EOF) { - util::remove(m_tmp_path); + std::ignore = util::remove(m_tmp_path); throw core::Error( FMT("failed to write data to {}: {}", m_path, strerror(errno))); } diff --git a/src/ccache/core/mainoptions.cpp b/src/ccache/core/mainoptions.cpp index e4507e87..ec235215 100644 --- a/src/ccache/core/mainoptions.cpp +++ b/src/ccache/core/mainoptions.cpp @@ -614,11 +614,17 @@ process_main_options(int argc, const char* const* argv) util::XXH3_128 checksum; util::Fd fd(arg == "-" ? STDIN_FILENO : open(arg.c_str(), O_RDONLY)); if (fd) { - util::read_fd(*fd, [&checksum](auto data) { checksum.update(data); }); + auto r = + util::read_fd(*fd, [&checksum](auto data) { checksum.update(data); }); + if (!r) { + PRINT(stderr, "Error: Failed to checksum {}: {}\n", arg, r.error()); + return EXIT_FAILURE; + } const auto digest = checksum.digest(); PRINT(stdout, "{}\n", util::format_base16(digest)); } else { PRINT(stderr, "Error: Failed to checksum {}\n", arg); + return EXIT_FAILURE; } break; } diff --git a/src/ccache/depfile.cpp b/src/ccache/depfile.cpp index f3c04974..011bbb94 100644 --- a/src/ccache/depfile.cpp +++ b/src/ccache/depfile.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -92,26 +93,24 @@ rewrite_source_paths(const Context& ctx, std::string_view content) } // Replace absolute paths with relative paths in the provided dependency file. -void +tl::expected make_paths_relative_in_output_dep(const Context& ctx) { if (ctx.config.base_dir().empty()) { LOG_RAW("Base dir not set, skip using relative paths"); - return; // nothing to do + return {}; // nothing to do } const auto& output_dep = ctx.args_info.output_dep; - const auto content = util::read_file(output_dep); - if (!content) { - LOG("Failed to read dependency file {}: {}", output_dep, content.error()); - return; - } - const auto new_content = rewrite_source_paths(ctx, *content); + TRY_ASSIGN(auto content, util::read_file(output_dep)); + const auto new_content = rewrite_source_paths(ctx, content); if (new_content) { - util::write_file(output_dep, *new_content); + TRY(util::write_file(output_dep, *new_content)); } else { LOG("No paths in dependency file {} made relative", output_dep); } + + return {}; } std::vector diff --git a/src/ccache/depfile.hpp b/src/ccache/depfile.hpp index d3b69924..13bc849f 100644 --- a/src/ccache/depfile.hpp +++ b/src/ccache/depfile.hpp @@ -20,6 +20,8 @@ class Context; +#include + #include #include #include @@ -32,7 +34,8 @@ std::string escape_filename(std::string_view filename); std::optional rewrite_source_paths(const Context& ctx, std::string_view file_content); -void make_paths_relative_in_output_dep(const Context& ctx); +tl::expected +make_paths_relative_in_output_dep(const Context& ctx); // Split `text` into tokens. A colon token delimits the target tokens from // dependency tokens. An empty token marks the end of an entry. diff --git a/src/ccache/execute.cpp b/src/ccache/execute.cpp index aa510514..b133cae1 100644 --- a/src/ccache/execute.cpp +++ b/src/ccache/execute.cpp @@ -209,7 +209,7 @@ win32execute(const char* const* argv, fs::path tmp_file_path; DEFER([&] { if (!tmp_file_path.empty()) { - util::remove(tmp_file_path); + std::ignore = util::remove(tmp_file_path); } }); @@ -218,7 +218,12 @@ win32execute(const char* const* argv, util::TemporaryFile::create(FMT("{}/cmd_args", temp_dir))); LOG("Arguments from {}", tmp_file.path); commandline = util::format_argv_as_win32_command_string(argv + 1, true); - util::write_fd(*tmp_file.fd, commandline.data(), commandline.length()); + if (auto r = util::write_fd( + *tmp_file.fd, commandline.data(), commandline.length()); + !r) { + LOG("Failed to write {}: {}", tmp_file.path, r.error()); + return -1; + } commandline = FMT(R"("{}" "@{}")", argv[0], tmp_file.path); tmp_file_path = tmp_file.path; } diff --git a/src/ccache/inodecache.cpp b/src/ccache/inodecache.cpp index a4771fd8..0d4c944e 100644 --- a/src/ccache/inodecache.cpp +++ b/src/ccache/inodecache.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2024 Joel Rosdahl and other contributors +// Copyright (C) 2020-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -285,7 +285,7 @@ InodeCache::mmap_file(const fs::path& path) k_version); map->unmap(); m_fd.close(); - fs::remove(path); + std::ignore = util::remove(path); return false; } m_map = std::move(*map); diff --git a/src/ccache/storage/local/localstorage.cpp b/src/ccache/storage/local/localstorage.cpp index 20aa37af..ccf2cf4c 100644 --- a/src/ccache/storage/local/localstorage.cpp +++ b/src/ccache/storage/local/localstorage.cpp @@ -346,7 +346,7 @@ clean_dir( // Delete any tmp files older than 1 hour right away. if (file.mtime() + util::Duration(3600) < current_time && util::TemporaryFile::is_tmp_file(file.path())) { - util::remove(file.path()); + std::ignore = util::remove(file.path()); continue; } @@ -605,7 +605,7 @@ LocalStorage::remove(const Hash::Digest& key, const core::CacheEntryType type) if (!l2_content_lock.acquire()) { LOG("Not removing {} due to lock failure", cache_file.path); } - util::remove_nfs_safe(cache_file.path); + std::ignore = util::remove_nfs_safe(cache_file.path); } LOG("Removed {} from local storage ({})", @@ -696,7 +696,7 @@ LocalStorage::clone_hard_link_or_copy_file(const fs::path& source, // run, but it's only we who can create the file entry now so we don't try // to handle a race between remove() and create_hard_link() below. - fs::remove(dest); // Ignore any error. + std::ignore = fs::remove(dest); // Ignore any error. LOG("Hard linking {} to {}", source, dest); if (auto result = fs::create_hard_link(source, dest); !result) { LOG("Failed to hard link {} to {}: {}", @@ -820,7 +820,7 @@ LocalStorage::wipe_all(const ProgressReceiver& progress_receiver) l2_progress_receiver(0.5); for (size_t i = 0; i < files.size(); ++i) { - util::remove_nfs_safe(files[i].path()); + std::ignore = util::remove_nfs_safe(files[i].path()); l2_progress_receiver(0.5 + 0.5 * ratio(i, files.size())); } @@ -1082,9 +1082,10 @@ LocalStorage::move_to_wanted_cache_level(const StatisticsCounters& counters, // Note: Two ccache processes may move the file at the same time, so failure // to rename is OK. LOG("Moving {} to {}", cache_file_path, wanted_path); - fs::rename(cache_file_path, wanted_path); + std::ignore = fs::rename(cache_file_path, wanted_path); for (const auto& [file_number, dest_path] : m_added_raw_files) { - fs::rename(dest_path, get_raw_file_path(wanted_path, file_number)); + std::ignore = + fs::rename(dest_path, get_raw_file_path(wanted_path, file_number)); } } } @@ -1461,7 +1462,8 @@ LocalStorage::clean_internal_tempdir() LOG("Cleaning up {}", m_config.temporary_dir()); core::ensure_dir_exists(m_config.temporary_dir()); - util::traverse_directory(m_config.temporary_dir(), [now](const auto& de) { + + auto remove_old = [now](const auto& de) { if (de.is_directory()) { return; } @@ -1474,11 +1476,15 @@ LocalStorage::clean_internal_tempdir() LOG("Removal failed: {}", result.error().message()); } } - }).or_else([&](const auto& error) { - LOG("Failed to clean up {}: {}", m_config.temporary_dir(), error); - }); + }; + if (auto r = util::traverse_directory(m_config.temporary_dir(), remove_old); + !r) { + LOG("Failed to clean up {}: {}", m_config.temporary_dir(), r.error()); + } - util::write_file(cleaned_stamp, ""); + if (auto r = util::write_file(cleaned_stamp, ""); !r) { + LOG("Failed to create {}: {}", cleaned_stamp, r.error()); + } } fs::path diff --git a/src/ccache/util/exec.cpp b/src/ccache/util/exec.cpp index 49ed7b3e..c3ecf686 100644 --- a/src/ccache/util/exec.cpp +++ b/src/ccache/util/exec.cpp @@ -130,18 +130,19 @@ exec_to_string(const Args& args) pid_t pid; auto argv_mutable = const_cast(argv.data()); - int result = posix_spawnp(&pid, argv[0], &fa, nullptr, argv_mutable, environ); + int spawn_result = + posix_spawnp(&pid, argv[0], &fa, nullptr, argv_mutable, environ); int saved_errno = errno; posix_spawn_file_actions_destroy(&fa); close(pipefd[1]); - if (result != 0) { + if (spawn_result != 0) { close(pipefd[0]); return tl::unexpected( FMT("posix_spawnp failed: {}", strerror(saved_errno))); } - read_fd(pipefd[0], [&](auto data) { + auto read_result = read_fd(pipefd[0], [&](auto data) { output.append(reinterpret_cast(data.data()), data.size()); }); @@ -151,6 +152,9 @@ exec_to_string(const Args& args) return tl::unexpected(FMT("waitpid failed: {}", strerror(errno))); } } + if (!read_result) { + return tl::unexpected(FMT("failed to read pipe: {}", read_result.error())); + } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { return tl::unexpected(FMT("Non-zero exit code: {}", WEXITSTATUS(status))); } diff --git a/src/ccache/util/file.cpp b/src/ccache/util/file.cpp index 183d04bb..aa201f38 100644 --- a/src/ccache/util/file.cpp +++ b/src/ccache/util/file.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2024 Joel Rosdahl and other contributors +// Copyright (C) 2021-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -109,9 +109,22 @@ copy_file_impl(const fs::path& src, static tl::expected copy_fd(int src_fd, int dst_fd) { - return read_fd(src_fd, [&](nonstd::span data) { - write_fd(dst_fd, data.data(), data.size()); + std::optional write_error; + auto read_result = read_fd(src_fd, [&](nonstd::span data) { + auto result = write_fd(dst_fd, data.data(), data.size()); + if (!result) { + write_error = result.error(); + } }); + if (write_error) { + return tl::unexpected( + FMT("failed to write to FD {}: {}", dst_fd, *write_error)); + } + if (!read_result) { + return tl::unexpected( + FMT("failed to read from FD {}: {}", src_fd, read_result.error())); + } + return {}; } static tl::expected @@ -605,7 +618,7 @@ traverse_directory(const fs::path& directory, is_dir = dir_entry.is_directory(); } if (is_dir) { - traverse_directory(path, visitor); + TRY(traverse_directory(path, visitor)); } else { visitor(path); } @@ -635,7 +648,7 @@ traverse_directory(const fs::path& directory, try { for (const auto& entry : fs::directory_iterator(directory)) { if (entry.is_directory()) { - traverse_directory(entry.path(), visitor); + TRY(traverse_directory(entry.path(), visitor)); } else { visitor(entry.path()); } diff --git a/src/ccache/util/lockfile.cpp b/src/ccache/util/lockfile.cpp index 69388b96..8eac5a3c 100644 --- a/src/ccache/util/lockfile.cpp +++ b/src/ccache/util/lockfile.cpp @@ -162,8 +162,12 @@ LockFile::release() if (m_lock_manager) { m_lock_manager->deregister_alive_file(m_alive_file); } - fs::remove(m_alive_file); - fs::remove(m_lock_file); + if (auto r = fs::remove(m_alive_file); !r) { + LOG("Failed to remove {}: {}", m_alive_file, r.error()); + } + if (auto r = fs::remove(m_lock_file); !r) { + LOG("Failed to remove {}: {}", m_lock_file, r.error()); + } #else CloseHandle(m_handle); #endif diff --git a/unittest/main.cpp b/unittest/main.cpp index fb298d26..58286f52 100644 --- a/unittest/main.cpp +++ b/unittest/main.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2024 Joel Rosdahl and other contributors +// Copyright (C) 2010-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -17,6 +17,7 @@ // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include +#include #include #include #include @@ -29,32 +30,47 @@ # include #endif +#include + namespace fs = util::filesystem; -int -main(int argc, char** argv) +tl::expected +prepare_test(int argc, char** argv) { -#ifdef _WIN32 - util::setenv("_CCACHE_TEST", "1"); -#endif - util::unsetenv("GCC_COLORS"); // Don't confuse argument processing tests. - auto dir_before = *fs::current_path(); - std::string testdir = FMT("testdir/{}", getpid()); - fs::remove_all(testdir); - fs::create_directories(testdir); - fs::current_path(testdir); + fs::path testdir = FMT("testdir/{}", getpid()); + + TRY(fs::remove_all(testdir)); + TRY(fs::create_directories(testdir)); + TRY(fs::current_path(testdir)); doctest::Context context; context.applyCommandLine(argc, argv); int result = context.run(); - if (result == 0) { - fs::current_path(dir_before); - fs::remove_all(testdir); + if (result == EXIT_SUCCESS) { + TRY(fs::current_path(dir_before)); + TRY(fs::remove_all(testdir)); } else { PRINT(stderr, "Note: Test data has been left in {}\n", testdir); } return result; } + +int +main(int argc, char** argv) +{ +#ifdef _WIN32 + util::setenv("_CCACHE_TEST", "1"); +#endif + util::unsetenv("GCC_COLORS"); // Don't confuse argument processing tests. + + auto result = prepare_test(argc, argv); + if (result) { + return *result; + } else { + PRINT(stderr, "error: {}\n", result.error()); + return EXIT_FAILURE; + } +} diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index 5e91902a..4c2a97f4 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -65,7 +65,7 @@ TEST_CASE("pass -fsyntax-only to compiler only") Context ctx; ctx.orig_args = Args::from_string("cc -c foo.c -fsyntax-only"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -82,7 +82,7 @@ TEST_CASE("dash_E_should_result_in_called_for_preprocessing") Context ctx; ctx.orig_args = Args::from_string("cc -c foo.c -E"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); CHECK(process_args(ctx).error() == Statistic::called_for_preprocessing); } @@ -93,7 +93,7 @@ TEST_CASE("dash_M_should_be_unsupported") Context ctx; ctx.orig_args = Args::from_string("cc -c foo.c -M"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); CHECK(process_args(ctx).error() == Statistic::unsupported_compiler_option); } @@ -105,7 +105,7 @@ TEST_CASE("dependency_args_to_compiler") " -Wp,-MT,wpmt -Wp,-MQ,wpmq -Wp,-MF,wpf"; Context ctx; ctx.orig_args = Args::from_string("cc " + dep_args + " -c foo.c -o foo.o"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -128,7 +128,7 @@ TEST_CASE("cpp_only_args_to_preprocessor_and_compiler") Context ctx; ctx.orig_args = Args::from_string("cc " + cpp_args + " " + dep_args + " -c foo.c -o foo.o"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -146,7 +146,7 @@ TEST_CASE( const std::string dep_args = "-MMD -MFfoo.d -MT mt -MTmt -MQmq"; Context ctx; ctx.orig_args = Args::from_string("cc -c " + dep_args + " foo.c -o foo.o"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -161,7 +161,7 @@ TEST_CASE("equal_sign_after_MF_should_be_removed") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("cc -c -MF=path foo.c -o foo.o"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -177,7 +177,7 @@ TEST_CASE("sysroot_should_be_rewritten_if_basedir_is_used") Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc --sysroot={}/foo/bar -c foo.c", ctx.actual_cwd); @@ -199,7 +199,7 @@ TEST_CASE( Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc --sysroot {}/foo -c foo.c", ctx.actual_cwd); ctx.orig_args = Args::from_string(arg_string); @@ -216,7 +216,7 @@ TEST_CASE("fbuild_session_file_should_be_rewritten_if_basedir_is_used") Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc -fbuild-session-file={}/foo/bar -c foo.c", ctx.actual_cwd); @@ -241,7 +241,7 @@ TEST_CASE( {"sloppiness", "ivfsoverlay"} }); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc -ivfsoverlay {}/foo -c foo.c", ctx.actual_cwd); @@ -264,7 +264,7 @@ TEST_CASE( {"sloppiness", "modules"} }); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc -fmodules-cache-path={}/foo/bar -c foo.c", ctx.actual_cwd); @@ -290,7 +290,7 @@ TEST_CASE( {"sloppiness", "modules"} }); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc -fmodule-map-file={}/foo/bar -c foo.c", ctx.actual_cwd); @@ -313,7 +313,7 @@ TEST_CASE("MF_flag_with_immediate_argument_should_work_as_last_argument") ctx.orig_args = Args::from_string("cc -c foo.c -o foo.o -MMD -MT bar -MFfoo.d"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); CHECK(result); @@ -330,7 +330,7 @@ TEST_CASE("MT_flag_with_immediate_argument_should_work_as_last_argument") ctx.orig_args = Args::from_string("cc -c foo.c -o foo.o -MMD -MFfoo.d -MT foo -MTbar"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); CHECK(result); @@ -349,7 +349,7 @@ TEST_CASE("MQ_flag_with_immediate_argument_should_work_as_last_argument") ctx.orig_args = Args::from_string("cc -c foo.c -o foo.o -MMD -MFfoo.d -MQ foo -MQbar"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); CHECK(result); @@ -365,7 +365,7 @@ TEST_CASE("MQ_flag_without_immediate_argument_should_not_add_MQobj") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MQ foo.d foo.c"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -381,7 +381,7 @@ TEST_CASE("MT_flag_without_immediate_argument_should_not_add_MTobj") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MT foo.d foo.c"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -397,7 +397,7 @@ TEST_CASE("MQ_flag_with_immediate_argument_should_not_add_MQobj") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MQfoo.d foo.c"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -413,7 +413,7 @@ TEST_CASE("MT_flag_with_immediate_argument_should_not_add_MQobj") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("gcc -c -MD -MP -MFfoo.d -MTfoo.d foo.c"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -431,7 +431,7 @@ TEST_CASE( Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir(get_root()); std::string arg_string = FMT("cc -isystem {}/foo -c foo.c", ctx.actual_cwd); ctx.orig_args = Args::from_string(arg_string); @@ -448,7 +448,7 @@ TEST_CASE("isystem_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used") Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir("/"); std::string cwd = ctx.actual_cwd; std::string arg_string = FMT("cc -isystem{}/foo -c foo.c", cwd); @@ -465,7 +465,7 @@ TEST_CASE("I_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used") Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.config.set_base_dir("/"); std::string cwd = *fs::current_path(); std::string arg_string = FMT("cc -I{}/foo -c foo.c", cwd); @@ -482,7 +482,7 @@ TEST_CASE("debug_flag_order_with_known_option_first") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("cc -g1 -gsplit-dwarf foo.c -c"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -497,7 +497,7 @@ TEST_CASE("debug_flag_order_with_known_option_last") TestContext test_context; Context ctx; ctx.orig_args = Args::from_string("cc -gsplit-dwarf -g1 foo.c -c"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -513,7 +513,7 @@ TEST_CASE("options_not_to_be_passed_to_the_preprocessor") Context ctx; ctx.orig_args = Args::from_string( "cc -Wa,foo foo.c -g -c -DX -Werror -Xlinker fie -Xlinker,fum -Wno-error"); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); @@ -531,9 +531,9 @@ TEST_CASE("cuda_option_file") Context ctx; ctx.config.set_compiler_type(CompilerType::nvcc); ctx.orig_args = Args::from_string("nvcc -optf foo.optf,bar.optf"); - util::write_file("foo.c", ""); - util::write_file("foo.optf", "-c foo.c -g -Wall -o"); - util::write_file("bar.optf", "out -DX"); + REQUIRE(util::write_file("foo.c", "")); + REQUIRE(util::write_file("foo.optf", "-c foo.c -g -Wall -o")); + REQUIRE(util::write_file("bar.optf", "out -DX")); const auto result = process_args(ctx); @@ -551,7 +551,7 @@ TEST_CASE("nvcc_warning_flags_short") ctx.config.set_compiler_type(CompilerType::nvcc); ctx.orig_args = Args::from_string("nvcc -Werror all-warnings -Xcompiler -Werror -c foo.cu"); - util::write_file("foo.cu", ""); + REQUIRE(util::write_file("foo.cu", "")); const auto result = process_args(ctx); CHECK(result); @@ -569,7 +569,7 @@ TEST_CASE("nvcc_warning_flags_long") ctx.config.set_compiler_type(CompilerType::nvcc); ctx.orig_args = Args::from_string( "nvcc --Werror all-warnings -Xcompiler -Werror -c foo.cu"); - util::write_file("foo.cu", ""); + REQUIRE(util::write_file("foo.cu", "")); const auto result = process_args(ctx); CHECK(result); @@ -604,7 +604,7 @@ TEST_CASE("-Xclang") ctx.orig_args = Args::from_string("clang -c foo.c " + common_args + " " + color_diag + " " + extra_args + " " + pch_pth_variants); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); const auto result = process_args(ctx); CHECK(result->preprocessor_args.to_string() @@ -619,7 +619,7 @@ TEST_CASE("-x") { TestContext test_context; Context ctx; - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); SUBCASE("intel option") { @@ -700,7 +700,7 @@ TEST_CASE("MSVC options" Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); ctx.orig_args = Args::from_string( FMT("cl.exe /Fobar.obj /c {}/foo.c /foobar", ctx.actual_cwd)); @@ -715,9 +715,9 @@ TEST_CASE("MSVC PCH options") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("foo.cpp", ""); - util::write_file("pch.h", ""); - util::write_file("pch.cpp", ""); + REQUIRE(util::write_file("foo.cpp", "")); + REQUIRE(util::write_file("pch.h", "")); + REQUIRE(util::write_file("pch.cpp", "")); SUBCASE("Create PCH") { @@ -734,7 +734,7 @@ TEST_CASE("MSVC PCH options") == "cl.exe /Ycpch.h /Fppch.cpp.pch /FIpch.h /c"); } - util::write_file("pch.cpp.pch", ""); + REQUIRE(util::write_file("pch.cpp.pch", "")); ctx.config.update_from_map({ {"sloppiness", "pch_defines,time_macros"} }); @@ -760,9 +760,9 @@ TEST_CASE("MSVC PCH options with empty -Yc") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("foo.cpp", ""); - util::write_file("pch.h", ""); - util::write_file("pch.cpp", ""); + REQUIRE(util::write_file("foo.cpp", "")); + REQUIRE(util::write_file("pch.h", "")); + REQUIRE(util::write_file("pch.cpp", "")); SUBCASE("Create PCH") { @@ -779,7 +779,7 @@ TEST_CASE("MSVC PCH options with empty -Yc") == "cl.exe /Yc /Fppch.cpp.pch /FIpch.h /c"); } - util::write_file("pch.cpp.pch", ""); + REQUIRE(util::write_file("pch.cpp.pch", "")); ctx.config.update_from_map({ {"sloppiness", "pch_defines,time_macros"} }); @@ -805,9 +805,9 @@ TEST_CASE("MSVC PCH options with empty -Yc and without -Fp") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("foo.cpp", ""); - util::write_file("pch.h", ""); - util::write_file("pch.cpp", ""); + REQUIRE(util::write_file("foo.cpp", "")); + REQUIRE(util::write_file("pch.h", "")); + REQUIRE(util::write_file("pch.cpp", "")); SUBCASE("Create PCH") { @@ -821,7 +821,7 @@ TEST_CASE("MSVC PCH options with empty -Yc and without -Fp") CHECK(result->compiler_args.to_string() == "cl.exe /Yc /c"); } - util::write_file("pch.pch", ""); + REQUIRE(util::write_file("pch.pch", "")); ctx.config.update_from_map({ {"sloppiness", "pch_defines,time_macros"} }); @@ -847,9 +847,9 @@ TEST_CASE("MSVC PCH options with empty -Yc and without -Fp and -Fo") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("foo.cpp", ""); - util::write_file("pch.h", ""); - util::write_file("pch.cpp", ""); + REQUIRE(util::write_file("foo.cpp", "")); + REQUIRE(util::write_file("pch.h", "")); + REQUIRE(util::write_file("pch.cpp", "")); SUBCASE("Create PCH") { @@ -863,7 +863,7 @@ TEST_CASE("MSVC PCH options with empty -Yc and without -Fp and -Fo") CHECK(result->compiler_args.to_string() == "cl.exe /Yc /c"); } - util::write_file("pch.pch", ""); + REQUIRE(util::write_file("pch.pch", "")); ctx.config.update_from_map({ {"sloppiness", "pch_defines,time_macros"} }); @@ -889,8 +889,8 @@ TEST_CASE("MSVC PCH unsupported options") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("pch.h", ""); - util::write_file("pch.cpp", ""); + REQUIRE(util::write_file("pch.h", "")); + REQUIRE(util::write_file("pch.cpp", "")); SUBCASE("/Fp with absolute folder path") { @@ -919,7 +919,7 @@ TEST_CASE("MSVC debug information format options") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::msvc); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); SUBCASE("Only /Z7") { @@ -968,7 +968,7 @@ TEST_CASE("ClangCL Debug information options") TestContext test_context; Context ctx; ctx.config.set_compiler_type(CompilerType::clang_cl); - util::write_file("foo.c", ""); + REQUIRE(util::write_file("foo.c", "")); SUBCASE("/Z7") { diff --git a/unittest/test_ccache.cpp b/unittest/test_ccache.cpp index 9b43a116..c8d1cc47 100644 --- a/unittest/test_ccache.cpp +++ b/unittest/test_ccache.cpp @@ -206,7 +206,7 @@ TEST_CASE("guess_compiler") SUBCASE("Follow symlink to actual compiler") { const auto cwd = *fs::current_path(); - util::write_file(cwd / "gcc", ""); + REQUIRE(util::write_file(cwd / "gcc", "")); CHECK(fs::create_symlink("gcc", cwd / "intermediate")); const auto cc = cwd / "cc"; CHECK(fs::create_symlink("intermediate", cc)); @@ -217,7 +217,7 @@ TEST_CASE("guess_compiler") SUBCASE("Classify clang-cl symlink to clang") { const auto cwd = *fs::current_path(); - util::write_file(cwd / "clang", ""); + REQUIRE(util::write_file(cwd / "clang", "")); const auto clang_cl = cwd / "clang-cl"; CHECK(fs::create_symlink("clang", clang_cl)); @@ -229,7 +229,7 @@ TEST_CASE("guess_compiler") const auto cwd = *fs::current_path(); const auto cc = cwd / "cc"; const auto gcc = cwd / "gcc"; - util::write_file(cwd / "cc", ""); + REQUIRE(util::write_file(cwd / "cc", "")); CHECK(fs::create_hard_link(cc, gcc)); CHECK(guess_compiler(cc) == CompilerType::gcc); @@ -240,7 +240,7 @@ TEST_CASE("guess_compiler") const auto cwd = *fs::current_path(); const auto cc = cwd / "cc"; const auto clang = cwd / "clang"; - util::write_file(cwd / "cc", ""); + REQUIRE(util::write_file(cwd / "cc", "")); CHECK(fs::create_hard_link(cc, clang)); CHECK(guess_compiler(cc) == CompilerType::clang); @@ -252,7 +252,7 @@ TEST_CASE("guess_compiler") const auto cc = cwd / "cc"; const auto gcc = cwd / "gcc"; const auto clang = cwd / "clang"; - util::write_file(cwd / "cc", ""); + REQUIRE(util::write_file(cwd / "cc", "")); CHECK(fs::create_hard_link(cc, gcc)); CHECK(fs::create_hard_link(cc, clang)); diff --git a/unittest/test_config.cpp b/unittest/test_config.cpp index c0c4e46f..e6b5a00b 100644 --- a/unittest/test_config.cpp +++ b/unittest/test_config.cpp @@ -98,52 +98,55 @@ TEST_CASE("Config::update_from_file") std::string base_dir = FMT("C:/{0}/foo/{0}", user); #endif - util::write_file( + REQUIRE(util::write_file( "ccache.conf", - "base_dir = " + base_dir + "\n" - "cache_dir=\n" - "cache_dir = $USER$/${USER}/.ccache\n" - "\n" - "\n" - " #A comment\n" - "\t compiler = foo\n" - "compiler_check = none\n" - "compiler_type = nvcc\n" - "compression=false\n" - "compression_level= 2\n" - "cpp_extension = .foo\n" - "debug_dir = $USER$/${USER}/.ccache_debug\n" - "debug_level = 2\n" - "depend_mode = true\n" - "direct_mode = false\n" - "disable = true\n" - "extra_files_to_hash = a:b c:$USER\n" - "file_clone = true\n" - "hard_link = true\n" - "hash_dir = false\n" - "ignore_headers_in_manifest = a:b/c\n" - "ignore_options = -a=* -b\n" - "inode_cache = false\n" - "keep_comments_cpp = true\n" - "log_file = $USER${USER} \n" - "max_files = 17\n" - "max_size = 123M\n" - "msvc_dep_prefix = Some other prefix:\n" - "path = $USER.x\n" - "pch_external_checksum = true\n" - "prefix_command = x$USER\n" - "prefix_command_cpp = y\n" - "read_only = true\n" - "read_only_direct = true\n" - "recache = true\n" - "reshare = true\n" - "sloppiness = time_macros ,include_file_mtime" - " include_file_ctime,file_stat_matches,file_stat_matches_ctime,pch_defines" - " , no_system_headers,system_headers,clang_index_store,ivfsoverlay," - " gcno_cwd,\n" - "stats = false\n" - "temporary_dir = ${USER}_foo\n" - "umask = 777"); // Note: no newline. + "base_dir = " + base_dir + + "\n" + "cache_dir=\n" + "cache_dir = $USER$/${USER}/.ccache\n" + "\n" + "\n" + " #A comment\n" + "\t compiler = foo\n" + "compiler_check = none\n" + "compiler_type = nvcc\n" + "compression=false\n" + "compression_level= 2\n" + "cpp_extension = .foo\n" + "debug_dir = $USER$/${USER}/.ccache_debug\n" + "debug_level = 2\n" + "depend_mode = true\n" + "direct_mode = false\n" + "disable = true\n" + "extra_files_to_hash = a:b c:$USER\n" + "file_clone = true\n" + "hard_link = true\n" + "hash_dir = false\n" + "ignore_headers_in_manifest = a:b/c\n" + "ignore_options = -a=* -b\n" + "inode_cache = false\n" + "keep_comments_cpp = true\n" + "log_file = $USER${USER} \n" + "max_files = 17\n" + "max_size = 123M\n" + "msvc_dep_prefix = Some other prefix:\n" + "path = $USER.x\n" + "pch_external_checksum = true\n" + "prefix_command = x$USER\n" + "prefix_command_cpp = y\n" + "read_only = true\n" + "read_only_direct = true\n" + "recache = true\n" + "reshare = true\n" + "sloppiness = time_macros ,include_file_mtime" + " " + "include_file_ctime,file_stat_matches,file_stat_matches_ctime,pch_" + "defines" + " , no_system_headers,system_headers,clang_index_store,ivfsoverlay," + " gcno_cwd,\n" + "stats = false\n" + "temporary_dir = ${USER}_foo\n" + "umask = 777")); // Note: no newline. Config config; REQUIRE(config.update_from_file("ccache.conf")); @@ -204,31 +207,31 @@ TEST_CASE("Config::update_from_file, error handling") SUBCASE("missing equal sign") { - util::write_file("ccache.conf", "no equal sign"); + REQUIRE(util::write_file("ccache.conf", "no equal sign")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: missing equal sign"); } SUBCASE("unknown key") { - util::write_file("ccache.conf", "# Comment\nfoo = bar"); + REQUIRE(util::write_file("ccache.conf", "# Comment\nfoo = bar")); CHECK(config.update_from_file("ccache.conf")); } SUBCASE("invalid bool") { - util::write_file("ccache.conf", "disable="); + REQUIRE(util::write_file("ccache.conf", "disable=")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: not a boolean value: \"\""); - util::write_file("ccache.conf", "disable=foo"); + REQUIRE(util::write_file("ccache.conf", "disable=foo")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: not a boolean value: \"foo\""); } SUBCASE("invalid variable reference") { - util::write_file("ccache.conf", "base_dir = ${foo"); + REQUIRE(util::write_file("ccache.conf", "base_dir = ${foo")); REQUIRE_THROWS_WITH( config.update_from_file("ccache.conf"), "ccache.conf:1: syntax error: missing '}' after \"foo\""); @@ -237,14 +240,14 @@ TEST_CASE("Config::update_from_file, error handling") SUBCASE("empty umask") { - util::write_file("ccache.conf", "umask = "); + REQUIRE(util::write_file("ccache.conf", "umask = ")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.umask() == std::nullopt); } SUBCASE("invalid size") { - util::write_file("ccache.conf", "max_size = foo"); + REQUIRE(util::write_file("ccache.conf", "max_size = foo")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: invalid size: \"foo\""); // Other cases tested in test_Util.c. @@ -252,7 +255,7 @@ TEST_CASE("Config::update_from_file, error handling") SUBCASE("unknown sloppiness") { - util::write_file("ccache.conf", "sloppiness = time_macros, foo"); + REQUIRE(util::write_file("ccache.conf", "sloppiness = time_macros, foo")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.sloppiness().to_bitmask() == static_cast(core::Sloppy::time_macros)); @@ -260,15 +263,15 @@ TEST_CASE("Config::update_from_file, error handling") SUBCASE("invalid unsigned") { - util::write_file("ccache.conf", "max_files ="); + REQUIRE(util::write_file("ccache.conf", "max_files =")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: invalid unsigned integer: \"\""); - util::write_file("ccache.conf", "max_files = -42"); + REQUIRE(util::write_file("ccache.conf", "max_files = -42")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: invalid unsigned integer: \"-42\""); - util::write_file("ccache.conf", "max_files = foo"); + REQUIRE(util::write_file("ccache.conf", "max_files = foo")); REQUIRE_THROWS_WITH(config.update_from_file("ccache.conf"), "ccache.conf:1: invalid unsigned integer: \"foo\""); } @@ -280,12 +283,12 @@ TEST_CASE("Config::update_from_file, error handling") SUBCASE("relative base dir") { - util::write_file("ccache.conf", "base_dir = relative/path"); + REQUIRE(util::write_file("ccache.conf", "base_dir = relative/path")); REQUIRE_THROWS_WITH( config.update_from_file("ccache.conf"), "ccache.conf:1: not an absolute path: \"relative/path\""); - util::write_file("ccache.conf", "base_dir ="); + REQUIRE(util::write_file("ccache.conf", "base_dir =")); CHECK(config.update_from_file("ccache.conf")); } } @@ -313,7 +316,7 @@ TEST_CASE("Config::response_file_format") SUBCASE("from config gcc") { - util::write_file("ccache.conf", "response_file_format = posix"); + REQUIRE(util::write_file("ccache.conf", "response_file_format = posix")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.response_file_format() == ResponseFileFormat::posix); @@ -321,7 +324,7 @@ TEST_CASE("Config::response_file_format") SUBCASE("from config msvc") { - util::write_file("ccache.conf", "response_file_format = windows"); + REQUIRE(util::write_file("ccache.conf", "response_file_format = windows")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.response_file_format() == ResponseFileFormat::windows); @@ -329,8 +332,8 @@ TEST_CASE("Config::response_file_format") SUBCASE("from config msvc with clang compiler") { - util::write_file("ccache.conf", - "response_file_format = windows\ncompiler_type = clang"); + REQUIRE(util::write_file( + "ccache.conf", "response_file_format = windows\ncompiler_type = clang")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.response_file_format() == ResponseFileFormat::windows); @@ -338,7 +341,7 @@ TEST_CASE("Config::response_file_format") SUBCASE("guess from compiler gcc") { - util::write_file("ccache.conf", "compiler_type = clang"); + REQUIRE(util::write_file("ccache.conf", "compiler_type = clang")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.response_file_format() == ResponseFileFormat::posix); @@ -346,7 +349,7 @@ TEST_CASE("Config::response_file_format") SUBCASE("guess from compiler msvc") { - util::write_file("ccache.conf", "compiler_type = msvc"); + REQUIRE(util::write_file("ccache.conf", "compiler_type = msvc")); CHECK(config.update_from_file("ccache.conf")); CHECK(config.response_file_format() == ResponseFileFormat::windows); @@ -360,7 +363,7 @@ TEST_CASE("Config::set_value_in_file") SUBCASE("set new value") { - util::write_file("ccache.conf", "path = vanilla\n"); + REQUIRE(util::write_file("ccache.conf", "path = vanilla\n")); config.set_value_in_file("ccache.conf", "compiler", "chocolate"); std::string content = *util::read_file("ccache.conf"); CHECK(content == "path = vanilla\ncompiler = chocolate\n"); @@ -368,7 +371,8 @@ TEST_CASE("Config::set_value_in_file") SUBCASE("existing value") { - util::write_file("ccache.conf", "path = chocolate\nstats = chocolate\n"); + REQUIRE( + util::write_file("ccache.conf", "path = chocolate\nstats = chocolate\n")); config.set_value_in_file("ccache.conf", "path", "vanilla"); std::string content = *util::read_file("ccache.conf"); CHECK(content == "path = vanilla\nstats = chocolate\n"); @@ -376,7 +380,8 @@ TEST_CASE("Config::set_value_in_file") SUBCASE("unknown option") { - util::write_file("ccache.conf", "path = chocolate\nstats = chocolate\n"); + REQUIRE( + util::write_file("ccache.conf", "path = chocolate\nstats = chocolate\n")); try { config.set_value_in_file("ccache.conf", "foo", "bar"); CHECK(false); @@ -390,7 +395,7 @@ TEST_CASE("Config::set_value_in_file") SUBCASE("unknown sloppiness") { - util::write_file("ccache.conf", "path = vanilla\n"); + REQUIRE(util::write_file("ccache.conf", "path = vanilla\n")); config.set_value_in_file("ccache.conf", "sloppiness", "foo"); std::string content = *util::read_file("ccache.conf"); CHECK(content == "path = vanilla\nsloppiness = foo\n"); @@ -398,7 +403,7 @@ TEST_CASE("Config::set_value_in_file") SUBCASE("comments are kept") { - util::write_file("ccache.conf", "# c1\npath = blueberry\n#c2\n"); + REQUIRE(util::write_file("ccache.conf", "# c1\npath = blueberry\n#c2\n")); config.set_value_in_file("ccache.conf", "path", "vanilla"); config.set_value_in_file("ccache.conf", "compiler", "chocolate"); std::string content = *util::read_file("ccache.conf"); @@ -431,14 +436,16 @@ TEST_CASE("Config::visit_items") { TestContext test_context; - util::write_file( - "test.conf", - "absolute_paths_in_stderr = true\n" #ifndef _WIN32 - "base_dir = /bd\n" +# define BASE_DIR "/bd\n" #else - "base_dir = C:\\bd\n" +# define BASE_DIR "C:\\bd\n" #endif + + REQUIRE(util::write_file( + "test.conf", + "absolute_paths_in_stderr = true\n" + "base_dir = " BASE_DIR "cache_dir = cd\n" "compiler = c\n" "compiler_check = cc\n" @@ -482,7 +489,8 @@ TEST_CASE("Config::visit_items") "stats = false\n" "stats_log = sl\n" "temporary_dir = td\n" - "umask = 022\n"); + "umask = 022\n")); +#undef BASE_DIR Config config; config.update_from_file("test.conf"); diff --git a/unittest/test_core_common.cpp b/unittest/test_core_common.cpp index 43c2a084..7cda15df 100644 --- a/unittest/test_core_common.cpp +++ b/unittest/test_core_common.cpp @@ -43,14 +43,14 @@ TEST_CASE("core::ensure_dir_exists") CHECK_NOTHROW(core::ensure_dir_exists("create/dir")); CHECK(DirEntry("create/dir").is_directory()); - util::write_file("create/dir/file", ""); + REQUIRE(util::write_file("create/dir/file", "")); CHECK_THROWS_AS(core::ensure_dir_exists("create/dir/file"), core::Fatal); } TEST_CASE("core::rewrite_stderr_to_absolute_paths") { TestContext test_context; - util::write_file("existing", ""); + REQUIRE(util::write_file("existing", "")); std::string input = "a:1:2\n" diff --git a/unittest/test_core_statslog.cpp b/unittest/test_core_statslog.cpp index 43942831..9b5ce4bb 100644 --- a/unittest/test_core_statslog.cpp +++ b/unittest/test_core_statslog.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2024 Joel Rosdahl and other contributors +// Copyright (C) 2021-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -33,7 +33,7 @@ TEST_CASE("read") { TestContext test_context; - util::write_file("stats.log", "# comment\ndirect_cache_hit\n"); + REQUIRE(util::write_file("stats.log", "# comment\ndirect_cache_hit\n")); const auto counters = StatsLog("stats.log").read(); CHECK(counters.get(Statistic::direct_cache_hit) == 1); diff --git a/unittest/test_hashutil.cpp b/unittest/test_hashutil.cpp index 16406070..fbae64dd 100644 --- a/unittest/test_hashutil.cpp +++ b/unittest/test_hashutil.cpp @@ -33,10 +33,10 @@ static bool hco(Hash& hash, const std::string& command, const std::string& compiler) { #ifdef _WIN32 - util::write_file("command.bat", FMT("@echo off\r\n{}\r\n", command)); + REQUIRE(util::write_file("command.bat", FMT("@echo off\r\n{}\r\n", command))); return hash_command_output(hash, "command.bat", compiler); #else - util::write_file("command.sh", FMT("#!/bin/sh\n{}\n", command)); + REQUIRE(util::write_file("command.sh", FMT("#!/bin/sh\n{}\n", command))); chmod("command.sh", 0555); return hash_command_output(hash, "./command.sh", compiler); #endif @@ -89,7 +89,7 @@ TEST_CASE("hash_command_output_compiler_substitution") CHECK(hco(h1, "echo foo", "not used")); #ifdef _WIN32 - util::write_file("command.bat", "@echo off\r\necho foo\r\n"); + REQUIRE(util::write_file("command.bat", "@echo off\r\necho foo\r\n")); CHECK(hash_command_output(h2, "%compiler%", "command.bat")); #else CHECK(hash_command_output(h2, "%compiler% foo", "echo")); @@ -105,7 +105,7 @@ TEST_CASE("hash_command_output_stdout_versus_stderr") Hash h2; #ifdef _WIN32 - util::write_file("stderr.bat", "@echo off\r\necho foo>&2\r\n"); + REQUIRE(util::write_file("stderr.bat", "@echo off\r\necho foo>&2\r\n")); CHECK(hco(h1, "echo foo", "not used")); CHECK(hco(h2, "stderr.bat", "not used")); #else @@ -124,8 +124,8 @@ TEST_CASE("hash_multicommand_output") #ifdef _WIN32 h2.hash("foo\r\nbar\r\n"); - util::write_file("foo.bat", "@echo off\r\necho foo\r\n"); - util::write_file("bar.bat", "@echo off\r\necho bar\r\n"); + REQUIRE(util::write_file("foo.bat", "@echo off\r\necho foo\r\n")); + REQUIRE(util::write_file("bar.bat", "@echo off\r\necho bar\r\n")); CHECK(hash_multicommand_output(h1, "foo.bat; bar.bat", "not used")); #else h2.hash("foo\nbar\n"); diff --git a/unittest/test_inodecache.cpp b/unittest/test_inodecache.cpp index 79b45927..f71ca050 100644 --- a/unittest/test_inodecache.cpp +++ b/unittest/test_inodecache.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2024 Joel Rosdahl and other contributors +// Copyright (C) 2020-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -49,7 +49,7 @@ inode_cache_available() return false; } bool available = tmp_file->fd && InodeCache::available(*tmp_file->fd); - fs::remove(tmp_file->path); + std::ignore = fs::remove(tmp_file->path); return available; } @@ -105,7 +105,7 @@ TEST_CASE("Test lookup nonexistent") init(config); InodeCache inode_cache(config, util::Duration(0)); - util::write_file("a", ""); + REQUIRE(util::write_file("a", "")); CHECK(!inode_cache.get("a", InodeCache::ContentType::checked_for_temporal_macros)); @@ -122,7 +122,7 @@ TEST_CASE("Test put and lookup") init(config); InodeCache inode_cache(config, util::Duration(0)); - util::write_file("a", "a text"); + REQUIRE(util::write_file("a", "a text")); HashSourceCodeResult result; result.insert(HashSourceCode::found_date); @@ -138,7 +138,7 @@ TEST_CASE("Test put and lookup") CHECK(inode_cache.get_misses() == 0); CHECK(inode_cache.get_errors() == 0); - util::write_file("a", "something else"); + REQUIRE(util::write_file("a", "something else")); CHECK(!inode_cache.get("a", InodeCache::ContentType::checked_for_temporal_macros)); @@ -186,7 +186,7 @@ TEST_CASE("Test content type") init(config); InodeCache inode_cache(config, util::Duration(0)); - util::write_file("a", "a text"); + REQUIRE(util::write_file("a", "a text")); auto binary_digest = Hash().hash("binary").digest(); auto code_digest = Hash().hash("code").digest(); diff --git a/unittest/test_storage_local_statsfile.cpp b/unittest/test_storage_local_statsfile.cpp index 1bbd794a..20493cd2 100644 --- a/unittest/test_storage_local_statsfile.cpp +++ b/unittest/test_storage_local_statsfile.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2024 Joel Rosdahl and other contributors +// Copyright (C) 2011-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -45,7 +45,7 @@ TEST_CASE("Read bad") { TestContext test_context; - util::write_file("test", "bad 1 2 3 4 5\n"); + REQUIRE(util::write_file("test", "bad 1 2 3 4 5\n")); const auto counters = StatsFile("test").read(); REQUIRE(counters.size() == static_cast(Statistic::END)); @@ -56,7 +56,7 @@ TEST_CASE("Read existing") { TestContext test_context; - util::write_file("test", "0 1 2 3 27 5\n"); + REQUIRE(util::write_file("test", "0 1 2 3 27 5\n")); const auto counters = StatsFile("test").read(); REQUIRE(counters.size() == static_cast(Statistic::END)); @@ -74,7 +74,7 @@ TEST_CASE("Read future counters") content += FMT("{}\n", i); } - util::write_file("test", content); + REQUIRE(util::write_file("test", content)); const auto counters = StatsFile("test").read(); REQUIRE(counters.size() == count); @@ -87,7 +87,7 @@ TEST_CASE("Update") { TestContext test_context; - util::write_file("test", "0 1 2 3 27 5\n"); + REQUIRE(util::write_file("test", "0 1 2 3 27 5\n")); auto counters = StatsFile("test").update([](auto& cs) { cs.increment(Statistic::internal_error, 1); diff --git a/unittest/test_storage_local_util.cpp b/unittest/test_storage_local_util.cpp index c6766677..f6159658 100644 --- a/unittest/test_storage_local_util.cpp +++ b/unittest/test_storage_local_util.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2024 Joel Rosdahl and other contributors +// Copyright (C) 2021-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -51,14 +51,14 @@ TEST_CASE("storage::local::get_cache_dir_files") { TestContext test_context; - fs::create_directories("e/m/p/t/y"); + REQUIRE(fs::create_directories("e/m/p/t/y")); - fs::create_directories("0/1"); - fs::create_directories("0/f/c"); - util::write_file("0/file_a", ""); - util::write_file("0/1/file_b", "1"); - util::write_file("0/1/file_c", "12"); - util::write_file("0/f/c/file_d", "123"); + REQUIRE(fs::create_directories("0/1")); + REQUIRE(fs::create_directories("0/f/c")); + REQUIRE(util::write_file("0/file_a", "")); + REQUIRE(util::write_file("0/1/file_b", "1")); + REQUIRE(util::write_file("0/1/file_c", "12")); + REQUIRE(util::write_file("0/f/c/file_d", "123")); SUBCASE("nonexistent subdirectory") { diff --git a/unittest/test_util_args.cpp b/unittest/test_util_args.cpp index e43ace0c..6943111d 100644 --- a/unittest/test_util_args.cpp +++ b/unittest/test_util_args.cpp @@ -98,14 +98,14 @@ TEST_CASE("Args::from_response_file") SUBCASE("Empty") { - util::write_file("rsp_file", ""); + REQUIRE(util::write_file("rsp_file", "")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix); CHECK(args.size() == 0); } SUBCASE("One argument without newline") { - util::write_file("rsp_file", "foo"); + REQUIRE(util::write_file("rsp_file", "foo")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix); CHECK(args.size() == 1); CHECK(args[0] == "foo"); @@ -113,7 +113,7 @@ TEST_CASE("Args::from_response_file") SUBCASE("One argument with newline") { - util::write_file("rsp_file", "foo\n"); + REQUIRE(util::write_file("rsp_file", "foo\n")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix); CHECK(args.size() == 1); CHECK(args[0] == "foo"); @@ -121,7 +121,7 @@ TEST_CASE("Args::from_response_file") SUBCASE("Multiple simple arguments") { - util::write_file("rsp_file", "x y z\n"); + REQUIRE(util::write_file("rsp_file", "x y z\n")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix); CHECK(args.size() == 3); CHECK(args[0] == "x"); @@ -131,10 +131,10 @@ TEST_CASE("Args::from_response_file") SUBCASE("Tricky quoting") { - util::write_file( + REQUIRE(util::write_file( "rsp_file", "first\rsec\\\tond\tthi\\\\rd\nfourth \tfif\\ th \"si'x\\\" th\"" - " 'seve\nth'\\"); + " 'seve\nth'\\")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix); CHECK(args.size() == 7); CHECK(args[0] == "first"); @@ -148,7 +148,7 @@ TEST_CASE("Args::from_response_file") SUBCASE("Ignore single quote in MSVC format") { - util::write_file("rsp_file", "'a b'"); + REQUIRE(util::write_file("rsp_file", "'a b'")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows); CHECK(args.size() == 2); CHECK(args[0] == "'a"); @@ -157,7 +157,7 @@ TEST_CASE("Args::from_response_file") SUBCASE("Backslash as directory separator in MSVC format") { - util::write_file("rsp_file", R"("-DDIRSEP='A\B\C'")"); + REQUIRE(util::write_file("rsp_file", R"("-DDIRSEP='A\B\C'")")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows); CHECK(args.size() == 1); CHECK(args[0] == R"(-DDIRSEP='A\B\C')"); @@ -165,7 +165,7 @@ TEST_CASE("Args::from_response_file") SUBCASE("Backslash before quote in MSVC format") { - util::write_file("rsp_file", R"(/Fo"N.dir\Release\\")"); + REQUIRE(util::write_file("rsp_file", R"(/Fo"N.dir\Release\\")")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows); CHECK(args.size() == 1); CHECK(args[0] == R"(/FoN.dir\Release\)"); @@ -173,7 +173,7 @@ TEST_CASE("Args::from_response_file") SUBCASE("Arguments on multiple lines in MSVC format") { - util::write_file("rsp_file", "a\nb"); + REQUIRE(util::write_file("rsp_file", "a\nb")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows); CHECK(args.size() == 2); CHECK(args[0] == "a"); @@ -182,11 +182,11 @@ TEST_CASE("Args::from_response_file") SUBCASE("Tricky quoting in MSVC format (#1247)") { - util::write_file( + REQUIRE(util::write_file( "rsp_file", R"(\ \\ '\\' "\\" '"\\"' "'\\'" '''\\''' ''"\\"'' '"'\\'"' '""\\""' "''\\''" "'"\\"'" ""'\\'"" """\\""" )" R"(\'\' '\'\'' "\'\'" ''\'\''' '"\'\'"' "'\'\''" ""\'\'"" '''\'\'''' ''"\'\'"'' '"'\'\''"' '""\'\'""' "''\'\'''" "'"\'\'"'" ""'\'\''"" """\'\'""" )" - R"(\"\" '\"\"' "\"\"" ''\"\"'' '"\"\""' "'\"\"'" ""\"\""" '''\"\"''' ''"\"\""'' '"'\"\"'"' '""\"\"""' "''\"\"''" "'"\"\""'" ""'\"\"'"" """\"\"""")"); + R"(\"\" '\"\"' "\"\"" ''\"\"'' '"\"\""' "'\"\"'" ""\"\""" '''\"\"''' ''"\"\""'' '"'\"\"'"' '""\"\"""' "''\"\"''" "'"\"\""'" ""'\"\"'"" """\"\"""")")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows); CHECK(args.size() == 44); CHECK(args[0] == R"(\)"); @@ -239,11 +239,11 @@ TEST_CASE("Args::from_response_file") { // See // https://learn.microsoft.com/en-us/previous-versions//17w5ykft(v=vs.85)?redirectedfrom=MSDN - util::write_file("rsp_file", - R"("abc" d e )" - R"(a\\\b d"e f"g h )" - R"(a\\\"b c d )" - R"(a\\\\"b c" d e)"); + REQUIRE(util::write_file("rsp_file", + R"("abc" d e )" + R"(a\\\b d"e f"g h )" + R"(a\\\"b c d )" + R"(a\\\\"b c" d e)")); args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows); CHECK(args.size() == 12); CHECK(args[0] == R"(abc)"); diff --git a/unittest/test_util_clang.cpp b/unittest/test_util_clang.cpp index afded55f..e4122b70 100644 --- a/unittest/test_util_clang.cpp +++ b/unittest/test_util_clang.cpp @@ -39,7 +39,7 @@ TEST_CASE("util::split_preprocessed_file_from_clang_cuda") SUBCASE("normal") { fs::path filename = "test_normal.txt"; - util::write_file(filename, R"(# 1 "test_cuda.cu" + REQUIRE(util::write_file(filename, R"(# 1 "test_cuda.cu" # 1 "" 1 # 1 "" 3 void caller() { @@ -48,7 +48,7 @@ void caller() { # 1 "test_cuda.cu" # 1 "" 1 # 1 "" 3 -)"); +)")); auto result = util::split_preprocessed_file_from_clang_cuda(filename); @@ -75,7 +75,7 @@ void caller() { SUBCASE("empty file") { fs::path filename = "test_empty.txt"; - util::write_file(filename, ""); + REQUIRE(util::write_file(filename, "")); CHECK(util::split_preprocessed_file_from_clang_cuda(filename).empty()); } diff --git a/unittest/test_util_direntry.cpp b/unittest/test_util_direntry.cpp index 84d2aba1..741e08fb 100644 --- a/unittest/test_util_direntry.cpp +++ b/unittest/test_util_direntry.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2024 Joel Rosdahl and other contributors +// Copyright (C) 2019-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -209,7 +209,7 @@ TEST_CASE("Stat file descriptor") { TestContext test_context; - util::write_file("a", "123"); + REQUIRE(util::write_file("a", "123")); util::Fd fd(open("a", O_RDONLY)); DirEntry entry("a", *fd); @@ -225,12 +225,12 @@ TEST_CASE("Caching and refresh") { TestContext test_context; - util::write_file("a", ""); + REQUIRE(util::write_file("a", "")); DirEntry entry("a"); CHECK(entry.size() == 0); - util::write_file("a", "123", util::WriteFileMode::in_place); + REQUIRE(util::write_file("a", "123", util::WriteFileMode::in_place)); CHECK(entry.size() == 0); entry.refresh(); CHECK(entry.size() == 3); @@ -240,15 +240,15 @@ TEST_CASE("Same i-node as") { TestContext test_context; - util::write_file("a", ""); - util::write_file("b", ""); + REQUIRE(util::write_file("a", "")); + REQUIRE(util::write_file("b", "")); DirEntry entry_a("a"); DirEntry entry_b("b"); CHECK(entry_a.same_inode_as(entry_a)); CHECK(!entry_a.same_inode_as(entry_b)); - util::write_file("a", "change size", util::WriteFileMode::in_place); + REQUIRE(util::write_file("a", "change size", util::WriteFileMode::in_place)); CHECK(DirEntry("a").same_inode_as(entry_a)); CHECK(!DirEntry("nonexistent").same_inode_as(DirEntry("nonexistent"))); @@ -258,7 +258,7 @@ TEST_CASE("Get path") { TestContext test_context; - util::write_file("a", ""); + REQUIRE(util::write_file("a", "")); CHECK(DirEntry("a").path() == "a"); CHECK(DirEntry("does_not_exist").path() == "does_not_exist"); } @@ -267,7 +267,7 @@ TEST_CASE("Return values when file exists") { TestContext test_context; - util::write_file("file", "1234567"); + REQUIRE(util::write_file("file", "1234567")); DirEntry de("file"); CHECK(de); @@ -362,7 +362,7 @@ TEST_CASE("Symlink to file" * doctest::skip(!symlinks_supported())) { TestContext test_context; - util::write_file("file", "1234567"); + REQUIRE(util::write_file("file", "1234567")); #ifdef _WIN32 // SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: 0x2 @@ -431,7 +431,7 @@ TEST_CASE("Hard links") { TestContext test_context; - util::write_file("a", ""); + REQUIRE(util::write_file("a", "")); #ifdef _WIN32 REQUIRE(CreateHardLinkA("b", "a", nullptr)); @@ -461,7 +461,7 @@ TEST_CASE("Hard links") CHECK(entry_a.inode() == entry_b.inode()); CHECK(entry_a.same_inode_as(entry_b)); - util::write_file("a", "1234567", util::WriteFileMode::in_place); + REQUIRE(util::write_file("a", "1234567", util::WriteFileMode::in_place)); entry_b.refresh(); CHECK(entry_b.size() == 7); } @@ -553,7 +553,7 @@ TEST_CASE("Win32 Readonly File") { TestContext test_context; - util::write_file("file", ""); + REQUIRE(util::write_file("file", "")); DWORD prev_attrs = GetFileAttributesA("file"); REQUIRE(prev_attrs != INVALID_FILE_ATTRIBUTES); diff --git a/unittest/test_util_exec.cpp b/unittest/test_util_exec.cpp index e0d1e80a..d79af381 100644 --- a/unittest/test_util_exec.cpp +++ b/unittest/test_util_exec.cpp @@ -35,7 +35,8 @@ TEST_CASE("util::exec_to_string") SUBCASE("stdout + stderr") { #ifdef _WIN32 - util::write_file("command.bat", "@echo off\r\necho fisk\r\necho sork>&2"); + REQUIRE(util::write_file("command.bat", + "@echo off\r\necho fisk\r\necho sork>&2")); util::Args args{"command.bat"}; #else util::Args args{"sh", "-c", "echo fisk; echo sork >&2"}; diff --git a/unittest/test_util_file.cpp b/unittest/test_util_file.cpp index 728df776..9e8366d9 100644 --- a/unittest/test_util_file.cpp +++ b/unittest/test_util_file.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022-2024 Joel Rosdahl and other contributors +// Copyright (C) 2022-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -254,10 +254,10 @@ TEST_CASE("util::traverse_directory") TestContext test_context; REQUIRE(fs::create_directories("dir-with-subdir-and-file/subdir")); - util::write_file("dir-with-subdir-and-file/subdir/f", ""); + REQUIRE(util::write_file("dir-with-subdir-and-file/subdir/f", "")); REQUIRE(fs::create_directory("dir-with-files")); - util::write_file("dir-with-files/f1", ""); - util::write_file("dir-with-files/f2", ""); + REQUIRE(util::write_file("dir-with-files/f1", "")); + REQUIRE(util::write_file("dir-with-files/f2", "")); REQUIRE(fs::create_directory("empty-dir")); std::vector visited; @@ -282,14 +282,14 @@ TEST_CASE("util::traverse_directory") SUBCASE("traverse empty directory") { - CHECK_NOTHROW(util::traverse_directory("empty-dir", visitor)); + std::ignore = util::traverse_directory("empty-dir", visitor); REQUIRE(visited.size() == 1); CHECK(visited[0] == "[d] empty-dir"); } SUBCASE("traverse directory with files") { - CHECK_NOTHROW(util::traverse_directory("dir-with-files", visitor)); + std::ignore = util::traverse_directory("dir-with-files", visitor); REQUIRE(visited.size() == 3); fs::path f1("[f] dir-with-files/f1"); fs::path f2("[f] dir-with-files/f2"); @@ -300,8 +300,7 @@ TEST_CASE("util::traverse_directory") SUBCASE("traverse directory hierarchy") { - CHECK_NOTHROW( - util::traverse_directory("dir-with-subdir-and-file", visitor)); + std::ignore = util::traverse_directory("dir-with-subdir-and-file", visitor); REQUIRE(visited.size() == 3); CHECK(visited[0] == fs::path("[f] dir-with-subdir-and-file/subdir/f")); CHECK(visited[1] == fs::path("[d] dir-with-subdir-and-file/subdir")); diff --git a/unittest/test_util_lockfile.cpp b/unittest/test_util_lockfile.cpp index 85705147..57fcd31c 100644 --- a/unittest/test_util_lockfile.cpp +++ b/unittest/test_util_lockfile.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2024 Joel Rosdahl and other contributors +// Copyright (C) 2020-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -115,7 +115,7 @@ TEST_CASE("Break stale lock, blocking") { TestContext test_context; - util::write_file("test.alive", ""); + REQUIRE(util::write_file("test.alive", "")); const util::TimePoint long_time_ago(0, 0); util::set_timestamps("test.alive", long_time_ago); CHECK(symlink("foo", "test.lock") == 0); @@ -130,7 +130,7 @@ TEST_CASE("Break stale lock, non-blocking") { TestContext test_context; - util::write_file("test.alive", ""); + REQUIRE(util::write_file("test.alive", "")); const util::TimePoint long_time_ago(0, 0); util::set_timestamps("test.alive", long_time_ago); CHECK(symlink("foo", "test.lock") == 0); diff --git a/unittest/testutil.cpp b/unittest/testutil.cpp index 8872ff8a..cc09db4f 100644 --- a/unittest/testutil.cpp +++ b/unittest/testutil.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2024 Joel Rosdahl and other contributors +// Copyright (C) 2020-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -38,15 +38,16 @@ TestContext::TestContext() } ++m_subdir_counter; fs::path subtest_dir = m_test_dir / FMT("test_{}", m_subdir_counter); - fs::create_directories(subtest_dir); - if (!fs::current_path(subtest_dir)) { - throw core::Error(FMT("Failed to change directory to {}", subtest_dir)); - } + util::throw_on_error(fs::create_directories(subtest_dir), + FMT("Failed to create {}: ", subtest_dir)); + util::throw_on_error( + fs::current_path(subtest_dir), + FMT("Failed to change directory to {}", subtest_dir)); } TestContext::~TestContext() { - fs::current_path(m_test_dir); + std::ignore = fs::current_path(m_test_dir); } } // namespace TestUtil