Skip to content

Commit

Permalink
Test fwd_step_log_open
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeda committed Nov 19, 2021
1 parent e2a8371 commit 7de47e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions libres/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(Catch)

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)

Expand Down
45 changes: 45 additions & 0 deletions libres/tests/analysis/test_fwd_step_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <string>
#include <filesystem>

#include "catch2/catch.hpp"

#include "ert/analysis/fwd_step_log.hpp"

namespace {
class TmpLog {
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);
}

0 comments on commit 7de47e0

Please sign in to comment.