Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fwd_step_log_open #2388

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ conan_cmake_run(
# Packages
REQUIRES
catch2/2.13.7
stduuid/1.0
# Options
OPTIONS
catch2:with_main=True
Expand Down
6 changes: 5 additions & 1 deletion libres/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ endif()
find_package(Catch2 REQUIRED)
include(Catch)

find_package(stduuid REQUIRED)
# include(stduuid)

add_executable(ert_test_suite analysis/modules/test_ies_enkf_main.cpp
analysis/test_enkf_linalg.cpp
analysis/test_fwd_step_log.cpp
res_util/test_matrix.cpp)
target_link_libraries(ert_test_suite res Catch2::Catch2WithMain)
target_link_libraries(ert_test_suite res Catch2::Catch2WithMain stduuid)

catch_discover_tests(ert_test_suite)
46 changes: 46 additions & 0 deletions libres/tests/analysis/test_fwd_step_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <string>
#include <filesystem>

#include "catch2/catch.hpp"
#include "stduuid/uuid.h"

#include "ert/analysis/fwd_step_log.hpp"

namespace {
class TmpLog {
dafeda marked this conversation as resolved.
Show resolved Hide resolved
public:
std::filesystem::path log_file_path;
fwd_step_log_type *fwd_step_log;

TmpLog() : log_file_path("tmp_fwd_step_log_open/test.txt") {
fwd_step_log = fwd_step_log_alloc();
fwd_step_log_set_log_file(fwd_step_log, log_file_path.c_str());
}
~TmpLog() {
fwd_step_log_free(fwd_step_log);
std::filesystem::remove_all(log_file_path.parent_path());
}
};
} // namespace

TEST_CASE_METHOD(TmpLog, "fwd_step_log_open clear_log is true", "[analysis]") {
bool exists_before = std::filesystem::exists(log_file_path);
REQUIRE(!exists_before);

fwd_step_log_set_clear_log(fwd_step_log, true);
fwd_step_log_open(fwd_step_log);

bool exists_after = std::filesystem::exists(log_file_path);
REQUIRE(exists_after);
}

TEST_CASE_METHOD(TmpLog, "fwd_step_log_open clear_log is false", "[analysis]") {
bool exists_before = std::filesystem::exists(log_file_path);
REQUIRE(!exists_before);

fwd_step_log_set_clear_log(fwd_step_log, false);
fwd_step_log_open(fwd_step_log);

bool exists_after = std::filesystem::exists(log_file_path);
REQUIRE(exists_after);
}