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 18, 2021
1 parent 024da43 commit 7e95357
Show file tree
Hide file tree
Showing 2 changed files with 37 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
36 changes: 36 additions & 0 deletions libres/tests/analysis/test_fwd_step_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <filesystem>

#include "catch2/catch.hpp"

#include "ert/analysis/fwd_step_log.hpp"

SCENARIO("fwd_step_log_open", "[analysis") {

GIVEN("A fwd_step_log_type with custom file path") {
const char *log_file_path = "tmp_fwd_step_log_open/test.txt";
fwd_step_log_type *fwd_step_log = fwd_step_log_alloc();
fwd_step_log_set_log_file(fwd_step_log, log_file_path);

WHEN("we want to clear the log") {
fwd_step_log_set_clear_log(fwd_step_log, true);
fwd_step_log_open(fwd_step_log);
THEN("file path should be created") {
bool exists_after = std::filesystem::exists(log_file_path);
REQUIRE_FALSE(!exists_after);
}
fwd_step_log_free(fwd_step_log);
std::filesystem::remove_all(log_file_path);
}
WHEN("we don't want to clear the log") {
fwd_step_log_set_clear_log(fwd_step_log, false);
fwd_step_log_open(fwd_step_log);
THEN("file path should still be created") {
bool exists_after = std::filesystem::exists(log_file_path);
REQUIRE_FALSE(!exists_after);
}
fwd_step_log_free(fwd_step_log);
std::filesystem::remove_all(log_file_path);
}
}
}

0 comments on commit 7e95357

Please sign in to comment.